npm i -D karma-webpack
This configuration is more performant, but you cannot run single test anymore (only the complete suite).
The above configuration generates a
webpack bundle for each test. For many test cases this can result in many big files. The alternative configuration creates a single bundle with all test cases.
files:// only specify one entry point// and require all tests in there'test/index_test.js'preprocessors:// add webpack as preprocessor'test/index_test.js': 'webpack'
// require all modules ending in "_test" from the// current directory and all subdirectoriesconst testsContext = requiretestsContext
Every test file is required using the require.context and compiled with webpack into one test bundle.
You can use the
karma-sourcemap-loader to get the source maps generated for your test bundle.
npm i -D karma-sourcemap-loader
And then add it to your preprocessors.
preprocessors:'test/test_index.js': 'webpack' 'sourcemap'
webpack to generate sourcemaps.
webpack:// ...devtool: 'inline-source-map'
This is the full list of options you can specify in your
||Pass custom middleware configuration to
webpack configuration (
beforeMiddleware is a
webpack option that allows injecting middleware before
karma's own middleware runs. This loader provides a
middleware that will block tests from running until code recompiles. That is,
given this scenario
- Have a browser open on the karma debug page (http://localhost:9876/debug.html)
- Make a code change
webpackBlocker middleware karma will serve files from before
the code change. With the
webpackBlocker middleware the loader will not serve
the files until the code has finished recompiling.
beforeMiddlewareoption is only supported in
karma >= v1.0.0
|Joshua Wiens||Will Farley||Daniela Valero|
|Jonathan Trang||Carlos Morales|