- Instrument the application. Add Istanbul to your bundler. This needs your application source, so your team does it.
- Collect coverage in tests. Turn on coverage in the test fixtures. An Empirical agent can make this change.
- Build the report. Download the coverage files from a run and build an HTML report with
nyc. This also needs your application source.
Instrument the application
This example uses Vite. Other bundlers need an equivalent Istanbul plugin. In your application repository, install the plugin:vite.config.ts. When tests run against a deployed URL rather than localhost, keep
forceBuildInstrument: true so production builds include the instrumentation:
Collect coverage in tests
Coverage collection needs@empiricalrun/playwright-utils 0.43.0 or later. In the test fixture file,
pass { collectCoverage: true } to baseTestFixture:
window.__coverage__ and attaches it to the test report as
an Istanbul coverage JSON file, uploaded like other artifacts such as videos.
Build the report
Download the coverage files for a test run, then build the report withnyc.
Fetch the run with the Get a test run API and download
the Playwright JSON report from its summary_url. Replace <TEST_RUN_ID> with the run’s ID:
.nyc_output:
/path/to/final-output-dir/index.html to see coverage by file.