Skip to content

Instantly share code, notes, and snippets.

@frederickfogerty
Created June 4, 2015 21:40
Show Gist options
  • Save frederickfogerty/f07f389c58ad1fdd28bc to your computer and use it in GitHub Desktop.
Save frederickfogerty/f07f389c58ad1fdd28bc to your computer and use it in GitHub Desktop.
Coverage + tests with webpack, babel, karma, mocha, and istanbul
var webpack = require('webpack')
module.exports = function (config) {
config.set({
browsers: [ 'Chrome' ], //run in Chrome
browserNoActivityTimeout: 60000,
singleRun: true, //just run once by default
frameworks: [ 'mocha' ], //use the mocha test framework
files: [
//'src/**/*.{jsx,js}',
'tests.webpack.js' //just load this file
],
preprocessors: {
'tests.webpack.js': ['webpack', 'sourcemap' ], //preprocess with webpack and our sourcemap loader
//'src/**/*.jsx?': ['coverage']
},
reporters: [ 'mocha', 'coverage' ], //report results in this format
mochaReporter: {
output: 'autowatch'
},
coverageReporter: {
reporters: [
{type: 'text'},
{type: 'html'}
]
},
webpack: {
devtool: 'inline-source-map',
module: {
loaders: [
{ test: /\.jsx?$/, loader: 'babel-loader' }
],
postLoaders: [ {
test: /\.js$/,
exclude: /(test|node_modules|bower_components)\//,
loader: 'istanbul-instrumenter'
} ]
}
},
webpackServer: {
noInfo: true //please don't spam the console when running in karma!
}
});
};
var context = require.context('./src', true, /\.test\.jsx?$/) // make sure you have your directory and regex test set correctly!
context.keys().forEach(context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment