Far*_*raz 6 mocha.js node.js istanbul
即使测试用例通过,我也无法弄清楚为什么测试覆盖率是0。我在package.json中有一个脚本:
"nyctest": "node --max_old_space_size=4096 node_modules/nyc/bin/nyc.js --reporter=text mocha"
Run Code Online (Sandbox Code Playgroud)
当我跑步 npm run nyctest
我的测试通过了,但是覆盖率为0%。
以下是测试,文件正在测试:
test.js
var chai = require('chai');
var sinon = require('sinon');
var sinonChai = require('sinon-chai');
chai.should();
chai.use(sinonChai);
var application = require('../../../src/main/resources/static/js/components/app.js');
describe('sample return testing', function(){
it('should return true', function(){
application.sample.returnValue().should.equal(true);
})
});
Run Code Online (Sandbox Code Playgroud)
app.js
const sample = {
returnValue: function () {
return true;
}
};
module.exports = {sample};
Run Code Online (Sandbox Code Playgroud)
感谢任何帮助。
mck*_*oss 13
当我在 TypeScript 中使用 "type": "module" (ES Modules) 时遇到了这个问题。
ESM 模块的纽约(伊斯坦布尔)加载程序存在问题。推荐的解决方案是放弃 nyc 并使用 Node 13 及以上版本中内置的本机覆盖范围:c8。
到 2020 年 8 月:两件事:
--all参数。.nycrc文件,以便在您的命令行中没有长命令行,package.json如下所示:最小.nycrc文件:
{
"all": true,
"include": [
"test/**.js"
],
"exclude": []
}
Run Code Online (Sandbox Code Playgroud)
小智 4
您需要nyctest使用 flag 修改您的命令--all,如下所示:
"nyctest": "nyc --reporter=lcov --reporter=text-lcov --all -x \"./node_modules/*\" -x \"./coverage/*\" check-coverage --lines 10 --functions 90 npm run unittest"
Run Code Online (Sandbox Code Playgroud)
所以有了--all标志,所有文件都会被获取
| 归档时间: |
|
| 查看次数: |
3863 次 |
| 最近记录: |