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

Improve the message when run coverage while there are no tests #6141

Closed
tiendq opened this issue May 6, 2018 · 14 comments · Fixed by #6334
Closed

Improve the message when run coverage while there are no tests #6141

tiendq opened this issue May 6, 2018 · 14 comments · Fixed by #6334

Comments

@tiendq
Copy link
Contributor

tiendq commented May 6, 2018

🐛 Bug Report

When you run jest with --coverage but there are no tests, it shows error "Jest: Coverage data for global was not found."

To Reproduce

  1. Delete all test files e.g. *.test.js

  2. Run jest --config=jest.json --coverage with below configuration in jest.json:

{
  "testEnvironment": "node",
  "coverageThreshold": {
    "global": {
      "branches": 90,
      "functions": 90,
      "lines": 90,
      "statements": -10
    }
  },
  "collectCoverageFrom" : [
    "*.js"
  ]
}

Expected behavior

A simple and clear error like "No tests found", or simply skipping coverage, or coverage report as usual (and failed 100%).

Link to repl or repo (highly encouraged)

https://github.com/Tiendq/lego-part-loader

Run npx envinfo --preset jest

System:
    OS: macOS Sierra 10.12.6
  Binaries:
    Node: 10.0.0 - /usr/local/bin/node
    Yarn: 1.6.0 - /usr/local/bin/yarn
    npm: 5.6.0 - /usr/local/bin/npm
  npmPackages:
    jest: ^22.4.3 => 22.4.3 
@misoguy
Copy link
Contributor

misoguy commented May 8, 2018

I'd like to try this if no one is on it 😄

@SimenB
Copy link
Member

SimenB commented May 8, 2018

Go for it :)

@misoguy
Copy link
Contributor

misoguy commented May 9, 2018

I'm looking into this issue and I can't seem to reproduce the issue so I'm quite lost.
I've run jest --config=jest.json --coverage on the repo that @tiendq provided above and got the following message

No tests found
In /Users/jayhwang/Documents/bug-test
  7 files checked.
  testMatch: **/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x) - 0 matches
  testPathIgnorePatterns: /node_modules/ - 7 matches
Pattern:  - 0 matches
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

There is no sign of Jest: Coverage data for global was not found.

I also tried it with the master branch of jest and got the following

No tests found
In /Users/jayhwang/Documents/bug-test
  7 files checked.
  testMatch: **/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x) - 0 matches
  testPathIgnorePatterns: /node_modules/ - 7 matches
Pattern:  - 0 matches

@SimenB
Copy link
Member

SimenB commented May 9, 2018

You need to include --coverage

@misoguy
Copy link
Contributor

misoguy commented May 9, 2018

I did include coverage
jest --config=jest.json --coverage

@tiendq
Copy link
Contributor Author

tiendq commented May 10, 2018

@misoguy I couldn't reproduce it too :(, I checked package.json history and Jest version is still same.

@zlk89
Copy link

zlk89 commented May 10, 2018

I am getting same issue here, my case has one more option: --changedSince=master

@tiendq
Copy link
Contributor Author

tiendq commented May 10, 2018

I could reproduce @zlk89 case, it seems that there is something unstable here.

jest --config=jest.json --coverage --changedSince=master

jest-error

@Oak-V
Copy link

Oak-V commented May 12, 2018

I am getting same issue here, my case only in watch mode --watch.

pakage.json

...
  "jest": {
    "transform": {
      "^.+\\.tsx?$": "ts-jest"
    },
    "testRegex": "/tests/.*\\.spec\\.tsx?$",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js",
      "jsx",
      "json",
      "node"
    ],
    "collectCoverage": true,
    "coverageDirectory": "coverage",
    "coverageThreshold": {
      "global": {
        "branches": 80,
        "functions": 80,
        "lines": 80,
        "statements": -10
      }
    }
  },
...

bash Jest

$ npx jest --watch

No tests found related to files changed since last commit.
Press `a` to run all tests, or run Jest with `--watchAll`.
----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |        0 |        0 |        0 |        0 |                   |
----------|----------|----------|----------|----------|-------------------|
Jest: Coverage data for global was not found.

bash envinfo

