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

@nrwl/jest schema.json defines a --coverage option that does not seem to affect coverage output #2564

Closed
derek-pavao opened this issue Feb 26, 2020 · 4 comments · Fixed by #2569
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug

Comments

@derek-pavao
Copy link
Contributor

Expected Behavior

The schema.json for the jest builder defines an option called --coverage https://github.com/nrwl/nx/blob/master/packages/jest/src/builders/jest/schema.json#L110

"coverage": {
      "description": "Indicates that test coverage information should be collected and reported in the output. This option is also aliased by --collectCoverage. (https://jestjs.io/docs/en/cli#coverage)",
      "type": "boolean"
    }

I would expect running npx nx test <app-name> --coverage=false would not generate coverage output, and npx nx test <app-name> --coverage=true would generate coverage output.

Current Behavior

The --coverage flag seems to be ignored when passed on the command line, and whatever is in the jest.confg file for coverage settings is used

Failure Information (for bugs)

Steps to Reproduce

I have created a minimal repo to reproduce the issue https://github.com/dotDeeka/nx-coverage-repro

  1. clone the git repo
  2. npm install
  3. run npx nx test example-app --coverage=true
    The coverage reporter is set to text in the jest config, but there is no coverage report printed to the terminal

Other

I have done a bit of preliminary investigation and I discovered that there is another, similar option --codeCoverage and setting this to true or false works as expected. Looking at the implementation (https://github.com/nrwl/nx/blob/master/packages/jest/src/builders/jest/jest.impl.ts) it appears that the --coverage option isn't actually passed to jest at all, unless I'm reading it wrong, or --coverage is meant for something else and I'm misunderstanding.

@derek-pavao
Copy link
Contributor Author

Could this be fixed with something as simple as changing this line (https://github.com/nrwl/nx/blob/master/packages/jest/src/builders/jest/jest.impl.ts#L95) to

coverage: options.codeCoverage ?? options.coverage,

@vsavkin vsavkin added scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug labels Feb 27, 2020
@vsavkin
Copy link
Member

vsavkin commented Feb 27, 2020

It's a bug. The codeCoverage option is used to indicate the coverage. I'd delete the coverage option and leave only codeCoverage. Would you like to submit a PR?

@derek-pavao
Copy link
Contributor Author

Sure, I would be glad to

derek-pavao pushed a commit to derek-pavao/nx that referenced this issue Feb 27, 2020
the --coverage option was not being used in the builder at all, so provided no change in behavior.
The --codeCoverage option should be used instead

ISSUES CLOSED: nrwl#2564
rarmatei pushed a commit that referenced this issue Feb 27, 2020
the --coverage option was not being used in the builder at all, so provided no change in behavior.
The --codeCoverage option should be used instead

ISSUES CLOSED: #2564
@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants