import { test, expect } from '@playwright/test';
const BASE_URL = 'http://localhost:8080';
test.describe('Example Files Smoke Tests', () => {
test('sql_demo.html loads without errors', async ({ page }) => {
const errors = [];
page.on('pageerror', error => errors.push(error.message));
await page.goto(`${BASE_URL}/examples/sql_demo.html`);
await page.waitForSelector('#output', { timeout: 10000 });
await page.waitForFunction(() => {
const output = document.querySelector('#output');
return output && output.textContent.includes('Final user count');
}, { timeout: 15000 });
const output = await page.locator('#output').textContent();
expect(output).toContain('SELECT * FROM users');
expect(output).toContain('Final user count');
expect(errors).toHaveLength(0);
});
test('web_demo.html loads without errors', async ({ page }) => {
const errors = [];
page.on('pageerror', error => errors.push(error.message));
await page.goto(`${BASE_URL}/examples/web_demo.html`);
await page.waitForSelector('#dbName', { timeout: 10000 });
const title = await page.title();
expect(title).toContain('SQLite IndexedDB Demo');
expect(errors).toHaveLength(0);
});
test('multi-tab-demo.html loads without errors', async ({ page }) => {
const errors = [];
page.on('pageerror', error => errors.push(error.message));
await page.goto(`${BASE_URL}/examples/multi-tab-demo.html`);
await page.waitForSelector('#leaderBadge', { timeout: 10000 });
const badge = await page.locator('#leaderBadge').textContent();
expect(badge).toContain('LEADER');
expect(errors).toHaveLength(0);
});
test('benchmark.html loads without errors', async ({ page }) => {
const errors = [];
page.on('pageerror', error => errors.push(error.message));
await page.goto(`${BASE_URL}/examples/benchmark.html`);
await page.waitForSelector('h1', { timeout: 10000 });
const h1 = await page.locator('h1').textContent();
expect(h1).toContain('Benchmark');
const hasWasmErrors = errors.some(err => err.includes('absurder_sql'));
expect(hasWasmErrors).toBe(false);
});
test('multi-tab-wrapper.js has new methods', async ({ page }) => {
await page.goto(`${BASE_URL}/examples/multi-tab-demo.html`);
await page.waitForSelector('#leaderBadge', { timeout: 10000 });
const hasNewMethods = await page.evaluate(() => {
return (
typeof window.db.enableOptimisticUpdates === 'function' &&
typeof window.db.enableCoordinationMetrics === 'function' &&
typeof window.db.getCoordinationMetrics === 'function' &&
typeof window.db.trackOptimisticWrite === 'function'
);
});
expect(hasNewMethods).toBe(true);
});
});