简体   繁体   中英

gulp karma test TypeError: Server is not a function

Trying to run karma using gulp for running tests but after following the example from: https://github.com/karma-runner/gulp-karma

My gulp file:

var gulp = require('gulp');
var Server = require('karma').Server;

/**
 * Run test once and exit
 */
gulp.task('test', function (done) {
  new Server({
    configFile: __dirname + '/karma.conf.js',
    singleRun: true
  }, done).start();
});

/**
 * Watch for file changes and re-run tests on each change
 */
gulp.task('tdd', function (done) {
  new Server({
    configFile: __dirname + '/karma.conf.js'
  }, done).start();
});

gulp.task('default', ['tdd']);

after I run: gulp test I get the Error:

TypeError: Server is not a function at Gulp.<anonymous>

Any suggestions of what might be wrong?

Which version of karma do you have installed?

The API has changed from 0.12 to 0.13 and the example you've shown is the one for 0.13 .

The previous API was the following:

var server = require('karma').server;

//... more code
server.start( { .... } , function(exitCode){
  // ...
});

The issue was that karma-cli npm module wasn't properly installed globally. Running: npm install -g karma-cli solved the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM