使用 Karma 未能 运行 测试
Failing to run tests using Karma
我正在设置 Karma 以简化遗留项目中的单元测试。问题是,我收到一个错误 You need to include some adapter that implements __karma__.start method!
。正如我所发现的,这是一个非常不具体的错误,所以我不知道如何进一步调试它。我已将设置减少到最低限度,但错误仍然存在。
这里是 karma 配置文件:
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);
})
请问如何进一步调试这个问题?
更新: 这是一个 gist 具有最小可重现性的案例。我一定是哪里做错了,因为我仍然收到错误 You need to include some adapter that implements __karma__.start method!
,但我不知道我的错误是什么。
尝试删除 karma 配置中对 chai-sinon
的引用。当我摆脱它时,测试就会运行。我无法准确解释原因,但可能存在版本不兼容问题。
我正在设置 Karma 以简化遗留项目中的单元测试。问题是,我收到一个错误 You need to include some adapter that implements __karma__.start method!
。正如我所发现的,这是一个非常不具体的错误,所以我不知道如何进一步调试它。我已将设置减少到最低限度,但错误仍然存在。
这里是 karma 配置文件:
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);
})
请问如何进一步调试这个问题?
更新: 这是一个 gist 具有最小可重现性的案例。我一定是哪里做错了,因为我仍然收到错误 You need to include some adapter that implements __karma__.start method!
,但我不知道我的错误是什么。
尝试删除 karma 配置中对 chai-sinon
的引用。当我摆脱它时,测试就会运行。我无法准确解释原因,但可能存在版本不兼容问题。