vue测试覆盖范围Jest只检查进口
我正在用jest
和vue-test-utils
测试我的vue.js 2项目,测试效果很好,但是当我尝试测量该测试时,我有问题的覆盖范围.vue
文件。
问题是,当我执行jest -Coverage
时,我会在这些文件中获得100%的覆盖范围,但是如果我输入以检查哪个行覆盖范围,则只检查了进口量以获取了Jest Covery和代码号的其余部分(您可以在第二张图片中看到。)
I'm testing my vue.js 2 project with jest
and vue-test-utils
, the test works fine, but I've a problem when I try to measure the coverage of .vue
files.
The problem is that when I execute jest --coverage
I obtain 100% of coverage in those files, but if i enter to inspect which lines are coverage I see only the imports have been checked for Jest coverage and the rest of the code No (You can see that in the second picture.)
???? If you need more info please leave me a commend. Thanks
This is my package.json
(only relevant info):
"scripts": {
"test": "jest --coverage",
},
"dependencies": {
"core-js": "3.20.3",
"single-spa-vue": "2.5.0",
"systemjs-webpack-interop": "2.3.7",
"vue": "2.6.14",
"vue-i18n": "8",
"vue-router": "3.5.2"
},
"devDependencies": {
"@vue/cli-plugin-unit-jest": "~4.5.19",
"@vue/cli-service": "~4.5.19",
"@vue/test-utils": "^1.3.0",
"babel-jest": "^26.6.3",
"jest": "^26.6.3",
"jest-junit": "^13.0.0",
"jest-transform-stub": "^2.0.0"
}
And my `jest.config.js`:
```
const alias = require("./aliases.config");
module.exports = {
moduleFileExtensions: ["js", "vue", "json"],
transform: {
"^.+\\.jsquot;: "babel-jest",
"^.+\\.vuequot;: "vue-jest",
".+\\.(css|styl|less|sass|scss|jpg|jpeg|png|svg|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|avif)quot;:
"jest-transform-stub",
},
preset: "@vue/cli-plugin-unit-jest",
testPathIgnorePatterns: ["/node_modules/"],
modulePathIgnorePatterns: ["/node_modules/"],
testMatch: ["**/tests/unit/**/*.(unit|test|spec).js"],
collectCoverage: false,
collectCoverageFrom: [
"<rootDir>/src/**/*.{vue,js}",
"!<rootDir>/src/main.js",
"!<rootDir>/src/set-public-path.js",
"!<rootDir>/src/router/index.js",
],
coverageDirectory: "reports/unit-reports/coverage",
coverageReporters: ["text-summary", "html", "cobertura"],
moduleNameMapper: {
...alias.forJest,
"@divilo/styleguide-base-front":
"<rootDir>/tests/mocks/styleguide-base-front.js",
"@divilo/api-mfes-front": "<rootDir>/tests/mocks/api-mfes-front.js",
},
coverageProvider: "babel",
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: -10,
},
},
reporters: [
"default",
[
"jest-junit",
{
outputDirectory: "reports/unit-reports/tests",
outputName: "junit.xml",
},
],
],
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论