Coverage folder not created
See original GitHub issueDo 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:
- Created 7 years ago
- Reactions:1
- Comments:9 (1 by maintainers)
Top Related StackOverflow Question
Hi, I could solve this problem by passing
coverageDirectory: './coverage/',or evencoverageDirectory: '<rootdir>/coverage/',in my ./.jestrc.js file (no permission errors norsudoneeded!). Maybe this helps you too…I call it with:
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 statement suggests that the intention was to generate the
coveragefolder 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 thecoverageDirectoryto/coverage/, what is being stated is that the intention is to generate thecoveragefolder 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 thecoveragefolder to be generated in the root of the node package (as opposed to the topmost directory on the machine), then thecoverageDirectorysetting 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.