jeudi 16 janvier 2020

How do I configure the global threshold to match the "All Files" value using Jest?

When I run my test with the --coverage flag set I get a message that my global coverage threshold isn't met. But when I look at the "All Files" section in the report it seems to match my set thresholds.

At first I thought it was the low coverage I have on the React components, but when I excluded all the components the global percentage only went up with 1 or 2 percent.

So my question is, how do I align the global threshold to the "All Files" results?

This is the report I get when I run my tests

    ----------------------------|----------|----------|----------|----------|-------------------|
    File                        |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
    ----------------------------|----------|----------|----------|----------|-------------------|
    All files                   |    86.39 |    80.53 |    90.12 |    87.16 |                   |
    src                         |      100 |      100 |      100 |      100 |                   |
    settings.js                 |      100 |      100 |      100 |      100 |                   |
    src/actions                 |      100 |    72.22 |      100 |      100 |                   |
    deploysActions.js           |      100 |       50 |      100 |      100 |                30 |
    environmentsActions.js      |      100 |       75 |      100 |      100 |                31 |
    errorsActions.js            |      100 |      100 |      100 |      100 |                   |
    systemsActions.js           |      100 |       50 |      100 |      100 |                24 |
    tagsActions.js              |      100 |       75 |      100 |      100 |                31 |
    testResultsActions.js       |      100 |       50 |      100 |      100 |                35 |
    timeRangeActions.js         |      100 |      100 |      100 |      100 |                   |
    src/constants               |      100 |      100 |      100 |      100 |                   |
    actions.js                  |      100 |      100 |      100 |      100 |                   |
    responseColumns.js          |      100 |      100 |      100 |      100 |                   |
    src/middleware              |        0 |        0 |        0 |        0 |                   |
    localStorageMiddleware.js   |        0 |        0 |        0 |        0 |      4,5,6,7,8,11 |
    loggerMiddleware.js         |        0 |      100 |        0 |        0 |     1,2,3,4,5,6,7 |
    src/reducers                |    88.55 |    80.17 |    97.37 |    88.05 |                   |
    authReducer.js              |        0 |        0 |        0 |        0 |... 44,49,55,56,60 |
    deploysReducer.js           |      100 |    86.67 |      100 |      100 |                77 |
    environmentsReducer.js      |      100 |      100 |      100 |      100 |                   |
    errorsReducer.js            |      100 |      100 |      100 |      100 |                   |
    rootReducer.js              |        0 |      100 |      100 |        0 |                11 |
    systemsReducer.js           |      100 |      100 |      100 |      100 |                   |
    tagsReducer.js              |      100 |      100 |      100 |      100 |                   |
    testResultsReducer.js       |      100 |    97.37 |      100 |      100 |               122 |
    timeRangeReducer.js         |      100 |      100 |      100 |      100 |                   |
    src/store                   |        0 |        0 |        0 |        0 |                   |
    configureStore.js           |        0 |        0 |        0 |        0 |... 11,13,15,16,18 |
    src/utils                   |    94.55 |       94 |      100 |    94.55 |                   |
    api.js                      |      100 |      100 |      100 |      100 |                   |
    dateTimeFormatting.js       |      100 |      100 |      100 |      100 |                   |
    environments.js             |      100 |      100 |      100 |      100 |                   |
    errors.js                   |      100 |      100 |      100 |      100 |                   |
    localStorage.js             |       75 |       25 |      100 |       75 |          18,19,21 |
    ----------------------------|----------|----------|----------|----------|-------------------|
    Jest: "global" coverage threshold for statements (50%) not met: 4%
    Jest: "global" coverage threshold for branches (50%) not met: 0%
    Jest: "global" coverage threshold for lines (50%) not met: 4.76%
    Jest: "global" coverage threshold for functions (40%) not met: 0%

And this is my jest configuration (Note, the components directory is excluded)

"jest": {
    "collectCoverageFrom": [
        "src/**/*.js",
        "!**/node_modules/**",
        "!**/coverage/**",
        "!src/components/**",
        "!src/index.js",
        "!src/serviceWorker.js"
    ],
    "coverageReporters": ["html", "cobertura", "json", "lcov", "text", "clover"],
    "coverageThreshold": {
        "global": {
            "branches": 50,
            "functions": 40,
            "lines": 50,
            "statements": 50
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire