我正在关注一个angular-webpack教程,当学习使用karma进行测试时,webpack被用作karma配置文件中的预处理器,并且其条目被设置为karma的监视文件:所以这就是整个{{ 1}}:
karma.config.js
这是前一个文件中所需的var path = require('path');
var webpackConfig = require('./webpack.config');
var entry = path.resolve(webpackConfig.context, webpackConfig.entry);
var preprocessors = {};
preprocessors[entry] = ['webpack'];
// Karma configuration
// Generated on Wed Sep 14 2016 08:47:45 GMT+0100 (Afr. centrale Ouest)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha'],
// list of files / patterns to load in the browser
files: [entry],
webpack:webpackConfig,
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: preprocessors,
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity,
plugins:[
require('karma-webpack'),
'karma-chai',
'karma-mocha',
'karma-chrome-launcher'
]
})
}
:
webpack.config.js
当我试图开始业力测试时,我得到以下错误:
var webpack = require('webpack');
module.exports = {
context: require('path').resolve(__dirname, "app"),
entry:'./app.js',
output: {
path : __dirname + '/app',
filename:'bundle.js'
},
plugins:[
new webpack.DefinePlugin({
ON_TEST:process.env.NODE_ENV === 'test';
})
],
module:{
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel', // 'babel-loader' is also a legal name to reference
query: {
presets: ['es2015']
}
},
{ test: /\.css$/,
loader: "style-loader!css-loader",
exclude: /(node_modules|bower_components)/
},
{
test: /\.html$/,
exclude: /(node_modules|bower_components)/,
loader: 'raw', // 'babel-loader' is also a legal name to reference
},
{ test: /\.styl$/,
loader: 'style-loader!css-loader!stylus-loader',
exclude: /(node_modules|bower_components)/
}
]
},
resolve: {
extensions: ['', '.js', '.jsx', '.css']
},
resolveLoader: {
root: require('path').resolve(__dirname, "node_modules")
}
}