0.23.3 • Published yesterday
@tracecov/playwright
Licence
LicenseRef-TraceCov-Community-1.0
Version
0.23.3
Deps
1
Size
15 kB
Vulns
0
Weekly
0
@tracecov/playwright
Automatic OpenAPI coverage capture for Playwright API testing.
Install
npm install -D @tracecov/playwright
Usage
Swap the test import and add the reporter.
// tests/api.spec.ts
import { test } from '@tracecov/playwright';
import { expect } from '@playwright/test';
test('lists pets', async ({ request }) => {
const res = await request.get('/pets');
expect(res.ok()).toBeTruthy();
});
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: { baseURL: 'http://localhost:8080' },
reporter: [
['list'],
['@tracecov/playwright/reporter', {
schema: './openapi.json',
report: { html: 'coverage.html', markdown: 'coverage.md' },
thresholds: { operations: 80 },
}],
],
});
A reporter configured with neither report nor thresholds emits nothing — set at least one to get output.
Contexts you create yourself (request.newContext(), global setup) aren't covered by the fixture — wrap them:
import { wrapRequest, createDirRecorder, interactionsDir } from '@tracecov/playwright';
const { recorder, flush } = createDirRecorder(interactionsDir());
const ctx = wrapRequest(await request.newContext(), recorder);
// ... use ctx ...
flush();
Limitations
- Context-level headers. Only per-call headers are recorded. Headers set on the context (
newContext({ extraHTTPHeaders }), auth) are merged by Playwright with no public getter, so coverage of header parameters supplied that way is missed. - Network errors with relative paths. A request that fails before a response, when its URL is relative to a context
baseURL, isn't recorded as an operation error (Playwright exposes nobaseURLto resolve it). Successful-response coverage is unaffected. - Interactions directory. Workers and the reporter share
os.tmpdir()/tracecov-playwright-<cwd-hash>. SetTRACECOV_PLAYWRIGHT_DIRto override it — e.g. to isolate concurrent runs that share one working directory.