我正在使用 mocha
测试我的 js 文件。有些测试用例需要时间来解决响应,所以我使用了超时。完整的命令看起来像
istanbul cover _mocha test/sol-verifier.js -- --timeout 300000
问题是,在进行这样的覆盖范围时,我没有创建覆盖范围报告,它只成功运行测试用例并停止(而不是终止)。我该如何解决这个问题?
我的代码位于node.js 中,它不会创建任何服务器。
此外,当我删除 --timeout
标志并注释掉需要更多时间的测试用例时。它工作正常并生成覆盖率报告。
根据我的发现,问题不在于 --timeout
标志,当测试用例需要比平常更长的时间来解决时,不会生成报告。
最佳答案
您可以向测试套件函数添加 done
参数,并在每个测试函数末尾调用 done()
:
it('test expectation', function(done) {
// test asynchronous code
// call done() to terminate test and proceed to the next test
done();
}
或者,尝试在 mocha
上使用 --exit
标志运行测试:
istanbul cover _mocha --exit test/sol-verifier.js -- --timeout 300000
根据docs :
To avoid false positives and encourage better testing practices, Mocha will no longer automatically kill itself via process.exit() when it thinks it should be done running.
If the mocha process is still alive after your tests seem "done", then your tests have scheduled something to happen (asynchronously) and haven't cleaned up after themselves properly. Did you leave a socket open?
Supply the --exit flag to use pre-v4 behavior.
关于node.js - 当测试用例花费更多时间时, Istanbul 尔与摩卡不会生成覆盖率报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53849817/