Files
crowd-funder-for-time-pwa/test-playwright/warmUpDevServer.ts
T

27 lines
1.2 KiB
TypeScript

import { chromium, FullConfig } from "@playwright/test";
/**
* Loads the app once before any test so Vite has bundled its dependencies and
* transformed the modules (including the SQL worker) before the workers start.
*
* Reason: with several Firefox instances running in parallel, Firefox can fail
* with "no WebAssembly compiler available", sql.js cannot start, and the app
* shows "Time Safari Cannot Start". It is most frequent at the start of a run
* against a cold dev server, which this avoids; it also happens mid-run, which
* this does not, so the retry in playwright.config-local.ts stays.
*/
export default async function warmUpDevServer(config: FullConfig) {
const baseURL = config.projects[0]?.use?.baseURL || "http://localhost:8080";
const browser = await chromium.launch();
try {
const page = await browser.newPage();
await page.goto(baseURL, { timeout: 120000 });
// Vite reloads the page if it finds dependencies it has not bundled yet,
// so wait for the app to render and the network to go quiet afterward.
await page.locator("#Content").first().waitFor({ timeout: 120000 });
await page.waitForLoadState("networkidle", { timeout: 120000 });
} finally {
await browser.close();
}
}