// What the browser tests run of the page's script (#390). With IPX_COVERAGE=1, web/build.mjs // builds the script unminified with a source map to web/src, every test's page records V8's // coverage of it, and the teardown (coverage-teardown.ts) writes the report, file by file, to // target/coverage/page. Without it, `test` is Playwright's own. // // The specs take `test` and `expect` from here, not from @playwright/test, so no test is left out. import { test as base, expect } from '@playwright/test'; import { CoverageReport, type CoverageReportOptions } from 'monocart-coverage-reports'; export const coverageOptions: CoverageReportOptions = { name: 'iPX page', outputDir: 'target/coverage/page', reports: ['v8', 'lcovonly', 'console-summary', 'markdown-details'], // The pages' scripts; the service worker is a worker of its own, which a page's coverage does // not see. entryFilter: (e) => /\/(app|admin|login)\.js(\?|$)/.test(e.url), sourceFilter: (p) => p.startsWith('web/src/'), }; export const test = base.extend<{ coverage: void }>({ coverage: [ async ({ page }, use) => { if (!process.env.IPX_COVERAGE) return use(); // Kept across a reload or a sign-in, which several tests make. await page.coverage.startJSCoverage({ resetOnNavigation: false }); await use(); await new CoverageReport(coverageOptions).add(await page.coverage.stopJSCoverage()); }, { auto: true }, ], }); export { expect };