简体   繁体   English

带有Mocha测试用例的Istanbul覆盖率仅显示规格文件(测试文件)的覆盖率报告

[英]Istanbul coverage with mocha test cases only showing coverage report for spec files (test files)

Istanbul coverage report only shows coverage report for the spec files ie the test files and not the original router and controllers files. 伊斯坦布尔覆盖报告仅显示规格文件(即测试文件)的覆盖报告,而不显示原始路由器和控制器文件。

It displays 100% coverage for spec files and 0% for the router files. 它显示规格文件的100%覆盖率和路由器文件的0%。

The command i am using is npm test: 我正在使用的命令是npm test:

"test": "NODE_ENV=development istanbul cover --include-all-sources --root ./server ./node_modules/.bin/_mocha -- --compilers js:babel-core/register --recursive './server/**/**/**/*-spec.js'"

Below is the screenshot of the coverage report html file by istanbul 以下是伊斯坦布尔的覆盖率报告html文件的屏幕截图 在此处输入图片说明

I manage to make it work for me, maybe you can pick some of my configs and apply them to your environment 我设法使其对我有用,也许您可​​以选择一些配置并将其应用于您的环境

  1. My current packages version 我当前的软件包版本

     "@babel/core": "^7.0.0", "@babel/register": "^7.0.0", "babel-plugin-istanbul": "^5.0.1", "chai": "^4.1.2", "mocha": "^5.2.0", "nyc": "^13.0.1" 
  2. Update/Create your .babelrc adding the pluging for istanbul 更新/创建.babelrc增加对伊斯坦布尔pluging

    { "plugins": ["istanbul"] } {“ plugins”:[“ istanbul”]}

  3. Create a config file for istanbul: .nycrc and paste this configuration 为伊斯坦布尔创建一个配置文件: .nycrc并粘贴此配置

    { "require": ["@babel/register"], "exclude": ["**/*.{test,spec}.js"], "all": true, "instrument": false } {“ require”:[“ @ babel / register”],“ exclude”:[“ ** / *。{test,spec} .js”],“ all”:true,“ instrument”:false}

You can check for more options in the official nyc repository 您可以在官方nyc存储库中检查更多选项

  1. Then run the tests 然后运行测试

./node_modules/.bin/nyc mocha **/*.{test,spec}.js

or 要么

npx nyc mocha **/*.{test,spec}.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM