Last active
December 18, 2015 00:24
-
-
Save charlesponti/e71b686a946a2823e734 to your computer and use it in GitHub Desktop.
Webpack ES2015 Karma with Test coverage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-env node */ | |
var path = require('path'); | |
var _ = require('lodash'); | |
var here = require('path-here'); | |
/** | |
* Current Environment | |
* @type {string} | |
*/ | |
process.env.NODE_ENV = process.env.NODE_ENV || 'test'; | |
/** | |
* If tests are being run in DEBUG mode | |
* @type {boolean} | |
*/ | |
var debug = process.env.DEBUG === 'true'; | |
/** | |
* If tests are being run by Continuous Integration | |
* @type {boolean} | |
*/ | |
var ci = process.env.NODE_ENV === 'test:ci'; | |
/** | |
* Webpack configuration | |
* @type {*|exports|module.exports} | |
*/ | |
var webpackConfig = require('./webpack.config'); | |
webpackConfig.entry = {}; | |
module.exports = function(config) { | |
config.set({ | |
basePath: './', | |
frameworks: ['jasmine'], | |
files: [ | |
'assets/js/vendor.js', | |
'bower_components/angular-mocks/angular-mocks.js', | |
'./src/main.js', | |
'./src/**/*.spec.js' | |
], | |
babelPreprocessor: { | |
options: { | |
presets: ['es2015'], | |
sourceMap: 'inline' | |
} | |
}, | |
preprocessors: { | |
'./src/main.js': ['webpack', 'sourcemap'], | |
'./src/**/*.spec.js': ['webpack'] | |
}, | |
reporters: ['progress', 'coverage'], | |
webpack: { | |
devtool: 'inline-source-map', | |
module: { | |
loaders: webpackConfig.module.loaders, | |
postLoaders: [ | |
{ | |
test: /\.js$/, | |
exclude: /(__tests__|node_modules|bower_components)\//, | |
loader: 'istanbul-instrumenter' | |
} | |
] | |
} | |
}, | |
webpackMiddleware: {noInfo: true}, | |
coverageReporter: { | |
reporters: [ | |
{type: 'html', dir: 'coverage/'}, | |
{type: 'lcov', dir: 'coverage/', subdir: '.'}, | |
{type: 'json', dir: 'coverage/', subdir: '.'}, | |
{type: 'text-summary'} | |
] | |
}, | |
port: 9876, | |
colors: true, | |
logLevel: config.LOG_INFO, | |
autoWatch: !ci, | |
browsers: [debug ? 'Chrome' : 'PhantomJS2'], | |
singleRun: ci, | |
browserNoActivityTimeout: 180000 | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webpack = require('webpack'); | |
module.exports = { | |
entry: __dirname + '/src/main.js', | |
stats: { | |
colors: true, | |
reasons: true | |
}, | |
devtool: 'source-map', | |
output: { | |
path: './assets/js', | |
filename: 'main.js' | |
}, | |
module: { | |
loaders: [ | |
{ | |
test: /\.js?$/, | |
exclude: /(node_modules|bower_components)/, | |
loader: 'babel', | |
query: { | |
presets: ['es2015'], | |
plugins: ['transform-runtime'] | |
} | |
}, | |
{ | |
test: /\.html$/, | |
name: "templates", | |
loader: 'raw!html-minify' | |
} | |
] | |
}, | |
'html-minify-loader': { | |
empty: true, // KEEP empty attributes | |
cdata: true, // KEEP CDATA from scripts | |
comments: true // KEEP comments | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment