Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 841
guilhebl Avatar asked Oct 29 '15 23:10

guilhebl


2 Answers

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){
  // ...
});
like image 122
MarcoL Avatar answered Nov 15 '22 20:11

MarcoL


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

like image 2
guilhebl Avatar answered Nov 15 '22 18:11

guilhebl