karma-runner / karma-requirejs

A Karma plugin. Adapter for RequireJS framework.
MIT License
39 stars 36 forks source link

Mocha v3 triggers "mismatched anonymous define" error #50

Open viveleroi opened 8 years ago

viveleroi commented 8 years ago

After upgrading to Mocha 3.0.0, karma-requirejs throws an error when trying to run tests:

Mismatched anonymous define() module: function () { return JSON3; }

This does not occur when I downgrade to Mocha 2.5.3.

I'm using:

We use gulp to activate the tests:

gulp.task('test:components', function() {
    var karma = require('karma').server;

    karma.start({
        configFile: basePath + '/karma.conf.js'
    });
});

And I've reduced our karma.conf.js file to a very limited set:

module.exports = function(config) {
    config.set({
        frameworks: ['mocha', 'requirejs'],
        browsers: ['PhantomJS'],
        port: 9876,
        singleRun: true
    });
};

Here's the full startup log:

03 08 2016 12:54:05.189:INFO [karma]: Karma v1.1.2 server started at http://localhost:9876/
03 08 2016 12:54:05.192:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
03 08 2016 12:54:05.198:INFO [launcher]: Starting browser PhantomJS
03 08 2016 12:54:05.786:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket /#0At0vvA1atYS3xCnAAAA with id 32375243
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  Error: Mismatched anonymous define() module: function () {
        return JSON3;
      }
  http://requirejs.org/docs/errors.html#mismatch
  at /Users/viveleroi/project/node_modules/requirejs/require.js:143
fearphage commented 8 years ago

I filed this bug officially with the Mocha team - mochajs/mocha#2424.

lddubeau commented 8 years ago

I can reproduce the problem but the issue is not with karma-requirejs. It is with Mocha itself. Switch your frameworks so that they are like this:

frameworks: ['requirejs', 'mocha']

and the problem should be resolved. I'm going to explain why on the Mocha issue that fearphage filed.

boneskull commented 8 years ago

This should be fixed in mocha@3.0.2 (publishing in a few minutes).