$ npx envinfo --preset jest

  System:
    OS: macOS Sierra 10.12.6
    CPU: x64 Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
  Binaries:
    Node: 10.0.0 - /usr/local/bin/node
    Yarn: 1.6.0 - /usr/local/bin/yarn
    npm: 6.0.1 - /usr/local/bin/npm
  npmPackages:
    @types/jest: ^22.2.3 => 22.2.3
    jest: ^22.4.3 => 22.4.3

@zlk89
Copy link

zlk89 commented May 24, 2018

@misoguy kindly ask if there is any update on this?

@misoguy
Copy link
Contributor

misoguy commented May 24, 2018

@zlk89 I'm sorry, lately I didn't really find time... Feel free to take this issue if you'd like, if not I'll try to find time to tackle this issue soon 😄

@tiendq
Copy link
Contributor Author

tiendq commented May 25, 2018

I also want to try it too but it won't be done quickly, I'm new to Jest codebase :) and it seems that the issue happens with many cases.

@rickhanlonii
Copy link
Member

Here's where that error is thrown, should be able to add the check you need somewhere in that function with a nice explination

rhysawilliams2010 pushed a commit to rhysawilliams2010/jest that referenced this issue May 29, 2018
fixes jestjs#6141
Update the coverage reporting so that it still conforms to the
documentation but doesn't throw an error when there are no files matching
"global" threshold group (maybe because they are already matched with a path or glob).
Also make sure that a file is matched against all matching path and glob threshold groups instead of just one.
rhysawilliams2010 pushed a commit to rhysawilliams2010/jest that referenced this issue May 29, 2018
fixes jestjs#6141
Update the coverage reporting so that it still conforms to the
documentation but doesn't throw an error when there are no files matching
"global" threshold group (maybe because they are already matched with a path or glob).
Also make sure that a file is matched against all matching path and glob threshold groups instead of just one.
rhysawilliams2010 pushed a commit to rhysawilliams2010/jest that referenced this issue May 29, 2018
fixes jestjs#6141
Update the coverage reporting so that it still conforms to the
documentation but doesn't throw an error when there are no files matching
"global" threshold group (maybe because they are already matched with a path or glob).
Also make sure that a file is matched against all matching path and glob threshold groups instead of just one.
rhysawilliams2010 pushed a commit to rhysawilliams2010/jest that referenced this issue May 29, 2018
fixes jestjs#6141
Update the coverage reporting so that it still conforms to the
documentation but doesn't throw an error when there are no files matching
"global" threshold group (maybe because they are already matched with a path or glob).
Also make sure that a file is matched against all matching path and glob threshold groups instead of just one.
rhysawilliams2010 pushed a commit to rhysawilliams2010/jest that referenced this issue May 29, 2018
fixes jestjs#6141
Update the coverage reporting so that it still conforms to the
documentation but doesn't throw an error when there are no files matching
"global" threshold group (maybe because they are already matched with a path or glob).
Also make sure that a file is matched against all matching path and glob threshold groups instead of just one.
rhysawilliams2010 pushed a commit to rhysawilliams2010/jest that referenced this issue May 29, 2018
fixes jestjs#6141
Update the coverage reporting so that it still conforms to the
documentation but doesn't throw an error when there are no files matching
"global" threshold group (maybe because they are already matched with a path or glob).
Also make sure that a file is matched against all matching path and glob threshold groups instead of just one.
thymikee pushed a commit that referenced this issue Aug 9, 2018
…6334)

* Improve the message when running coverage while there are no tests
fixes #6141
Update the coverage reporting so that it still conforms to the
documentation but doesn't throw an error when there are no files matching
"global" threshold group (maybe because they are already matched with a path or glob).
Also make sure that a file is matched against all matching path and glob threshold groups instead of just one.

* use Object.assign

* Only mock specific functions exported by istanbul-lib-coverage
(instead of the whole module).
So that I can use the original createCoverageSummary function to
create test data.

* Add e2e tests for coverage threshold.
I added snapshots for stderr so that I could test the Jest errors raised for each failed threshold group.

* revert unnecessary test changes

* linting

* Replace process.cwd() in stderr snapshot test.

* Make the tests more robust by using extractSummary method to compare
stderr snapshots.
Do a replace on the stderr which has a full path to a failed
glob threshold file which won't match when the test runs on windows
(appveyor)

* move changelog entry
@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 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants