Skip to content

Instantly share code, notes, and snippets.

@gztchan
Last active April 18, 2018 07:33
Show Gist options
  • Save gztchan/6d18b71394ab3fa08fb033d5c24d82bb to your computer and use it in GitHub Desktop.
Save gztchan/6d18b71394ab3fa08fb033d5c24d82bb to your computer and use it in GitHub Desktop.
karma.base.config.js, Generate Coverage with Karma for New JavaScript features.
const webpackConfig = {
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
],
},
};
module.exports = {
basePath: '../../',
frameworks: ['mocha'],
reporters: ['mocha', 'coverage'], // coverage as subsequent reporter(optional)
files: [
// should include all *.karma.js and helpers
{ pattern: 'spec/helpers/*.js' },
{ pattern: 'spec/**/*.karma.js' },
],
preprocessors: {
// preprocessing with complier if your tests are written in new JavaScript features.
// Do not include source code files for preprocssing by coverage, because babel-plugin-istanbul
// will deal with it.
'spec/helpers/*.js': ['webpack'],
'spec/**/*.karma.js': ['webpack'],
},
webpack: webpackConfig,
plugins: [
'karma-mocha',
'karma-webpack',
],
coverageReporter: {
dir: './coverage',
reporters: [
{ type: 'text' },
{ type: 'html' },
],
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment