azangru
azangru

Reputation: 2738

Failing to run tests using Karma

I am setting up Karma to simplify unit tests in a legacy project. The problem is, I am getting an error You need to include some adapter that implements __karma__.start method!. As I have found, this is a very non-specific error, so I am at a loss of how to debug it further. I have reduced my setup to the bare minimum, but the error still persists.

Here is the karma config file:

module.exports = function (config) {
  config.set({
    browsers: [ 'PhantomJS' ], //run in Phantom
    autoWatch: false,
    singleRun: true, //just run once by default
    frameworks: [ 'mocha', 'chai', 'sinon', 'chai-sinon' ], // test frameworks
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    files: [
      './js/test/tests.webpack.js' //just load this file
    ],
    preprocessors: {
      './js/test/tests.webpack.js': [ 'webpack', 'sourcemap' ] //preprocess with webpack and our sourcemap loader
    },
    reporters: [ 'mocha' ], //report results in this format
    webpack: { // webpack settings
      devtool: 'inline-source-map',
      module: {
        loaders: [
          { test: /\.js$/, loader: 'babel-loader' }
        ]
      }
    },
    webpackServer: {
      noInfo: true
    },
    plugins: [
        'karma-mocha',
        'karma-webpack',
        'karma-sourcemap-loader',
        'karma-mocha-reporter',
        'karma-phantomjs-launcher',
        'karma-chai',
        'karma-sinon',
        'karma-chai-sinon'
    ]
  });
};

Here are the packages I have installed (from package.json):

"babel-core": "^6.9.1",
"babel-loader": "^6.2.4",
"babel-plugin-module-alias": "^1.5.0",
"babel-preset-es2015": "^6.9.0",
"chai": "^3.5.0",
"karma": "^1.0.0",
"karma-chai": "^0.1.0",
"karma-chai-sinon": "^0.1.5",
"karma-chrome-launcher": "^1.0.1",
"karma-mocha": "^1.0.1",
"karma-mocha-reporter": "^2.0.4",
"karma-phantomjs-launcher": "^1.0.1",
"karma-sinon": "^1.0.5",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.7.0",
"mocha": "^2.5.3",
"phantomjs": "^2.1.7",
"phantomjs-polyfill": "0.0.2",
"sinon": "^1.17.4",
"sinon-chai": "^2.8.0",
"webpack": "^1.13.1"

Here is .babelrc:

{
  "presets": ["es2015"]
}

And here is the test file that I am referencing in karma.conf.js (tests.webpack.js). My initial idea was to require all spec files in it, but now I have changed it to run at least a single test. Still no luck:

import chai from 'chai';
var expect = chai.expect;

console.log('I was found');
it('works', function () {
    expect(true).to.equal(true);
})

Could you please advise how to debug this problem further?

UPDATE: Here's a gist with a minimal reproducible case. I must be doing something wrong there, because I am still receiving the error You need to include some adapter that implements __karma__.start method!, but I can't figure out what my mistake is.

Upvotes: 2

Views: 1490

Answers (1)

Andrew Eisenberg
Andrew Eisenberg

Reputation: 28737

Try removing the reference to chai-sinon in karma config. When I get rid of it, the test runs. I can't exactly explain why, but perhaps there is version incompatibility going on.

Upvotes: 3

Related Questions