Description
Do you want to request a feature or report a bug?
Bug report.
What is the current behavior?
Moving a source file doesn't seem to bust the Jest cache. This causes the default coverage reporter to report missing coverage on the moved file in the new location, and report full coverage on the moved file in the old location.
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
.
Here is my src dir structure:
$ tree src/
src/
├── components
│ └── Example
│ └── README.md
├── foo
│ └── index.js
└── scss
└── index.scss
4 directories, 3 files
Running jest before moving index.js
:
$ ./node_modules/.bin/jest --config jest.config.js
PASS tests/components/example.test.js
ExampleComponent
✓ renders all the right stuff (15ms)
✓ passes a snapshot test (8ms)
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 1 passed, 1 total
Time: 1.598s, estimated 2s
Ran all test suites.
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
----------|----------|----------|----------|----------|----------------|
Moving index.js
:
$ mv src/foo/index.js src/components/Example/
$ tree src/
src/
├── components
│ └── Example
│ ├── index.js
│ └── README.md
└── scss
└── index.scss
3 directories, 3 files
Rerunning Jest after moving index.js
(and updating the import
statement in the test):
$ ./node_modules/.bin/jest --config jest.config.js
PASS tests/components/example.test.js
ExampleComponent
✓ renders all the right stuff (15ms)
✓ passes a snapshot test (8ms)
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 1 passed, 1 total
Time: 1.628s, estimated 2s
Ran all test suites.
--------------------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
--------------------|----------|----------|----------|----------|----------------|
All files | 4.76 | 0 | 20 | 20 | |
components/Example | 0 | 0 | 0 | 0 | |
index.js | 0 | 0 | 0 | 0 | 1,3,5,6 |
foo | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
--------------------|----------|----------|----------|----------|----------------|
Jest: Coverage for statements (4.76%) does not meet global threshold (100%)
Jest: Coverage for branches (0%) does not meet global threshold (100%)
Jest: Coverage for lines (20%) does not meet global threshold (100%)
Jest: Coverage for functions (20%) does not meet global threshold (100%)
What is the expected behavior?
Jest should detect that I've moved the file. Running Jest with --no-cache
"fixes" this (coverage is as expected). Rerunning without --no-cache
causes the issue again (cache isn't cleared?). Editing the moved file however fixes the problem.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Jest config:
module.exports = {
collectCoverage: true,
collectCoverageFrom: [
'src/**/*.js'
],
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100
}
},
snapshotSerializers: [
'enzyme-to-json/serializer'
]
};
Version details:
$ ./node_modules/.bin/jest --version
v20.0.4
$ node --version
v5.11.0
$ npm --version
3.8.6
$ uname -a
Linux dev36-devc 4.2.0-42-generic #49~14.04.1-Ubuntu SMP Wed Jun 29 20:22:11 UTC 2016 x86_64 GNU/Linux