笑话报道报告未知

时间:2018-10-14 05:07:50

标签: webpack jestjs babel-jest

我想将Jest集成到我的webpack流中,我已经按照以下依赖项进行了安装

    "@babel/core": "^7.1.2",
    "@babel/preset-env": "^7.1.0",
    "babel-7-jest": "^21.3.3",
    "babel-core": "^7.0.0-bridge.0",
    "babel-jest": "^23.6.0",
    "babel-loader": "^8.0.4",
    "clean-webpack-plugin": "^0.1.19",
    "css-loader": "^1.0.0",
    "express": "^4.16.3",
    "extract-text-webpack-plugin": "^4.0.0-beta.0",
    "file-loader": "^2.0.0",
    "html-loader": "^0.5.5",
    "html-webpack-plugin": "^3.2.0",
    "jest": "^23.6.0",
    "jest-cli": "^23.6.0",
    "node-sass": "^4.9.3",
    "sass-loader": "^7.1.0",
    "style-loader": "^0.23.0",
    "webpack": "^4.20.2",
    "webpack-cli": "^3.1.2",
    "webpack-dev-middleware": "^3.4.0",
    "webpack-dev-server": "^3.1.9"

下面是我的笑话配置

rootDir: path.resolve(__dirname, 'test'),
verbose: true,
collectCoverage: true,
collectCoverageFrom: ['src/**/*.{js}'],
coverageReporters: ['json', 'html']

当我使用以下脚本运行npm test时,我得到以下输出,其中测试可以正常运行,但是每次覆盖率都不高

"coverage": "jest --coverage --config=jest.config.js",

=============================== Coverage summary ===============================
Statements   : Unknown% ( 0/0 )
Branches     : Unknown% ( 0/0 )
Functions    : Unknown% ( 0/0 )
Lines        : Unknown% ( 0/0 )
================================================================================
Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.491s
Ran all test suites.

所有测试都是纯JavaScript。

1 个答案:

答案 0 :(得分:0)

假设这是您的目录布局:

- ./project_root
 |_./jest.config.js
 |_./src/
 |_./test/

rootDir设置为project_root或将其保留为默认值。 (可选)如果node_modules以外的任何文件夹都应从覆盖率报告中排除,请将其添加到coveragePathIgnorePatterns

来自Jest文档on rootDir

  

Jest应该在其中扫描测试和模块的根目录。如果将Jest配置放入package.json中,并希望将根目录作为仓库的根目录,则此配置参数的值将默认为package.json的目录。