Javascript 防止茉莉花不完全退出

Javascript 防止茉莉花不完全退出,javascript,node.js,jasmine,Javascript,Node.js,Jasmine,我想多次调用test函数,但在第一次调用jasmine.onComplete后,程序退出。我已经知道,我不能并行地进行多个测试,但是我想,我可能可以对它们进行排队,但是如果jasmine退出节点,我就完成了。因此: 有没有办法防止jasmine退出节点 const toCall = {} jasmine.onComplete(function(passed) { toCall[varReporter.last.name](passed, varReporter.last.result)

我想多次调用
test
函数,但在第一次调用
jasmine.onComplete
后,程序退出。我已经知道,我不能并行地进行多个测试,但是我想,我可能可以对它们进行排队,但是如果jasmine退出节点,我就完成了。因此:

有没有办法防止jasmine退出节点

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.

我的测试不会分组调用,而是基于用户与文件的交互,一个接一个地调用。我需要在每次保存后运行测试,以便确定何时应该处理它们

您可以覆盖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));
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.
观看tests.js

const path = require('path'),
    Jasmine = require('jasmine/lib/jasmine.js');

const jasmine = new Jasmine({ projectBaseDir: path.resolve() });
jasmine.execute(process.argv.slice(2));
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.

您可以覆盖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));
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.
观看tests.js

const path = require('path'),
    Jasmine = require('jasmine/lib/jasmine.js');

const jasmine = new Jasmine({ projectBaseDir: path.resolve() });
jasmine.execute(process.argv.slice(2));
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.

这就是我最终得到的。。。主要原因是,我可以运行多个测试(即使是并行的,这不是必需的,但仍然很好),只是为了澄清一下,你应该在fork中添加密切的侦听器,这样人们就可以看到如何正确地执行它。这实际上是我最终得到的。。。主要原因是,我可以运行多个测试(即使是并行的,这不是必需的,但仍然很好),只是为了澄清,您应该在fork中添加close listener,这样人们就可以看到如何正确地执行它