Not sure if it's a bug or by design, but I cannot provide the collectCoverageFrom, coverageThreshold in a project level config i.e. they are ignored.
If I have the following in root jest.config.js and run jest --coverage the collectCoverageFrom, coverageThreshold are ignored and no files are detected.
module.exports = {
projects: [
{
displayName: "project1",
testMatch: [
"<rootDir>/project1/src/**/?(*.)+(spec|test).[jt]s?(x)"
],
collectCoverageFrom: [
"<rootDir>/project1/src/**/*.{js,jsx,ts,tsx}"
],
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: -10
}
}
}
]
}
However if I move the collectCoverageFrom, coverageThreshold to the top, then it works:
module.exports = {
projects: [{
displayName: "project1",
testMatch: [
"<rootDir>/project1/src/**/?(*.)+(spec|test).[jt]s?(x)"
],
}],
collectCoverageFrom: [
"<rootDir>/project1/src/**/*.{js,jsx,ts,tsx}"
],
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: -10
}
}
}
Project level config can define / override collectCoverageFrom, coverageThreshold and other options.
Hi @akum32. Seems like the problem you have is not a bug. The config settings coverageThreshold and collectCoverageFrom have to be specified on a global level. In order to more specifically config the files for which jest needs to collect coverage from, you need to use some glob patterns defined inside coverageThreshold and collectCoverageFrom arrays on a global level.
"/some/specific/glob/pattern": {
branches: 80,
functions: 80,
lines: 80,
statements: -10
}
Thanks @armansujoyan
Most helpful comment
Hi @akum32. Seems like the problem you have is not a bug. The config settings coverageThreshold and collectCoverageFrom have to be specified on a global level. In order to more specifically config the files for which jest needs to collect coverage from, you need to use some glob patterns defined inside coverageThreshold and collectCoverageFrom arrays on a global level.