Set up Playwright with Chromium, dev server auto-start, test helpers for seeding bots and programmatic auth. Added smoke spec that verifies homepage and leaderboard load without crashes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
/**
|
|
* E2E test setup helpers.
|
|
* Provides utilities for seeding test data and managing test state.
|
|
*/
|
|
|
|
/** Wait for the dev server to be ready */
|
|
export async function waitForServer(baseURL: string, timeoutMs = 10_000): Promise<void> {
|
|
const start = Date.now()
|
|
while (Date.now() - start < timeoutMs) {
|
|
try {
|
|
const res = await fetch(baseURL)
|
|
if (res.ok) return
|
|
} catch {
|
|
// Server not ready yet
|
|
}
|
|
await new Promise(r => setTimeout(r, 500))
|
|
}
|
|
throw new Error(`Server at ${baseURL} did not start within ${timeoutMs}ms`)
|
|
}
|
|
|
|
/** Seed a mock bot via the API for testing */
|
|
export async function seedBot(baseURL: string, name: string, pubkey: string): Promise<{ id: string; secret: string }> {
|
|
const res = await fetch(`${baseURL}/api/auth/register`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
pubkey,
|
|
name,
|
|
webhookUrl: 'http://mock.local',
|
|
}),
|
|
})
|
|
|
|
if (!res.ok) {
|
|
const body = await res.text()
|
|
throw new Error(`Failed to seed bot ${name}: ${res.status} ${body}`)
|
|
}
|
|
|
|
return res.json()
|
|
}
|
|
|
|
/** Generate a random hex pubkey for testing */
|
|
export function randomPubkey(): string {
|
|
const bytes = new Uint8Array(32)
|
|
crypto.getRandomValues(bytes)
|
|
return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('')
|
|
}
|