gpt4 book ai didi

mocha.js - 以编程方式使用时,Mocha 在第一次测试失败后存在

转载 作者:行者123 更新时间:2023-12-04 23:24:54 31 4
gpt4 key购买 nike

我正在尝试以编程方式运行 mocha。
runner的代码如下:

var Mocha = require("mocha");
var mocha = new Mocha();
mocha.reporter('list').ui('bdd').ignoreLeaks();
//Here the serv_paths variable is defined, -- this code snippet is skipped
// ...
serv_paths.forEach(function(file){
mocha.addFile(file);
});
var runner = mocha.run(function(){ });

测试非常简单:
 var assert = require("assert");
describe('True!', function(){
it('true = true', function(){
assert.equal(true, true);
});
it('true = false', function(){
assert.equal(true, false);
});
it('true = false -- second', function(){
assert.equal(true, false);
});
it('true = true', function(){
assert.equal(true, true);
});
});

mocha 在第一次失败之前运行测试,然后退出并忽略其他测试。

输出是:
  [Jan 21 04:57:23]   ✓ True! true = true: 0ms
[Jan 21 04:57:23] 1) True! true = false
[Jan 21 04:57:23] ✖ 1 of 4 tests failed:
[Jan 21 04:57:23] 1) True! true = false:
AssertionError: true == false
at Context.<anonymous> (/home/ubuntu/project/plugins-server/cloud9.ide.help/test_test.js:14:10)
at Test.run (/home/ubuntu/project/node_modules/mocha/lib/runnable.js:213:32)
at Runner.runTest (/home/ubuntu/project/node_modules/mocha/lib/runner.js:343:10)
at /home/ubuntu/project/node_modules/mocha/lib/runner.js:389:12
at next (/home/ubuntu/project/node_modules/mocha/lib/runner.js:269:14)
at /home/ubuntu/project/node_modules/mocha/lib/runner.js:278:7
at next (/home/ubuntu/project/node_modules/mocha/lib/runner.js:226:23)
at Array.<anonymous> (/home/ubuntu/project/node_modules/mocha/lib/runner.js:246:5)
at EventEmitter._tickCallback (node.js:190:38)

有没有办法强制 Mocha 运行所有测试?

最佳答案

在挖掘了 Mocha 的源代码之后,我发现以下工作(在我们的情况下)。我们将参数“bail”附加到我们的 mocha 套件设置中

测试.html

<script src="mocha.js"></script>
<script>
mocha.ui('bdd');
mocha.bail(false);//<-- this line is the magic
mocha.reporter('html');
</script>

通过附加保释参数,它不会在第一次失败后停止执行。默认情况下,此参数似乎为 false(从命令行运行时),但在通过 phantomjs 执行测试时为 true。 (我们使用的是 Mocha v1.8.1)

关于mocha.js - 以编程方式使用时,Mocha 在第一次测试失败后存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14434033/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com