Currents Documentation
Currents.devGitHubChangelog
  • Getting Started
    • What is Currents?
    • Playwright
      • Playwright: Quick Start
      • Troubleshooting Playwright
    • Cypress
      • Your First Cypress Run
      • Integrating with Cypress
        • Compatibility
        • Alternative Cypress Binaries
      • Troubleshooting Cypress
    • Jest
      • Your First Jest Run
      • Detox + Jest
      • Troubleshooting Jest
    • Others
    • CI Setup
      • GitHub Actions
        • Cypress - GitHub Actions
        • Playwright - GitHub Actions
        • Jest - GitHub Actions
        • Node.js - GitHub Actions
        • Commit data for GitHub Actions
        • Custom Docker runners
        • Named Runners
      • GitLab
        • Cypress - GitLab CI/CD
        • Playwright - GitLab CI/CD
        • Custom Docker runners
      • Jenkins
        • Cypress - Jenkins
        • Playwright - Jenkins
      • CircleCI
        • Cypress - CircleCI
        • Playwright - CircleCI
      • Bitbucket
        • Cypress - Bitbucket Pipelines
      • Azure DevOps
        • Cypress - Azure DevOps
        • Playwright - Azure DevOps
      • AWS Code Build
        • Cypress - AWS Code Build
        • Playwright - AWS Code Build
      • NX
        • Playwright - NX
        • Cypress - NX
  • Guides
    • Record Key
    • CI Build ID
    • Reporting
      • Reporting Strategy
      • Reporting in CI
      • Step-Level Reporting
    • CI Optimization
      • Playwright Parallelization
      • Orchestration Setup
      • Fully Parallel Mode
      • Re-run Only Failed Tests
      • Cloud Spot Instances
      • Failing Fast
      • Load Balancing
    • Code Coverage
      • Code Coverage for Playwright
      • Code Coverage for Cypress
    • Currents Actions
      • Setup Currents Actions
      • Using Currents Actions
      • Reference
        • Conditions
        • Actions
    • Playwright Component Testing
    • Playwright Visual Testing
    • Playwright Annotations
    • Playwright Tags
    • MCP Server
  • Dashboard
    • Projects
      • Projects Summary view
      • Project Settings
      • Archive and Unarchive Projects
    • Runs
      • Run Status
      • Run Details
      • Commit Information
      • Tags
      • Run Timeouts
      • Cancelling Runs
      • Deleting Runs
      • Run Progress
    • Tests
      • Spec File Status
      • Test Status
      • Flaky Tests
      • Test History
    • Test Suite Explorer
      • Test Explorer
        • Tests Performance
      • Spec Files Explorer
        • Spec Files Performance
      • Errors Explorer
  • Automated Reports
  • Insights and Analytics
  • Administration
    • Email Domain Based Access
    • SSO SAML2.0
      • SAML2.0 Configuration
      • SCIM User Provisioning
      • IdP-initiated Sessions
      • JumpCloud
        • JumpCloud User provisioning
      • Okta
        • Okta User provisioning
      • Troubleshooting SSO
    • Billing & Usage
  • Billing and Pricing
  • Resources
    • Reporters
      • cypress-cloud
        • Batched Orchestration
        • Migration to Cypress@13
      • @currents/cli
      • @currents/playwright
        • Configuration
        • pwc
        • pwc-p (orchestration)
        • Playwright Fixtures
      • @currents/jest
      • @currents/node-test-reporter
      • @currents/cmd
        • currents api
        • currents upload
        • currents cache
        • currents convert
      • Data Format Reference
    • Integrations
      • GitHub
        • GitHub App
        • GitHub OAuth
      • GitLab
      • Slack
      • Microsoft Teams
      • HTTP Webhooks
      • Bitbucket
    • API
      • Introduction
      • Authentication
      • API Keys
      • Errors
      • Pagination
      • API Resources
        • Instances
        • Runs
        • Projects
        • Spec Files
        • Test Signature
        • Test Results
    • Data Privacy
      • Access to Customer Data
      • Data Retention
      • Cloud Endpoints
    • Support
