Configuring karma to work with webpack

This commit is contained in:
Jeff Avallone 2016-10-15 12:33:28 -04:00
parent a8a76651c2
commit 2a496bf4c1
3 changed files with 13 additions and 19 deletions

View File

@ -1,30 +1,21 @@
var _ = require('lodash'), var webpack = require('./webpack.config.js');
config = require('./config');
module.exports = function(karma) { module.exports = function(karma) {
var globs = _.flatten([
config.globs.js,
config.globs.spec
]);
karma.set({ karma.set({
frameworks: ['browserify', 'jasmine'], frameworks: ['browserify', 'jasmine'],
files: globs, files: [ 'spec/test_index.js' ],
preprocessors: _(globs) preprocessors: {
.zipObject() 'spec/test_index.js': ['webpack', 'sourcemap']
.mapValues(_.constant(['browserify'])) },
.valueOf(),
reporters: ['progress', 'notify'], reporters: ['progress', 'notify'],
colors: true, colors: true,
logLevel: karma.LOG_INFO, logLevel: karma.LOG_INFO,
browsers: ['Firefox'], browsers: ['Firefox'],
autoWatch: true, autoWatch: true,
singleRun: false, singleRun: false,
browserify: _.extend({ webpack: {
configure: function(bundler) { devtool: 'inline-source-map',
bundler.transform(require('./lib/canopy-transform')); module: webpack.module
bundler.transform(require('babelify'));
} }
}, config.browserify)
}); });
}; };

View File

@ -33,10 +33,11 @@
"imports-loader": "^0.6.5", "imports-loader": "^0.6.5",
"jasmine-core": "^2.4.1", "jasmine-core": "^2.4.1",
"karma": "^1.1.2", "karma": "^1.1.2",
"karma-browserify": "^5.0.2",
"karma-firefox-launcher": "^1.0.0", "karma-firefox-launcher": "^1.0.0",
"karma-jasmine": "^1.0.2", "karma-jasmine": "^1.0.2",
"karma-notify-reporter": "^1.0.1", "karma-notify-reporter": "^1.0.1",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.8.0",
"lodash": "^4.6.1", "lodash": "^4.6.1",
"node-bourbon": "^4.2.3", "node-bourbon": "^4.2.3",
"snapsvg": "^0.4.0", "snapsvg": "^0.4.0",

2
spec/test_index.js Normal file
View File

@ -0,0 +1,2 @@
var testsContext = require.context(".", true, /_spec$/);
testsContext.keys().forEach(testsContext);