简体   繁体   English

gulp karma test TypeError:服务器不是函数

[英]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 尝试使用gulp运行karma运行测试,但是在遵循以下示例之后: https//github.com/karma-runner/gulp-karma

My gulp file: 我的gulp档案:

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: 在我运行之后:gulp test我得到错误:

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 . 该API已经从0.120.13 ,你已经证明的例子是一个为0.13

The previous API was the following: 以前的API如下:

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

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

The issue was that karma-cli npm module wasn't properly installed globally. 问题是karma-cli npm模块没有在全球范围内正确安装。 Running: npm install -g karma-cli solved the issue. 正在运行: npm install -g karma-cli解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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