Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge the coverage information into the Jest coverage output #591

Open
ocavue opened this issue Feb 22, 2021 · 4 comments
Open

Merge the coverage information into the Jest coverage output #591

ocavue opened this issue Feb 22, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@ocavue
Copy link
Contributor

ocavue commented Feb 22, 2021

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.

@mmarkelov mmarkelov added the enhancement New feature or request label Feb 22, 2021
@mmarkelov
Copy link
Member

@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

@ocavue
Copy link
Contributor Author

ocavue commented Feb 22, 2021

@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?

@mmarkelov
Copy link
Member

@ocavue good question. For me it's better the second one, i thinks it's more cleaner

@DylanPiercey
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants