首页 > 解决方案 > 摩卡-柴覆盖范围未知

问题描述

大家好,我正在尝试获取 mocha chai 单元测试覆盖率报告。

我得到了测试结果通过。

还将覆盖范围生成为 html,但显示未知。请看下图。

在此处输入图像描述

Package.json在脚本中添加了以下配置。

 "scripts": {
    "test": "mocha",
    "test-with-coverage": "nyc --reporter=html mocha"
  },

并使用以下命令运行测试。

npm run test-with-coverage

编辑: 将报告更改为文本时,在终端中获取以下报告。

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |                   
----------|---------|----------|---------|---------|-------------------

标签: node.jsunit-testingmocha.jscode-coveragechai

解决方案


请尝试使用以下命令,

nyc -x \"**/tests/**\" --reporter=cobertura --reporter=html mocha 'your test folder path'

推荐阅读