You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Playwright extension that collects code coverage from running end-to-end tests. Assumes that code has been instrumented with babel-plugin-istanbul during the build process.
Prerequisites
Playwright test framework
babel-plugin-istanbul plugin
nyc for running tests
npm i -D @playwright/test babel-plugin-istanbul nyc
Installation
npm i -D playwright-test-coverage
Usage
Write your Playwright tests as usual, except requiretest and expect from this package as follows:
// tests/foo.spec.jsconst{ test, expect }=require("playwright-test-coverage");// Use test and expect as usualtest("basic test",async({ page })=>{awaitpage.goto("https://playwright.dev/");consttitle=page.locator(".navbar__inner .navbar__title");awaitexpect(title).toHaveText("Playwright");});
Then, instrument your front end source code for coverage using the babel-plugin-istanbul plugin.
Finally, run your server via nyc to capture code coverage. For more details see istanbul/nyc.
Options
ISTANBUL_TEMP_DIR - Set this environment variable to specify where Istanbul coverage files should be output. Defaults to $CWD/.nyc_output.