Jest: collectCoverageFrom and coverageThreshold ignored inside projects

Created on 7 Aug 2019  路  2Comments  路  Source: facebook/jest

馃悰 Bug Report

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.

To Reproduce

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
        }
    }
}

Expected behavior

Project level config can define / override collectCoverageFrom, coverageThreshold and other options.

Bug Report Needs Repro Needs Triage

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.

"/some/specific/glob/pattern": {
            branches: 80, 
            functions: 80,
            lines: 80,
            statements: -10
}

All 2 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kentor picture kentor  路  3Comments

Secretmapper picture Secretmapper  路  3Comments

samzhang111 picture samzhang111  路  3Comments

paularmstrong picture paularmstrong  路  3Comments

ianp picture ianp  路  3Comments