Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "module not defined" error when using Gulp to run karma tests

My team is working on moving from Grunt to Gulp. I have a Grunt test task that works fine, but when I try to run the tests (using gulp-karma) I get an error that says "ReferenceError: Can't find variable: module"

I Googled and found a lot of posts saying to check the location of my angular-mocks.js file, and it's in the correct space (my Grunt task for the same code does work).

To verify that it wasn't something weird in my code a spun up a new yo angular app and was able to replicate the error.

My guess is that I'm missing a configuration value or a step or something. Any advice?

Thanks.

like image 789
James Bender Avatar asked Dec 19 '22 08:12

James Bender


1 Answers

The answer by @mcranston18 will absolutely work. But as an alternative option, gulp-karma is currently an unnecessary plugin. Part of the advantage of gulp is that you don't have to use a plugin for everything under the sun. Instead, you can wire into karma directly.

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

gulp.task('tests', function(done) {
  return karma.start({
      configFile: __dirname + '/test/karma.conf.js',
      singleRun: true
    }, done);
});
like image 95
Jay Harris Avatar answered Dec 28 '22 05:12

Jay Harris