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

Getting all "Unknown% ( 0/0 )" in coverage results #433

Closed
szalapski opened this issue Mar 7, 2019 · 9 comments
Closed

Getting all "Unknown% ( 0/0 )" in coverage results #433

szalapski opened this issue Mar 7, 2019 · 9 comments

Comments

@szalapski
Copy link

szalapski commented Mar 7, 2019

Environment

  1. node -v: v10.13.0

  2. npm -v: 6.4.1

  3. npm ls jest or npm ls react-scripts (if you haven’t ejected): [email protected]

  4. your vscode-jest settings if customized:

    • jest.pathToJest? Do not have
    • jest.pathToConfig? Do not have
    • in jest.config.js:
      collectCoverage: true,
      collectCoverageFrom: ['ClientApp/src/**/*.{js,vue}'],
      coverageReporters: ['text-summary'],
    • in settings.json:
      "jest.rootPath": "web",
      "jest.debugMode": true,
      "jest.showCoverageOnLoad": true,
  5. Operating system: Windows 10

Prerequisite

  • are you able to run jest test from command line? yes
  • how do you run your tests from command line? (for example: npm run test or node_modules/.bin/jest) These all work well, showing code coverage summary with interesting results:
    npm run test
    npm test -- --coverage
    node node_modules/jest/bin/jest.js

Steps to Reproduce

Start VS Code with a solution with tests. Run the tests by the command "Jest: Start Runner" in VS Code. Look into the Jest output window and see the tests run.

Relevant Debug Info

I get no errors or issues in the Jest output window or in the developer console.

Expected Behavior

Tests run and pass/fail appropriately in VS Code, and I should get a coverage report in the Jest output window with meaningful results

Actual Behavior

Tests run and pass/fail appropriately in VS Code, but I get:

=============================== Coverage summary ===============================
Statements   : Unknown% ( 0/0 )
Branches     : Unknown% ( 0/0 )
Functions    : Unknown% ( 0/0 )
Lines        : Unknown% ( 0/0 )
================================================================================

(This also prevents me from seeing any red highlights for coverage in VS Code text editors.)

@szalapski
Copy link
Author

szalapski commented Mar 7, 2019

I feel I must have some configuration wrong to get coverage to work, but not sure what it could be. I've done everything I can think of that the README points to. Any help to point me toward further setup for coverage would be appreciated.

@rynti
Copy link

rynti commented Mar 14, 2019

I'm having the same problem. It seems that actually after the initial test run, for a brief moment the coverage data is correct - however directly after it enters watch mode and reruns a test it immediately discards the previous result and outputs a coverage with no files and thus also 0 lines etc.

(Additionally, I'm using TypeScript with babel-jest, but that shouldn't have an impact on this)

@tomexx
Copy link

tomexx commented Jun 21, 2019

Same issue here.

"jest": "24.8.0",
"jest-junit": "^6.4.0"

@spyros-uk
Copy link

Same issue here, I am using CRA with Typescript and rescripts.

Dependencies

node: v10.15.0
npm: 6.4.1
react-scripts: 3.0.1
typescript: 3.4.5
@rescripts/cli: 0.0.10

Jest config

{
  ...config,
  setupFiles: ["<rootDir>//test/jest-config/setup.js"],
  testURL: "http://localhost",
  collectCoverage: true,
  coverageReporters: ["json", "html"],
  collectCoverageFrom: ["<rootDir>/src/**/*.{ts,tsx,js,jsx}"],
  testEnvironment: "node",
  transformIgnorePatterns: [
    "<rootDir>/node_modules/(?!(lodash-es|react-apollo)/).+\\.(mjs|js|jsx|ts|tsx)$"
  ],
  transform: {
    ...config.transform,
    "^.+\\.(graphql|gql)$": "jest-transform-graphql"
  },
  moduleFileExtensions: [...testExtensions, ...prevTestExtensions]
}

Result:
coverage_terminal

coverage_html

@connectdotz
Copy link
Collaborator

connectdotz commented Jun 21, 2019

vscode-jest spawns a jest child process then parsing its output for coverageMap, therefore the first thing is to make sure the jest run does produce the coverageMap... a few things to check:

  • turn on the debug mode per troubleshooting, you should be able to see output in the developer console like this:
