更新时间:2023-09-27 23:36:34
I have replicate your project and fix it. Following the https://github.com/webpack/karma-webpack
In the spec:
var a = require('../src/hello.js');
karma.conf.js:
module.exports = function (config) {
config.set({
frameworks: ['jasmine'],
files: [
//'src/**/*.js', <-------- Remove or comment this
'tests/**/*.spec.js'
],
preprocessors: {
'tests/**/*.spec.js': ['webpack'],
'src/**/*.js' : ['webpack']
},
browsers: ['PhantomJS'],
webpack: {
entry: './tests/hello.spec.js',
output: {
filename: 'bundle.js'
}
},
webpackMiddleware: {
noInfo: true
}
})
};
And additionally for npm test command: in package.json:
"scripts": {
"test": "./node_modules/karma/bin/karma start"
}