karma-webpack-with-fast-source-maps
This is a fork of karma-webpack which enables file source maps and hot testing
Installation
npm install --save-dev karma-webpack-with-fast-source-maps
Usage
// in karma.conf.jsfiles:// only specify one entry point// and require all tests in there'test/test_index.js'preprocessors:// add webpack as preprocessor'test/test_index.js': 'webpack'
// test/test_index.js// This gets replaced by karma webpack with the updated files on rebuildvar __karmaWebpackManifest__ = ;// require all modules ending in "_test" from the// current directory and all subdirectoriesvar testsContext = require;{return __karmaWebpackManifest__ >= 0;}var runnable = testsContext;// Run all tests if we didn't find any changesif !runnablelengthrunnable = testsContext;runnable;
Every test file is required using the require.context and compiled with webpack into one test bundle.
When a file changes, only the affected tests will be run.
If a failure occurs, the failing group will be rerun each run until they pass.
If no tests are affected by a change, all tests are rerun (if you touch
your test_index.js it will run all tests).
Source Maps
File (Faster)
File source maps are faster and work out of the box. Use:
webpack:// ...devtool: 'cheap-module-source-map'
Inline
Or, if you want inline source maps, you can use the karma-sourcemap-loader
:
npm install --save-dev karma-sourcemap-loader
And then add it to your preprocessors
preprocessors:'test/test_index.js': 'webpack' 'sourcemap'
And tell webpack to generate sourcemaps
webpack:// ...devtool: 'inline-source-map'
Options
This is the full list of options you can specify in your Karma config.
webpack
Webpack configuration.
webpackMiddleware
Configuration for webpack-dev-middleware.
License
Copyright 2014-2015 Tobias Koppers