我不知道如何解决这个问题。除上述之外,我没有任何错误。这是我的配置文件:
./ webpack.config.js
var webpackConfig = require('./webpack.config');
webpackConfig.devtool = 'inline-source-map';
module.exports = function(config) {
config.set({
frameworks: ['mocha', 'chai', 'sinon', 'sinon-chai'],
plugins: [
'karma-chrome-launcher',
'karma-mocha',
'karma-chai',
'karma-sinon',
'karma-sinon-chai',
'karma-sourcemap-loader',
'karma-webpack'
],
files: [
'tests.webpack.js'
],
exclude: [],
preprocessors: {
'tests.webpack.js': ['webpack', 'sourcemap']
},
webpack: webpackConfig,
webpackMiddleware: {
noInfo: true
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG,
autoWatch: true,
browsers: ['Chrome'],
singleRun: true,
});
}
./ karma.conf.js
'use strict';
require('babel-polyfill');
require('core-js/fn/object/assign');
var context = require.context('./test', true, /Test\.jsx$/);
context.keys().forEach(context);
./ tests.webpack.js
'use strict';
var TestUtils = require('react-addons-test-utils');
import {expect} from 'chai';
describe('App', () => {
it('should display correct text on render', () => {
let component = TestUtils.renderIntoDocument(<App/>);
expect('hello').to.equal('hello');
});
});
示例测试文件(test / app / AppTest.jsx):
DEBUG: [config]: autoWatch set to false, because of singleRun
DEBUG [plugin]: Loading plugin karma-chrome-launcher.
DEBUG [plugin]: Loading plugin karma-mocha.
DEBUG [plugin]: Loading plugin karma-chai.
DEBUG [plugin]: Loading plugin karma-sinon.
DEBUG [plugin]: Loading plugin karma-sinon-chai.
DEBUG [plugin]: Loading plugin karma-sourcemap-loader.
DEBUG [plugin]: Loading plugin karma-webpack.
DEBUG [web-server]: Instantiating middleware
DEBUG [preprocessor.sourcemap]: base64-encoded source map for /Users/gasim/Stack/gasim/gasim-frontend/tests.webpack.js
INFO [karma]: Karma v1.1.0 server started at http://localhost:9876/
INFO [launcher]: Launching browser Chrome with unlimited concurrency
INFO [launcher]: Starting browser Chrome
DEBUG [temp-dir]: Creating temp dir at /var/folders/0q/z4cbhb7x49jgk2ycw4f9hxd00000gn/T/karma-37005516
DEBUG [launcher]: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --user-data-dir=/var/folders/0q/z4cbhb7x49jgk2ycw4f9hxd00000gn/T/karma-37005516 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling http://localhost:9876/?id=37005516
DEBUG [web-server]: serving: /Users/gasim/Stack/gasim/gasim-frontend/node_modules/karma/static/client.html
DEBUG [web-server]: serving: /Users/gasim/Stack/gasim/gasim-frontend/node_modules/karma/static/karma.js
DEBUG [karma]: A browser has connected on socket /#ZLT5diBbmtOJweMIAAAA
DEBUG [web-server]: upgrade /socket.io/?EIO=3&transport=websocket&sid=ZLT5diBbmtOJweMIAAAA
DEBUG [web-server]: serving: /Users/gasim/Stack/gasim/gasim-frontend/node_modules/karma/static/favicon.ico
INFO [Chrome 51.0.2704 (Mac OS X 10.11.5)]: Connected on socket /#ZLT5diBbmtOJweMIAAAA with id 37005516
DEBUG [launcher]: Chrome (id 37005516) captured in 2.52 secs
DEBUG [middleware:karma]: custom files null null
DEBUG [middleware:karma]: Serving static request /context.html
DEBUG [web-server]: serving: /Users/gasim/Stack/gasim/gasim-frontend/node_modules/karma/static/context.html
DEBUG [web-server]: serving: /Users/gasim/Stack/gasim/gasim-frontend/node_modules/karma/static/context.js
Chrome 51.0.2704 (Mac OS X 10.11.5) ERROR
You need to include some adapter that implements __karma__.start method!
这是karma调试输出(我删除了时间,所以它更具可读性):
DEBUG [middleware:karma]: custom files null null
我真正感兴趣的是调试输出中的以下行:
null null
为什么会说{{1}}?这是否意味着测试文件是空的还是什么?
答案 0 :(得分:0)
这一行的问题在这里:
frameworks: ['mocha', 'chai', 'sinon', 'sinon-chai'],
无需包含chai
或sinon
。他们是给我错误的人。所以,我只保留mocha
和sinon-chai
,我只是从我的测试脚本中加载chai
和sinon
。