Playwright
@tracecov/playwright records coverage from Playwright's API testing — the request fixture and any APIRequestContext — and merges results from all workers into one report.
npm install -D @tracecov/playwright
Setup
Add the reporter to playwright.config.ts:
import { defineConfig } from '@playwright/test';
export default defineConfig({
reporter: [
['list'],
['@tracecov/playwright/reporter', {
schema: 'openapi.json',
report: { html: 'coverage.html' },
thresholds: { operations: 80 },
}],
],
});
Import test from @tracecov/playwright instead of @playwright/test. Its request fixture is instrumented, so every call it makes is recorded — no changes to the test body:
import { expect } from '@playwright/test';
import { test } from '@tracecov/playwright';
test('lists items', async ({ request }) => {
const response = await request.get('/items?limit=10');
expect(response.ok()).toBeTruthy();
});
Requests are recorded whether the test passes or fails. A thresholds breach fails the run.
The reporter takes the same report and thresholds options as the Vitest and Jest plugins, and reports the same six metrics — operations, parameters, keywords, examples, responses, response keywords. See Coverage Concepts for what each measures.
Instrumenting a context you build yourself
import { wrapRequest, createDirRecorder, interactionsDir } from '@tracecov/playwright';
Wrap an APIRequestContext with wrapRequest(context, recorder). Re-wrapping an already-wrapped context repoints it at the new recorder rather than double-counting.
How workers are merged
Playwright runs test files in worker processes, so no single coverage map sees every request. Workers buffer their interactions to a shared directory and the reporter merges them into one report in the main process.
That directory is derived from the working directory. If two runs share a working directory, set TRACECOV_PLAYWRIGHT_DIR so each gets its own.
Not captured
- Context-level
extraHTTPHeaders. Playwright merges those internally and exposes no getter, so headers set on the context — auth tokens, for example — do not count toward header-parameter coverage. Pass them per call to have them recorded. - Redirects. The final resolved URL is recorded, not the original one.
Related
- JavaScript Integration — Vitest, Jest, Express, Axios, fetch
- Coverage Concepts — what each coverage state means
- JavaScript API Reference