playwright-test-coverage-native
Measure test coverage with Playwright.
Its only dependency is @playwright/test
— unlike its alternatives, playwright-test-coverage-native
uses Playwright's
built-in coverage functionality without Istanbul.
Configuration
Add coverageDir
to playwright.config.ts
to set where coverage data should be written to.
For example,
import { defineConfig, devices } from "playwright-test-coverage-native";
export default defineConfig({
projects: [
{
name: "chromium",
use: {
...devices["Desktop Chrome"],
coverageDir: './coverage/tmp',
coverageSrc: './src'
},
},
],
});
[!NOTE]
Coverage APIs are only supported on Chromium-based browsers.
Usage
Install c8.
After running playwright test -c playwright.config.ts
,
run c8 report
to print a summary of the coverage.
c8 report
is also used to convert to various formats,
see c8 report --help
for more options.
Alternatives