我有一个正在用Jest进行单元测试的Vue应用程序。在Linux上,假设我删除了/coverage
文件夹,以覆盖率运行Jest会产生接近零的覆盖率值:
=============================== Coverage summary ===============================
Statements : 100% ( 15/15 )
Branches : 100% ( 0/0 )
Functions : 100% ( 0/0 )
Lines : 100% ( 15/15 )
================================================================================
当我第二次运行Jest时,我得到了真实的结果:
=============================== Coverage summary ===============================
Statements : 3.6% ( 890/24731 )
Branches : 0.96% ( 169/17656 )
Functions : 1.59% ( 125/7858 )
Lines : 5.6% ( 875/15638 )
================================================================================
为什么会这样,我该如何解决?
我的Jest配置来自package.json:
"jest": {
"rootDir": "../",
"moduleFileExtensions": [
"js",
"vue"
],
"transform": {
"^.+\\.vue$": "<rootDir>/tests/node_modules/jest-vue-preprocessor",
"^.+\\.js$": "<rootDir>/tests/node_modules/babel-jest"
},
"moduleNameMapper": {
"^~/(.*)$": "<rootDir>/$1"
},
"collectCoverage": true,
"collectCoverageFrom": [
"**/*.{js,vue}",
"!**/node_modules/**",
"!**router.js"
],
"coverageReporters": [
"html",
"text-summary"
],
"coverageDirectory": "coverage",
"notify": true,
"setupTestFrameworkScriptFile": "<rootDir>/tests/setup.js"
}