Coverage folder not created

See original GitHub issue

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

Report Bug

What is the current behavior?

When running jest --coverage no /coverage folder is output. This is showing the settings of Jest in the package.json

  "jest": {
    "coverageDirectory": "/coverage/",
    "coveragePathIgnorePatterns": [
      "/node_modules/",
      "/.node/",
      "/jest/"
    ]
  },

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.

Run jest --coverage see coverage folder created then removed. The command line experience still shows the coverage output, but not .lcov or html report is generated that persists.

What is the expected behavior?

The /coverage folder should persist and be replaced next run.

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

node: 6.9.1 npm: 4.1.2 jest: 18.1.0 yarn: 0.20.0

Confirmed on both OSX and GitLab CI Node docker image (linux).

Output from GitLab-CI

$ npm --silent run test:coverage || true
 PASS  __tests__/pages/index.test.js
  With Enzyme
    ✓ App shows "Hello world!" (22ms)
  With Snapshot Testing
    ✓ App shows "Hello world!" (16ms)

----------|----------|----------|----------|----------|----------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files |      100 |      100 |      100 |      100 |                |
 index.js |      100 |      100 |      100 |      100 |                |
----------|----------|----------|----------|----------|----------------|
Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   1 passed, 1 total
Time:        3.004s
Ran all test suites.
$ ls -al
total 320
drwxrwxrwx.   9 root root   4096 Feb  7 13:52 .
drwxrwxrwx.   4 root root   4096 Feb  7 13:51 ..
drwxrwxrwx.   5 root root   4096 Feb  7 13:51 .git
-rw-rw-rw-.   1 root root   1575 Feb  7 13:51 .gitignore
-rw-rw-rw-.   1 root root    584 Feb  7 13:51 .gitlab-ci.yml
-rw-rw-rw-.   1 root root   1098 Feb  7 13:51 .gitlab-ci.yml.bkup
-rw-rw-rw-.   1 root root     12 Feb  7 13:51 CHANGELOG.md
-rw-rw-rw-.   1 root root    628 Feb  7 13:51 README.md
drwxrwxrwx.   3 root root   4096 Feb  7 13:51 __tests__
drwxrwxrwx.   2 root root   4096 Feb  7 13:51 assets
drwxrwxrwx.   2 root root   4096 Feb  7 13:51 env
-rw-r--r--.   1 root root   3958 Feb  7 13:52 eslint-report.html
drwxr-xr-x.   3 root root   4096 Feb  7 13:52 jest
drwxr-xr-x. 688 root root  24576 Feb  7 13:52 node_modules
-rw-rw-rw-.   1 root root   2369 Feb  7 13:51 package.json
drwxrwxrwx.   2 root root   4096 Feb  7 13:51 pages
-rw-rw-rw-.   1 root root 168719 Feb  7 13:51 yarn.lock
Creating cache reports/15-setup-gitlab-ci-pipeline...
Created cache
Uploading artifacts...
eslint-report.html: found 1 matching files         
WARNING: coverage/: no matching files    

Notice that ls -al shows no coverage/ directory.

Locally when I run jest --coverage it throws permissions errors because it can not create folder /coverage. I run under sudo jest --coverage and the folder is created and remove. sudo is not needed on GitLab CI. I did everything I could to remove need for sudo locally and can not confirm what is causing it. No other application requires this. jest/ folder is created without sudo fine.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
deadratfinkcommented, May 10, 2017

Hi, I could solve this problem by passing coverageDirectory: './coverage/', or even coverageDirectory: '<rootdir>/coverage/', in my ./.jestrc.js file (no permission errors nor sudo needed!). Maybe this helps you too…

I call it with:

"scripts": {
  "test": "jest --coverage --config=./.jestrc.js"
}
8reactions
ifeanyiisitorcommented, May 17, 2019

I know that this has been closed for a while, but thought I’d post this to bring proper closure to this issue for the sake of others that may come here in the future seeking answers. The OP stated the following:

This was resolved by removing coverage data from package.json

This statement suggests that the intention was to generate the coverage folder in the root of the node package (i.e., at the same level with the package.json file), seeing that that is what would happen when the coverage settings are removed from the jest config in the package.json file. However, by setting the coverageDirectory to /coverage/, what is being stated is that the intention is to generate the coverage folder in the root (i.e., top most level) directory of the machine and because the current user account does not own that directory, it throws a permissions error. If the intention is for the coverage folder to be generated in the root of the node package (as opposed to the topmost directory on the machine), then the coverageDirectory setting needs to be set to ./coverage/ instead of /coverage/. So really, this is not a bug. It’s actually the expected behaviour, and @deadratfink’s solution is not a workaround, but the actual way to achieve what is really intended.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular karma code coverage report folder not generated
The reason, your code coverage is not generating is that, there are some ... Generate fresh code coverage folder through following command
Read more >
Angular karma code coverage report folder not generated
When I run ng test --code-coverage , The coverage report is sometimes not generating, sometimes it is generating so I'm unable to verify...
Read more >
Angular karma code coverage report folder not generated ...
The reason, your code coverage is not generating is that, there are some broken unit tests which stops the generation of the code...
Read more >
Find out how much code you're testing - Angular
When the tests are complete, the command creates a new /coverage folder in the project. Open the index.html file to see a report...
Read more >
Angular CLI - Code Coverage - Tutorialspoint
Now ng test command has created a coverage folder within the TutorialsPoint, the project folder and has prepared the coverage report in html...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found