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

<rootDir> is not respected by collectCoverageFrom #5499

Closed
StephanBijzitter opened this issue Feb 8, 2018 · 3 comments
Closed

<rootDir> is not respected by collectCoverageFrom #5499

StephanBijzitter opened this issue Feb 8, 2018 · 3 comments

Comments

@StephanBijzitter
Copy link
Contributor

Do you want to request a feature or report a bug?
I want to report a bug.

What is the current behavior?
When using <rootDir>/foo/bar as a value for collectCoverageFrom, no coverage is being collected at all.
screen shot 2018-02-08 at 23 00 57
However, using foo/bar does work as expected.

If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install and yarn test.

Take your own config and edit (or add) your collectCoverageFrom field with a value that starts with <rootDir>; then run jest with coverage enabled (yarn jest --coverage).

What is the expected behavior?
Coverage results are the same for both <rootDir>/foo/bar and foo/bar (where cwd is the root dir).

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

Yarn 1.3.2, Jest 22.2.1, ts-jest 22.0.3, Node 8.9.1.

Jest config:

  {
    "automock": false,
    "resetModules": true,
    "collectCoverage": false,
    "coverageDirectory": "<rootDir>/coverage/jest",
    "collectCoverageFrom": [
      "<rootDir>/packages/*/src/**/*.js",
      "<rootDir>/packages/*/src/**/*.ts",
      "!<rootDir>/packages/*/src/**/index.*",
      "!<rootDir>/packages/*/src/**/*.spec.*",
      "!<rootDir>/packages/*/src/**/*.snapshot.*"
    ],
    "testMatch": [
      "<rootDir>/packages/*/src/**/*.spec.js",
      "<rootDir>/packages/*/src/**/*.spec.ts"
    ],
    "moduleFileExtensions": [
      "js",
      "ts",
      "json"
    ],
    "transform": {
      "^.+\\.ts$": "ts-jest"
    }
  }
@SimenB
Copy link
Member

SimenB commented Feb 11, 2018

This is expected, as the docs point out it's relative to rootDir in the first place. I agree it's confusing though, PR welcome to at least strip out <rootDir>/ if it's provided.

https://github.com/facebook/jest/blob/f29c03ea0c97d97aede05b5c1a97ce04a953d3f9/packages/jest-cli/src/cli/args.js#L154-L159

@StephanBijzitter
Copy link
Contributor Author

StephanBijzitter commented Feb 11, 2018

Ah, yeah it would be nice for consistency if rootDir can be used, even if it means ignoring it. Will take a look, this sounds like a nice first contribution!

Edit: after searching through the repository I guess this would be the place to strip out any rootDir usage: https://github.com/facebook/jest/blob/1947496728db13a4f271dfef8e9b9cecdcb9ee40/packages/jest-config/src/normalize.js#L130-L164

Seems easy enough at first sight :-)

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants