Skip to content

Test coverage

Rollwright attempts to provide test coverage support out of the box. It uses Istanbul for code instrumentation and coverage reports. Necessary plugins are already included to Rollwright, no additional dependencies needed. In order to enable code instrumentation, add a reporter to the Playwright config:

js
import { defineConfig } from "@playwright/test";

export default defineConfig({
  // ...
  reporter: [
    /* other reporters */
    ["rollwright/coverage-reporter"], 
  ],
  // ...
});

Rollwright's coverage reporter uses Istanbul reporters. Desired report type can be configured via reporter options. Field name defines the report type, and options may be used for additional configuration required by istanbul-reports package. The most commonly used reporters are text (used by default, outputs a handy text report in the terminal) and html (creates coverage folder with HTML pages).

js
import { defineConfig } from "@playwright/test";

export default defineConfig({
  reporter: [
    ["rollwright/coverage-reporter", { name: "html" }], 
  ],
});

To change configuration for the selected Istanbul report type, add options object:

js
import { defineConfig } from "@playwright/test";

export default defineConfig({
  // ...
  reporter: [
    /* other reporters */
    [
      "rollwright/coverage-reporter",
      {
        name: "html",
        options: {
          /* reporter type options */
        },
      },
    ],
  ],
  // ...
});

Released under ISC License.