Playwright Test Coverage is an extension for the Playwright test framework designed to facilitate code coverage collection from end-to-end tests. Currently stable at version 1.2.12, this library integrates with `babel-plugin-istanbul` for source code instrumentation and `nyc` for managing the test run and generating comprehensive coverage reports. Unlike some other coverage tools, `playwright-test-coverage` requires developers to explicitly instrument their frontend source code during the build process and run their application server via `nyc`. It provides a wrapper around Playwright's `test` and `expect` functions, ensuring that coverage data from the browser context is properly captured and merged. This setup is particularly useful for projects that already leverage Babel for their build pipeline and require detailed E2E coverage metrics.
npm install playwright-test-coverageVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import `test` and `expect` from `playwright-test-coverage` to enable coverage collection in a basic Playwright E2E test, including necessary setup steps.
Ensure your frontend source code is correctly instrumented with `babel-plugin-istanbul` during your build process. This package does not instrument your code automatically.
You must run your application server (the one being tested by Playwright) through `nyc`. For example, instead of `node server.js`, use `nyc node server.js`.
Always import `test` and `expect` directly from `playwright-test-coverage` (e.g., `const { test, expect } = require("playwright-test-coverage")`) and NOT from `@playwright/test`. This ensures the coverage-enabled wrappers are used.Ensure `test` and `expect` are imported from `playwright-test-coverage`: `const { test, expect } = require("playwright-test-coverage");` or `import { test, expect } from "playwright-test-coverage";`Verify that your application's source code is instrumented with `babel-plugin-istanbul` and that your server is started using `nyc` (e.g., `nyc npm start` or `nyc node server.js`). Also, ensure tests interact with the instrumented code.