Powered by GitBook
On this page
  • Setting up the Currents reporter
  • Instrumenting the code
  • Playwright Fixtures for Code Coverage
  • Update tests to use new test method
  • NextJS + Babel Example

Was this helpful?

  1. Guides
  2. Code Coverage

Code Coverage for Playwright

Learn how to enable Code Coverage reporting for Playwright

PreviousCode CoverageNextCode Coverage for Cypress

Last updated 5 months ago

Was this helpful?

  • Follow the to get notified when we enable V8 coverage reports

  • Check out the

Reporting code coverage to Currents as part of running your Playwright tests consist of 3 steps:

  1. Setting up the project

  2. Instrumenting the code

  3. Configuring Playwright coverage fixtures

  4. Updating the tests code

Setting up the Currents reporter

Requires@currents/playwright v1.7.0+

Install and configure Currents reporter following Playwright: Quick Start. Make sure that @currents/playwright reporter is configured with the right Record Key and Project ID.

By default Currents reporter uploads all discovered coverage reports, you can include only certain Playwright projects by setting the coverage projects option, when using the reporter

playwright.config.ts
import {
  CurrentsConfig,
  CurrentsFixtures,
  currentsReporter,
  CurrentsWorkerFixtures,
} from "@currents/playwright";
import { defineConfig, PlaywrightTestConfig } from "@playwright/test";

const currentsConfig: CurrentsConfig = {
  recordKey: "xxx",
  projectId: "yyy",
  coverage: {
    projects: ['projectA', 'projectB],
  },
};

const config = defineConfig<CurrentsFixtures, CurrentsWorkerFixtures>({
  use: {
    ...
    currentsConfigOptions: currentsConfig,
  },

  reporter: [currentsReporter(currentsConfig)],
  ...
});

export default config;

or setting the --pwc-coverage projectA,projectB when using the pwc CLI command

npx pwc --key <record-key> --project-id <project-id> --pwc-coverage projectA,projectB

To check other configuration options run pwc command with the --help flag.

Instrumenting the code

Use the table below for enabling Istanbul instrumentation for your framework / bundler.

Bundler
Plugin

webpack

vite

rollup

swc

esbuild

Once enabled, you'd be able to see window.__coverage__ object in your browser's console when opening your webapp. Don't hesitate to contact Currents Support if you need help with instrumenting your code.

Playwright Fixtures for Code Coverage

base.ts
   import {
     CurrentsFixtures,
     CurrentsWorkerFixtures,
     fixtures,
   } from "@currents/playwright";
   import { test as base } from "@playwright/test";
   
   export const test = base.extend<CurrentsFixtures, CurrentsWorkerFixtures>({
     ...fixtures.baseFixtures,
     ...fixtures.coverageFixtures,
   });

Update tests to use new test method

Import and use the extended test for every test case to enable automatic collection of coverage reports

import { expect } from "@playwright/test";
import { test } from "./base.ts";

After completing this step and running the tests, Currents reporter will automatically merge and upload for post-processing the coverage reports. There's no need to run explicit upload commands.

NextJS + Babel Example

Install babel-plugin-istanbul

npm i -D babel-plugin-istanbul

Update (or create) babel.config.js

babel.config.js
module.exports = {
  presets: ["next/babel"],
  plugins: ["istanbul"],
};

After completing this step, your app's code is instrumented. Running npm run dev and opening your browser will activate the underlying code coverage methods and you'll see coverage information in window.__coverage__ object.

Note that Playwright tests use the extended test.extend command with Currents coverage fixtures. Running Playwright tests npm run test will activate a pre-configured Currents reporter and will send the code coverage information together with the rest of the results:

(experimental)

@currents/playwright provides a set of that simplify extraction and collection of coverage reports.

It is a good practice to the default Playwright test method, for example to enable , between multiple tests etc. See Playwright Fixtures for more information.

We will be using the to configure code coverage reporting for NextJS + babel.

feature request
example GitHub repository
Playwright fixtures
extend
Page Object Model
sharing a state
example GitHub repository
babel-plugin-istanbul
vite-plugin-istanbul
rollup-plugin-istanbul
swc-plugin-coverage-instrument
esbuild-plugin-instanbul
Exploring window.__coverage__ object