spawning process with command=yarn, args=test,--testLocationInResults,--json,--useStderr,--outputFile,/var/folders/kv/r07v4crd5qx_kd6959jjdmb80000gn/T/jest_runner_dots_core.json,--no-color
  • check if the command/args is what you expected. For example, if you usually run jest in the terminal window with my-own-test.sh, then you should expect the debug output: command=my-own-test.sh, args='--testLocationInResults,--json,--useStderr,.... If the command is not what you expected, chances are you will need to customize the jest.pathToJest to tell this extension what you want it to run.

  • if the above is correct, then you can look at the json output file, /var/folders/kv/r07v4crd5qx_kd6959jjdmb80000gn/T/jest_runner_dots_core.json in the abvoe example, to see if you see the correct coverageMap output there.

  • narrow down the problem: after going through the steps above, if there is a valid coverageMap in the json output file but vscode-jest failed to display the coverage, then the bug is in vscode-jest. If the coverageMap is all 0 then the issue is most likely related to the jest configuration.

Let us know what you find...

@rickyblaha
Copy link

I had the same issue, running npm test -- --coverage resulted in 0 statements found in the text report.

But by simply adding the CI=1 environment variable so jest does not run in interactive mode, it produced the expected coverage reports: CI=1 npm test -- --coverage

@szalapski
Copy link
Author

This sounds like some good answers. I will perhaps try them later, but I'm moving on for now.

adamcaron added a commit to raft-tech/TANF-app that referenced this issue Jul 30, 2020
Add scripts for CI and for local code coverage
- test:ci for CI
- test:cov to see code coverage locally. Because running with coverage
  slows down the test suite, this was added as an optional script.
  The --watchAll flag was added to `test:cov` because there is an issue
  where coverage reports 0/0% when tests run in interactive mode.
  jestjs/jest#7331
  jest-community/vscode-jest#433

Have ESLint and Git ignore the coverage output

Add tests for the App component

Update README with unit test instructions
RafterGit pushed a commit to raft-tech/TANF-app that referenced this issue Aug 6, 2020
Add scripts for CI and for local code coverage
- test:ci for CI
- test:cov to see code coverage locally. Because running with coverage
  slows down the test suite, this was added as an optional script.
  The --watchAll flag was added to `test:cov` because there is an issue
  where coverage reports 0/0% when tests run in interactive mode.
  jestjs/jest#7331
  jest-community/vscode-jest#433

Have ESLint and Git ignore the coverage output

Add tests for the App component

Update README with unit test instructions
RafterGit pushed a commit to raft-tech/TANF-app that referenced this issue Aug 6, 2020
Add scripts for CI and for local code coverage
- test:ci for CI
- test:cov to see code coverage locally. Because running with coverage
  slows down the test suite, this was added as an optional script.
  The --watchAll flag was added to `test:cov` because there is an issue
  where coverage reports 0/0% when tests run in interactive mode.
  jestjs/jest#7331
  jest-community/vscode-jest#433

Have ESLint and Git ignore the coverage output

Add tests for the App component

Update README with unit test instructions
adamcaron added a commit to raft-tech/TANF-app that referenced this issue Aug 21, 2020
Add scripts for CI and for local code coverage
- test:ci for CI
- test:cov to see code coverage locally. Because running with coverage
  slows down the test suite, this was added as an optional script.
  The --watchAll flag was added to `test:cov` because there is an issue
  where coverage reports 0/0% when tests run in interactive mode.
  jestjs/jest#7331
  jest-community/vscode-jest#433

Have ESLint and Git ignore the coverage output

Add tests for the App component

Update README with unit test instructions
RafterGit pushed a commit to raft-tech/TANF-app that referenced this issue Aug 26, 2020
Add scripts for CI and for local code coverage
- test:ci for CI
- test:cov to see code coverage locally. Because running with coverage
  slows down the test suite, this was added as an optional script.
  The --watchAll flag was added to `test:cov` because there is an issue
  where coverage reports 0/0% when tests run in interactive mode.
  jestjs/jest#7331
  jest-community/vscode-jest#433

Have ESLint and Git ignore the coverage output

Add tests for the App component

Update README with unit test instructions
@bttger
Copy link

bttger commented Mar 25, 2021

I also had the 0% coverage problem when running jest with the --config= option. The problem was that jest assumes the configPath to be the root directory and thus doesn't find any files to check the coverage for.

My solution was simply to go higher in the directory tree:

{
  "rootDir": "../.",
  ...
}

@erperejildo
Copy link

This sounds like some good answers. I will perhaps try them later, but I'm moving on for now.

any of this worked?

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

No branches or pull requests

8 participants