编程语言
首页 > 编程语言> > javascript – 在吞咽测试后关闭浏览器的Karma

javascript – 在吞咽测试后关闭浏览器的Karma

作者:互联网

我正在使用谷歌中的Chrome和Firefox发射器进行基本的茉莉花测试.但我的浏览器之后总是被关闭.无论测试成功与否,即使在任务和配置中指定单次运行为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次成功3次(0.041秒/ 0.036秒)

Firefox 38.0.0(Windows 7 0.0.0):执行3次成功3次(0.001秒/ 0.013秒)

总计:6成功

Chrome 43.0.2357(Windows 7 0.0.0):执行3次成功3次(0.041秒/ 0.036秒)

Firefox 38.0.0(Windows 7 0.0.0):执行3次成功3次(0.001秒/ 0.013秒)

总计:6成功

[11:09:27]在4.52秒后完成’测试’

进程以代码0终止.

解决方法:

当你使用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
    });
});

标签:javascript,gulp,karma-runner,karma-jasmine,gulp-karma
来源: https://codeday.me/bug/20190623/1273597.html