jest-playwright
jest-playwright copied to clipboard
Merge the coverage information into the Jest coverage output
Is your feature request related to a problem? Please describe.
Currently, when set collectCoverage
to true
, jest-playwright
can collect the code coverage information from babel-plugin-istanbul
and output the coverage to .nyc_output
. Since Jest can already output the coverage, it's better to merge the coverage into the Jest itself so that users can see the code coverage both from unit tests and e2e tests in one place.
$ yarn run test
PASS test/primeDeco.test.js <--- a jest unit test
PASS test/fibonacci.test.js <--- a jest-playwright e2e test
Test Suites: 2 passed, 2 total
Tests: 7 passed, 7 total
Snapshots: 0 total
Time: 4.718s
Ran all test suites.
--------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
fibonacci.js | 100 | 100 | 100 | 100 | | <--- coverage by jest-playwright e2e test
primeDeco.js | 100 | 100 | 100 | 100 | | <--- coverage by jest unit test
--------------|----------|----------|----------|----------|-------------------|
Describe the solution you'd like
Create a jest reporter to inject the coverage information from window.__coverage__
to Jest context. This reporter will use istanbul-lib-coverage to merge the coverage information from two sources.
Describe alternatives you've considered
N/A
Additional context
I've developed something very similar for jest-puppeteer: jest-puppeteer-istanbul. I would like to add this feature to jest-playwright if you guys think it's a good idea. By adding this feature to this repo instead of creating a separate package, users can skip the complex setup steps and let jest-playwright-preset
do the work for them.
@ocavue thanks for your suggestion. I think that can be helpful feature, but only thing that i want is to give developer ability to control this reporter. So it will be nice if it'll be configurable
@mmarkelov Thank you for your response. We can add a new configuration field coverageOutput
to JestPlaywrightConfig
, which controls how the coverage collection output.
export interface JestPlaywrightConfig {
/**
* The coverage output format. If includes `'files'`, save the coverage collection
* to the `.nyc_output/coverage.json` file. If includes `'jest'`, save the coverage
* collection as part of Jest's coverage output.
*
* @default ['files']
*/
coverageOutput?: Array<'file' | 'jest'>
}
I don't know which definition is better: coverageOutput?: Array<'file' | 'jest'>
or coverageOutput?: 'file' | 'jest' | 'all'
. Do you have any suggestion?
@ocavue good question. For me it's better the second one, i thinks it's more cleaner
Discovered https://github.com/ccpu/jest-playwright-istanbul which seems to do the trick.
It would be nice if this module also automatically collected coverage (likely via nyc cli) for the server command and merged that in as well.