我正在运行基本的茉莉花测试,使用Chrome和Firefox发射器进行业力测试,来自gulp。但我的浏览器之后总是被关闭。无论测试成功与否,即使在任务和配置中将单次运行指定为false也是如此。
Gulp任务:
karma = require('gulp-karma');
gulp.task('test', ['testsSetup'], function() {
// Be sure to return the stream
// NOTE: Using the fake './foobar' so as to run the files
// listed in karma.conf.js INSTEAD of what was passed to
// gulp.src !
return gulp.src('./foobar')
.pipe(karma({
configFile: 'karma.conf.js',
singleRun: false
}))
.on('error', function(err) {
// Make sure failed tests cause gulp to exit non-zero
console.log(err);
//this.emit('end'); //instead of erroring the stream, end it
});
});
karma.conf.js:
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome','Firefox'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
成功测试的最后一部分输出:
Chrome 43.0.2357(Windows 7 0.0.0):执行3 of 3 SUCCESS(0.041秒/0.036秒)
Firefox 38.0.0(Windows 7 0.0.0):执行3次成功3次(0.001秒/ 0.013秒)
TOTAL:6 SUCCESS
Chrome 43.0.2357(Windows 7 0.0.0):执行3 of 3 SUCCESS(0.041秒/0.036秒)
Firefox 38.0.0(Windows 7 0.0.0):执行3次成功3次(0.001秒/ 0.013秒)
TOTAL:6 SUCCESS
[11:09:27]在4.52秒后完成'测试'
进程以代码0终止。
答案 0 :(得分:4)
当你使用gulp-karma时,你传入的参数与你直接传递给业力的参数不同。 上面的singleRun参数被忽略。我将我的任务更改为以下内容(指定了一个操作),它可以按照您的预期运行:
gulp.task('test', ['testsSetup'], function() {
// Be sure to return the stream
// NOTE: Using the fake './foobar' so as to run the files
// listed in karma.conf.js INSTEAD of what was passed to
// gulp.src !
return gulp.src('./foobar')
.pipe(karma({
configFile: 'karma.conf.js',
action: 'watch',
showStack: true
}))
.on('error', function(err) {
// Make sure failed tests cause gulp to exit non-zero
console.log(err);
this.emit('end'); //instead of erroring the stream, end it
});
});