我在Karma中使用requirejs
来加载模块,它运行正常。当我将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
});
});
}
}
答案 0 :(得分:0)
在我的测试文件中将require
更改为define
后,它现在正在运行。
似乎webpack
将使用require
加载Commonjs模块作为默认值。