When I try to include all the project source code to get a more reasonable code coverage figure, I end up with
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files | Unknown | Unknown | Unknown | Unknown | |
----------|----------|----------|----------|----------|----------------|
My config contains the following:
"collectCoverageFrom": [
"<rootDir>/app_modules/",
"<rootDir>/src/"
],
I've also tried it without the trailing /
, with **/*.js
and with just a trailing *.js
all to no avail.
Based on the --debug
option, the path expands to the paths I want to collect coverage information from ( isn't the problem)
So what is the magic to getting more accurate coverage information?
The best docs I've been able to find come from this Github PR:
I ended up doing:
"collectCoverageFrom": [
"**/*.js",
"!webpack.config.js"
],
which only worked because this is part of the default config
"testPathIgnorePatterns": [
"/node_modules/"
],
It does add a huge amount of time to the test run though.
When I try to include all the project source code to get a more reasonable code coverage figure, I end up with
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files | Unknown | Unknown | Unknown | Unknown | |
----------|----------|----------|----------|----------|----------------|
My config contains the following:
"collectCoverageFrom": [
"<rootDir>/app_modules/",
"<rootDir>/src/"
],
I've also tried it without the trailing /
, with **/*.js
and with just a trailing *.js
all to no avail.
Based on the --debug
option, the path expands to the paths I want to collect coverage information from ( isn't the problem)
So what is the magic to getting more accurate coverage information?
The best docs I've been able to find come from this Github PR: https://github.com/facebook/jest/pull/1349/files
I ended up doing:
"collectCoverageFrom": [
"**/*.js",
"!webpack.config.js"
],
which only worked because this is part of the default config
"testPathIgnorePatterns": [
"/node_modules/"
],
It does add a huge amount of time to the test run though.
Share Improve this question edited Dec 8, 2016 at 22:38 Rick Hanlon II 21.7k7 gold badges48 silver badges53 bronze badges asked Sep 18, 2016 at 19:13 boatcoderboatcoder 18.1k21 gold badges124 silver badges186 bronze badges3 Answers
Reset to default 17Look at your link very carefully:
collectCoverageFrom: {
description: wrap(
'relative to <rootDir> glob pattern matching the files that coverage ' +
'info needs to be collected from.'
...
You can't use <rootDir>
. Try:
collectCoverageFrom: [
"**/app_modules/**",
"**/src/**"
],
This is just an other information to add to your edited question: instead of declaring a second array:
"testPathIgnorePatterns": [
"/node_modules/"
],
You can just keep using your collectCoverageFrom
array by prepending !
to the directory you do not want to collect coverage information about:
collectCoverageFrom: [
"!**/node_modules/**"
],
you can just force de coverage with the option forceCoverageMatch : ['/.ts','/.js']