在我的react项目中,我有一个./styles
根文件夹,其中包含样式组件的各种样式对象。我不希望这些文件显示在覆盖率测试中。
我试图这样隐藏它们,但是当我运行npm run coverage
时,它们仍然会显示。
"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/"
]
}
{
"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"]
]
}
}
}
答案 0 :(得分:2)
我只需要在package.json中
"coveragePathIgnorePatterns": [
"<rootDir>/styles/"
],
并将其从"testPathIgnorePatterns":
中删除<-在这里和在coveragePathIgnorePatterns
中都使用它会导致我的测试永久运行并且样式仍然显示。
我还从.babelrc
中删除了此内容:
["istanbul",{"exclude": ["styles/*.js"]}]
答案 1 :(得分:1)
modulePathIgnorePatterns:[“ directoryNameToIgnore”]
或:
modulePathIgnorePatterns:[“ / dist /”]
coveragePathIgnorePatterns:[“ / styles /”]