我想多次调用test
函数,但是在第一次调用jasmine.onComplete
之后,程序退出。我已经知道,我不能并行进行多个测试,但我想,我可以排队,但如果茉莉从节点退出,我就完成了。为此:
有没有办法防止茉莉花退出节点?
const toCall = {}
jasmine.onComplete(function(passed) {
toCall[varReporter.last.name](passed, varReporter.last.result)
toCall[varReporter.last.name] = null
});
function test(folder, file, callback){
toCall[file] = callback
jasmine.execute(['JS/' + folder + '/tests/' + file + '.js'])
}
// User saves a file, a test get triggered.
test('prototype', 'Array', function(passed, result){
console.log(util.inspect(result, { colors: true, depth: null }))
})
// User saves an other file and an other test should get triggered, but can't.
我的测试不会在组中调用,而是根据用户与文件的交互逐个调用。我需要在每次保存后运行测试,以便我可以确定何时应该处理它们。
答案 0 :(得分:2)
您可以覆盖jasmine退出选项:
jasmine.exit = () => {};
但这会导致各种故障。 我宁愿在另一个过程中运行整个脚本:
生成-test.js 强>
const path = require('path'),
Jasmine = require('jasmine/lib/jasmine.js');
const jasmine = new Jasmine({ projectBaseDir: path.resolve() });
jasmine.execute(process.argv.slice(2));
<强>手表tests.js 强>
const fork = require('child_process').fork;
function test(folder, file) {
fork('run-test.js', ['JS/' + folder + '/tests/' + file + '.js']);
}
// User saves a file, a test get triggered.
test('prototype', 'Array')
// User saves an other file and an other test should get triggered, but can't.