我正在尝试学习如何使用Jest,以及比个人项目更好的方法。
我已经安装了jest并进行了配置(正确地说,就我所知)。但我的报道报道都搞砸了。有人可以协助吗?测试正在进行,至少大部分都在进行。但问题在于覆盖率报告。以下是相关配置。
Facebook的文档在配置方面有很多不足之处。
Package.json“jest”键
"jest": {
"roots": [
"<rootDir>/src"
],
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"moduleDirectories": [
"node_modules"
],
"transform": {
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest",
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
"\\.(styl)$": "<rootDir>/node_modules/jest-css-modules"
},
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1"
},
"snapshotSerializers": [
"<rootDir>/node_modules/jest-serializer-vue",
"jest-serializer-html"
],
"mapCoverage": true,
"collectCoverage": true,
"collectCoverageFrom": [
"src/**/*.js",
"src/**/*.vue",
"!**/vendor/**",
"!**/__mocks__/**",
"!**/__tests__/**",
"!test/e2e/**"
],
"coveragePathIgnorePatterns": [
"**/node_modules/",
"**/__tests__/*"
],
"testPathIgnorePatterns": [
"**/node_modules/"
],
"verbose": true
}
项目布局
[ ] build
[ ] config
[ ] coverage
[ ] build
[ ] src
[ ] assets
[ ] components
[ ] Module 1
[ ] __tests__
[ ] __snapshots__
file module1.test.js
file module1.vue
[ ] config
[ ] router
[ ] store
[ ] stylus
file main.js
file App.vue
让我的报道报告看起来像:(我希望只显示相对于我的根的路径,以及实际的文件名,而不是“未知”)
Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 failed, 16 passed, 17 total
Snapshots: 2 passed, 2 total
Time: 0.719s, estimated 1s
Ran all test suites.
---------------------------------------------------------------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
---------------------------------------------------------------|----------|----------|----------|----------|----------------|
All files | 71.62 | 63.04 | 83.33 | 67.69 | |
root | 71.05 | 80 | 100 | 62.07 | |
unknown | 71.05 | 80 | 100 | 62.07 |... 151,152,154 |
root/Users/absolute/path/to/project/src/components/Module1 | 72.22 | 50 | 83.33 | 72.22 | |
Module1.vue | 72.22 | 50 | 83.33 | 72.22 |... 151,152,154 |
---------------------------------------------------------------|----------|----------|----------|----------|----------------|