我requirejs
在 Karma 中使用过加载模块,效果很好。当我更改requirejs
为 时webpack
,业力不会运行测试用例。我使用mocha
, sinon
,chai
作为我的测试框架。
├── src
| ├── js
| └── a.js
├── test
| ├── spec
| └── test_a.js
这是我的karma.conf.js
:
var webpackConfig = require("../webpack.config");
module.exports = function(config) {
config.set({
basePath: '../',
frameworks: ['mocha', 'chai', 'sinon'],
files: [
'test/**/test_*.js'
],
preprocessors: {
'test/**/test_*.js': ['webpack']
},
webpack: webpackConfig,
proxies: {
'/data/': '/base/test/data/'
},
exclude: [],
client: {
mocha: {
reporter: 'html',
ui: 'bdd'
}
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG,
autoWatch: false,
browsers: ['PhantomJS', 'Chrome'],
singleRun: false,
concurrency: Infinity
})
}
我webpack.config.js
的是:
var webpack = require('webpack');
var path = require('path');
module.exports = {
context: path.join(__dirname, 'src'),
entry: {
bundle1: './initializer.js'
},
output: {
path: path.join(__dirname, 'src'),
filename: '[name].js'
},
resolve: {
extensions: ['', '.js'],
modulesDirectories: ["./src", "node_modules"]
},
devtool: 'inline-source-map',
module: {
loaders: []
}
}
我test_a.js
的是:
require([
'jquery',
'src/js/a'
], function($, A) { // $ and A load successfully
describe('A', function() {
beforeEach(function() {
//****
});
afterEach(function() {
//****
});
describe('#on()', function() { // will come to this line
it('should ....', function() { //will come to this line too
assert.ok(1 > 0, "A is working"); // never run into the function
});
});
}
}