-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Empty coverage #433
Comments
I found that if you don't add in the
|
@browniefed Didn't help :( |
I'm also getting empty coverage results, but I'm not sure if it is a "jest": {
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
"testPathDirs": [
"<rootDir>/src"
],
"testDirectoryName": "spec",
"testFileExtensions": [
"js",
"jsx"
],
"moduleFileExtensions": [
"js",
"json"
],
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react"
]
} This is the Jest output: > iojs ./node_modules/jest-cli/bin/jest.js --coverage
Using Jest CLI v0.4.17
PASS src/tests/spec/DurationFormatter-test.js (1.751s)
1 test passed (1 total)
Run time: 2.435s
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
----------|----------|----------|----------|----------|----------------|
All files | 100 | 100 | 100 | 100 | |
----------|----------|----------|----------|----------|----------------|
All reports generated And <?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1438265018003" clover="3.2.0">
<project timestamp="1438265018003" name="All Files" >
<metrics statements="0" coveredstatements="0" conditionals="0" coveredconditionals="0" methods="0" coveredmethods="0" elements="0" coveredelements="0" complexity="0" packages="0" files="0" classes="0" loc="0" ncloc="0" />
</project>
</coverage> |
I get exactly the same output as @rbardini. I don't use babel-jest, I transpile the files before running jest from the 0.5 branch on them.
"jest": {
"scriptPreprocessor": "<rootDir>/preprocessor.js",
"testDirectoryName": "build",
"testPathDirs": [
"build"
],
"testFileExtensions": [
"spec.js"
],
"moduleFileExtensions": [
"js",
"jsx"
],
"unmockedModulePathPatterns": [
"/node_modules/"
]
} And the output: Using Jest CLI v0.4.17
PASS build/components/Paper/tests.spec.js (0.47s)
PASS build/components/Button/tests.spec.js (0.572s)
Warning: Returning `false` from an event handler is deprecated and will be ignored in a future release. Instead, manually call e.stopPropagation() or e.preventDefault(), as appropriate.
2 tests passed (2 total)
Run time: 1.603s
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
----------|----------|----------|----------|----------|----------------|
All files | 100 | 100 | 100 | 100 | |
----------|----------|----------|----------|----------|----------------|
All reports generated |
I fixed this by including every file in collectCoverageOnlyFrom: "jest": {
"scriptPreprocessor": "<rootDir>/preprocessor.js",
"testDirectoryName": "build",
"testPathDirs": [
"build"
],
"testFileExtensions": [
"spec.js"
],
"unmockedModulePathPatterns": [
"/node_modules/"
],
"collectCoverageOnlyFrom": {
"build/components/Paper/index.js": true,
"build/components/Button/index.js": true
}
} cc @rbardini |
Thanks @aluxian, your solution also worked for me, although I find it a little impractical to list all the desired files in Besides that, I've noticed that my test fails if I list the file in > iojs ./node_modules/jest-cli/bin/jest.js
Using Jest CLI v0.4.17
FAIL src/tests/spec/DurationFormatter-test.js
TypeError: src/tests/spec/DurationFormatter-test.js: undefined is not a function
at Loader._execModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:222:9)
at Loader.requireModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:905:12)
at Loader.requireModuleOrMock (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:926:17)
at Object.<anonymous> (src/tests/spec/DurationFormatter-test.js:2:258)
at Object.runContentWithLocalBindings (node_modules/jest-cli/src/lib/utils.js:495:17)
at Loader._execModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:236:9)
at Loader.requireModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:905:12)
at jasmineTestRunner (node_modules/jest-cli/src/jasmineTestRunner/jasmineTestRunner.js:283:16)
at node_modules/jest-cli/src/TestRunner.js:376:12
at tryCatcher (node_modules/jest-cli/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (node_modules/jest-cli/node_modules/bluebird/js/main/promise.js:503:31)
at Promise._settlePromiseAt (node_modules/jest-cli/node_modules/bluebird/js/main/promise.js:577:18)
at Promise._settlePromises (node_modules/jest-cli/node_modules/bluebird/js/main/promise.js:693:14)
at Async._drainQueue (node_modules/jest-cli/node_modules/bluebird/js/main/async.js:123:16)
at Async._drainQueues (node_modules/jest-cli/node_modules/bluebird/js/main/async.js:133:10)
at Immediate.Async.drainQueues [as _onImmediate] (node_modules/jest-cli/node_modules/bluebird/js/main/async.js:15:14)
at processImmediate [as _immediateCallback] (timers.js:371:17)
1 test failed, 0 tests passed (1 total)
Run time: 2.253s
npm ERR! Test failed. See above for more details. Otherwise it works as expected: > iojs ./node_modules/jest-cli/bin/jest.js --coverage
Using Jest CLI v0.4.17
PASS src/tests/spec/DurationFormatter-test.js (1.473s)
1 test passed (1 total)
Run time: 2.004s
-----------------------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
-----------------------|----------|----------|----------|----------|----------------|
components/ | 100 | 100 | 100 | 100 | |
DurationFormatter.js | 100 | 100 | 100 | 100 | |
-----------------------|----------|----------|----------|----------|----------------|
All files | 100 | 100 | 100 | 100 | |
-----------------------|----------|----------|----------|----------|----------------|
All reports generated |
Same for me ^ I enabled coverage by default now. And yeah, I know it's impractical, but hey – at least it works. Now that we know what's wrong is much easier to find a viable solution. |
Did someone found solution? I have lot of tests, so it's impractical to add them using |
+1 |
I found out that using |
@roman01la I think you need to put your test under My problem is I get the report only from the files I tested, or list them in collectCoverageOnlyFrom. If my test does not touch a file in the test folder, I wish the report show 0% for that file, but it is not reported at all. Should I raise separate issue? |
same like @akheron, as soon as i add Using |
Same issue here. I only get coverage if I add manually files in |
as workaround you can create fake |
@hourliert That was my finding as well. Annoying, but it works... |
@hourliert, @yaycmyk +1 |
Am also having this issue. Coverage only working when files added to |
jest-cli@0.8.2 By changing to syntax: |
Another reason is using a custom structure to organise tests and mocks.
While this won't work (even using dontMock instead of require.requireActual):
└── components
|
This should be fixed in 0.9.0, currently as alpha release tagged with |
@cpojer This is still a bug in 0.9.2. Steps to reproduce within a set of code with zero tests.
The second run will result with zero files untested. While it still should since there are plenty of files within src that doesn't have any tests. |
@blainekasten can you provide a repo that highlights this issue so we can add it as an integration test and fix it? |
In my case I get an empty coverage when I try to put test files in the same directory as source files. I found it useful to stick a breakpoint in this line https://github.com/facebook/jest/blob/master/src/Runtime/Runtime.js#L296 and found out that the whole test directory is excluded from coverage. My fix is to check if the file does not have test extension (I use 'spec.test') rather than being in the test directory. |
Oh you are right, it's because we don't collect coverage information from tests. I'm not entirely sure what the best behavior here should be – I believe when we fix the test path pattern to be based on the full path rather than just the directory name, this bug will resolve itself :) Soon! |
…es. Could potentially fix jestjs#433
Check if the file does have test extension rather than being in the test directory. Could potentially fix jestjs#433
Check if the file does have test extension rather than being in the test directory. Could potentially fix jestjs#433
Check if the file does have test extension rather than being in the test directory. Could potentially fix jestjs#433 The side effect of it is that you cannot specify just "js" as your test file extension as this would include all tests in the coverage
Check if the file does have test extension rather than being in the test directory. Could potentially fix jestjs#433 The side effect of it is that you cannot specify just "js" as your test file extension as this would include all tests in the coverage
There are so many different issues listed in this ticket that I'm having a hard time following what is actually still a problem. @cpojer I did make a repo with the one issue I currently still see here The issue i'm still seeing:
That said, I would gladly enjoy anyone else putting up PR's in that repo for other configurations that are having issues so we can try to keep these centrally located. |
I think this should be fine now. If there are issues that are still unresolved with Jest 12.1, please open individual new issues. |
@cpojer, i can confirm this is still an issue.
jest 17.x. thx! |
I am using jest version 24, and this is still an issue!!! What is the proper jest config to have it report untouched source files?? Insane that this hasn't been fixed yet... 😢 |
Not sure if it's still relevant for someone, but I fixed it by adding this to my package.json file:
|
This is still an issue in 26.6.3. When I pass specific files to jest, I have to pass those same files to I'm using the specific files in pre-commit hooks to only test the files that have changed. So what I have to do is this:
If there are multiple files that are changed in staging, then it needs to look like this to work:
Others have found success by hard-coding values into The ideal usage would be:
Ideally the above command would collect coverage only for that file that changed, unless otherwise specified in |
@MattAydin The problem with this is that this collects coverage on all the source code every time. If you want to run jest only on files that changed (and collect coverage for only the files that changed), there needs to be a dynamic solution for collecting coverage. |
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. |
I'm struggling to get code coverage with Jest.
Here's a sample component I'm running tests on:
And here's a test file:
And also Jest settings from
package.json
:All paths a valid. I've been debugging Jest and found out that
moduleLoader.getDependenciesFromPath(testFilePath)
returns empty array. So for some reason it can not get dependencies of the test file.The text was updated successfully, but these errors were encountered: