I've got a working Karma setup, using Webpack. Whenever I modify either a test file or any of its dependencies, all of the tests run. This is all good, but I'd really like it to run only the minimum number of tests. If I change a test file, it should run only that test file. If I change a source file, it should run whatever test files have that source file as a dependency (via require
).
Here's the relevant portion of my karma.config.js
:
files: [
{
pattern: '**/*.test.js',
watched: true,
included: true,
served: true
},
],
preprocessors: {
'**/*.test.js': ['webpack']
},
webpack: {
resolve: {
root: path.join(__dirname, '..', 'webpack'),
extensions: ['', '.js', '.jsx'],
},
module: {
loaders: [
{
test: /.jsx?$/,
loader: 'babel-loader',
exclude: [/node_modules/],
query: {
presets: ['es2015', 'react']
}
},
]
},
},
The complete karma.config.js
file is in a gist.
I'm familiar with solutions mentioned in other questions, involving process.env.npm_config_single_file
, but that's not what I'm trying to do.
Based on my config above, I'm expecting it to handle each file as a separate webpack, which is also implied by the documentation at the top of webpack/karma-webpack. Instead, what I seem to get is a single webpack with two chunks, per the log:
Asset Size Chunks Chunk Names
employee_list_entry.test.js 1.07 MB 0 [emitted] employee_list_entry.test.js
employer_list_entry.test.js 1.07 MB 1 [emitted] employer_list_entry.test.js
chunk {0} employee_list_entry.test.js (employee_list_entry.test.js) 1.01 MB
It always rebuilds both chunks even when I only save one test file.