samedi 31 août 2019

Jest, how to ignore test coverage of specific folders?

In my react project I have a root ./styles folder which contains various style objects for styled-components. I do not want these files to show up in the coverage test.

I've tried to hide them like so, but when I run npm run coverage they still show up.

enter image description here

package.json

"jest": {
  "setupFilesAfterEnv": [
    "<rootDir>/jest.setup.js"
  ],
  "coveragePathIgnorePatterns": [
    "<rootDir>/styles/",
    "./styles/"
  ],
  "testPathIgnorePatterns": [
    "<rootDir>/.next/",
    "<rootDir>/node_modules/",
    "<rootDir>/styles/",
    "./styles/"
  ],
  "transform": {
    "^.+\\.(js)$": "babel-jest",
    "^.+\\.js?$": "babel-jest",
    "^.+\\.ts?$": "babel-jest",
    "^.+\\.tsx?$": "babel-jest",
    "^.+\\.json5$": "json5-jest"
  },
  "moduleFileExtensions": [
    "js",
    "json",
    "json5",
    "ts",
    "tsx"
  ],
  "modulePaths": [
    "<rootDir>/components/",
    "<rootDir>/pages/",
    "<rootDir>/shared/"
  ]
}

babelrc

{
  "env": {
    "development": {
      "presets": [
        "next/babel",
        "@zeit/next-typescript/babel"
      ],
      "plugins": [
        ["styled-components", {"ssr": true, "displayName": true}],
        ["@babel/plugin-proposal-decorators", {"legacy": true}],
        ["istanbul",{"exclude": ["styles/*.js"]}]
      ]
    },
    "production": {
      "presets": [
        "next/babel",
        "@zeit/next-typescript/babel"
      ],
      "plugins": [
        ["styled-components", {"ssr": true, "displayName": true}],
        ["@babel/plugin-proposal-decorators", {"legacy": true}]
      ]
    },
    "test": {
      "presets": [
        "@babel/preset-typescript",
        ["next/babel", {"preset-env": { "modules": "commonjs" }}]
      ],
      "plugins": [
        ["styled-components", { "ssr": true, "displayName": true }],
        ["@babel/plugin-proposal-decorators", { "legacy": true }],
        ["babel-plugin-sass-vars"]
      ]
    }
  }
}

Aucun commentaire:

Enregistrer un commentaire