{"id":20731674,"url":"https://github.com/bgotink/playwright-coverage","last_synced_at":"2025-04-05T06:03:23.286Z","repository":{"id":43093154,"uuid":"408254305","full_name":"bgotink/playwright-coverage","owner":"bgotink","description":"Track coverage in playwright tests","archived":false,"fork":false,"pushed_at":"2025-03-10T20:54:46.000Z","size":2452,"stargazers_count":42,"open_issues_count":8,"forks_count":17,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-29T05:01:46.034Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bgotink.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-19T22:51:39.000Z","updated_at":"2025-03-11T17:52:01.000Z","dependencies_parsed_at":"2024-06-20T21:57:10.661Z","dependency_job_id":"4971c87f-da01-47d8-8f56-59797ff2e51e","html_url":"https://github.com/bgotink/playwright-coverage","commit_stats":{"total_commits":31,"total_committers":6,"mean_commits":5.166666666666667,"dds":"0.19354838709677424","last_synced_commit":"74f2eabc1eafccb943faad16615ea040c14f5290"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bgotink%2Fplaywright-coverage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bgotink%2Fplaywright-coverage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bgotink%2Fplaywright-coverage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bgotink%2Fplaywright-coverage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bgotink","download_url":"https://codeload.github.com/bgotink/playwright-coverage/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247294516,"owners_count":20915340,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T05:16:23.663Z","updated_at":"2025-04-05T06:03:23.234Z","avatar_url":"https://github.com/bgotink.png","language":"TypeScript","readme":"# `@bgotink/playwright-coverage` [![Latest published version on NPM](https://img.shields.io/npm/v/@bgotink/playwright-coverage)](https://npm.im/@bgotink/playwright-coverage)\n\nReport coverage on playwright tests using v8 coverage, without requiring any instrumentation.\n\n## Usage\n\nInstall this package\n\n```bash\nyarn add -D @bgotink/playwright-coverage\n```\n\nThen add the reporter to your playwright configuration:\n\n```ts\nimport {defineCoverageReporterConfig} from '@bgotink/playwright-coverage';\nimport {defineConfig} from '@playwright/test';\n\nexport default defineConfig({\n  // ...\n\n  reporter: [\n    ['list'],\n    [\n      '@bgotink/playwright-coverage',\n      defineCoverageReporterConfig({\n        /* Path to the root files should be resolved from, most likely your repository root */\n        sourceRoot: __dirname,\n        /* Files to ignore in coverage, useful\n           - if you're testing the demo app of a component library and want to exclude the demo sources\n           - or part of the code is generated\n           - or if you're running into any of the other many reasons people have for excluding files */\n        exclude: ['path/to/ignored/code/**'],\n        /* Directory in which to write coverage reports */\n        resultDir: path.join(__dirname, 'results/e2e-coverage'),\n        /* Configure the reports to generate.\n           The value is an array of istanbul reports, with optional configuration attached. */\n        reports: [\n          /* Create an HTML view at \u003cresultDir\u003e/index.html */\n          ['html'],\n          /* Create \u003cresultDir\u003e/coverage.lcov for consumption by tooling */\n          [\n            'lcovonly',\n            {\n              file: 'coverage.lcov',\n            },\n          ],\n          /* Log a coverage summary at the end of the test run */\n          [\n            'text-summary',\n            {\n              file: null,\n            },\n          ],\n        ],\n        /* Configure watermarks, see https://github.com/istanbuljs/nyc#high-and-low-watermarks */\n        // watermarks: {},\n      }),\n    ],\n  ],\n});\n```\n\nNow replace all calls to `@playwright/test`'s `test` variable with a variant that tracks coverage.\nThe easiest way to do this is by importing `test` from `@bgotink/playwright-coverage` instead.\n\n```diff\n-import {expect, test} from '@playwright/test';\n+import {expect, test} from '@bgotink/playwright-coverage';\n```\n\nIf you're already using a different `test` function, e.g. if you're using [`@ngx-playwright/test`](https://github.com/bgotink/ngx-playwright), you can add coverage tracking using the `mixinFixtures` function:\n\n```ts\nimport {test as base} from '@ngx-playwright/test'; // or wherever your test function comes from\nimport {mixinFixtures as mixinCoverage} from '@bgotink/playwright-coverage';\n\nexport const test = mixinCoverage(base);\n```\n\nor you can use `mergeTests` if you're using playwright ≥ 1.40.0:\n\n```ts\nimport {mergeTests} from '@playwright/test';\nimport {test as testWithCoverage} from '@bgotink/playwright/coverage';\nimport {test as otherTest} from '@ngx-playwright/test'; // or wherever your test function comes from\n\nexport const test = mergeTests(\n  testWithCoverage,\n  otherTest,\n);\n```\n\nNow replace all usage of `test` with the function export defined there, and coverage will be tracked.\n\n## How does it work?\n\nThe fixtures registered in `test` or via `mixinFixtures` hook into created [`Page`s](https://playwright.dev/docs/api/class-page) to track javascript coverage with v8. The coverage data is added as attachment to every test.\n\nUpon completion of all tests, the reporter merges all generated coverage files into one and then converts the v8 coverage format into the coverage format used by istanbul. The istanbul data is then passed into the reports of `istanbul-reports`.\n\n## Common issues\n\n**The HTML report shows errors saying the source files couldn't be read**\n\nThis means the reporter is looking in the wrong place because playwright and the server process are using paths relative to a different working folder.\n\nTry setting the `sourceRoot` folder. If you need more control over the actual path of the files, pass a `rewritePath` property in the options:\n\n```ts\n{\n  sourceRoot: __dirname,\n\n  /**\n   * Modify the paths of files on which coverage is reported\n   *\n   * The input is an object with two properties:\n   * - absolutePath\n   * - relativePath\n   * both are strings and they represent the absoslute and relative\n   * path of the file as computed based on the source map.\n   *\n   * Return the rewritten path. If nothing is returned, `absolutePath`\n   * is used instead.\n   */\n  rewritePath: ({absolutePath, relativePath}) =\u003e {\n    return absolutePath;\n  },\n}\n```\n\n**Coverage is empty**\n\nDid you perhaps use `@playwright/test`'s own `test` function?\nIf you don't use a `test` function created using `mixinCoverage`, coverage won't be tracked and the reporter won't have anything to report on.\n\n## Status\n\nThis project is very experimental. It has been proven to work on one angular application, i.e. with webpack with the unmodified configuration angular applies to it.\n\n## License\n\nLicensed under the MIT license, see `LICENSE.md`.\n","funding_links":[],"categories":["Utils","Recently Updated","Testing"],"sub_categories":["[Mar 09, 2025](/content/2025/03/09/README.md)","E2E"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbgotink%2Fplaywright-coverage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbgotink%2Fplaywright-coverage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbgotink%2Fplaywright-coverage/lists"}