我正在设置 Karma 以简化遗留项目中的单元测试。问题是,我得到一个错误You need to include some adapter that implements __karma__.start method!
。正如我所发现的,这是一个非常非特定的错误,所以我不知道如何进一步调试它。我已将设置减少到最低限度,但错误仍然存在。
这是业力配置文件:
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'
]
});
};
这是我安装的软件包(来自 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"
这是.babelrc:
{
"presets": ["es2015"]
}
这是我在 karma.conf.js (tests.webpack.js) 中引用的测试文件。我最初的想法是要求其中包含所有规范文件,但现在我已将其更改为至少运行一个测试。仍然没有运气:
import chai from 'chai';
var expect = chai.expect;
console.log('I was found');
it('works', function () {
expect(true).to.equal(true);
})
您能否建议如何进一步调试此问题?
更新:这是一个具有最小可重现案例的要点。我一定在那里做错了什么,因为我仍然收到错误You need to include some adapter that implements __karma__.start method!
,但我无法弄清楚我的错误是什么。