“API changed” warning when starting Karma on grunt

When I start karma from the grunt task, I get the following warning:

Running "karma:unit" (karma) task Warning: The api interface has changed. Please use server = new Server(config, [done]) server.start() instead. Use --force to continue. Aborted due to warnings. 

I checked the karma with my configuration using the “run” and “start” karma commands, and they seem to work fine.

Using grunt --force may complete the task, but it ends with warnings.

These are the versions that I am currently using:

  • Karma 0.13.0
  • Grunt 0.4.5
  • grunt-cli 0.1.13
  • node.js 0.12.7
  • npm 2.11.3

The project was generated using yoman (1.4.7), but I have the same problem using Karma in a separate project using only jasmine, karma and Grunt (also tested with Gulp).

I was looking for a warning message but could not find anything. I do not know if this is the expected behavior or if there is another way to complete tasks without warning.

+6
source share
4 answers

If you use the grunt-karma plugin to run Karma tests from Grunt, you need to update the grunt-karma dependency in your package.json file to 0.12.0:

 "devDependencies": { ... "grunt-karma": "~0.12.0", ... } 

Version 0.12.0 from grunt-karma was released earlier today and it uses the new API: https://github.com/karma-runner/grunt-karma/releases

+4
source

They have changed with the new version here:

https://github.com/karma-runner/karma/blob/master/CHANGELOG.md#breaking-changes

 var Server = require('karma').Server; var config = { configFile: path.join(__dirname, '/../karma.conf.js'), singleRun: singleRun, autoWatch: !singleRun }; var server = new Server(config, done) server.start() 
+5
source

I use Gulp, and I had to either configure the test task as follows:

 var Server = require('karma').Server; gulp.task('test', function (done) { new Server({ configFile: __dirname + '/karma.conf.js', singleRun: true }, done).start(); }); 

or return the karma version to 0.10.0 for it to work. There is currently no request for pull gulp-karma to change how it works, but I'm not sure if there will be changes in the future.

Here is a useful example that was updated after changing the Karma API: https://github.com/karma-runner/gulp-karma

0
source

If you use the Yeoman - angular generator, like me, you will need to disable it in the grunt-karma.js file.

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

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

and then at the bottom of the file in the else block instead of server.start(config, done);

you will find server.start(data, finished.bind(done));

just put var server = new Server(data, finished.bind(done)); right above it, and it should work fine.

-1
source

All Articles