Skip to content

Instantly share code, notes, and snippets.

@jonesmac
Created December 22, 2018 00:47
Show Gist options
  • Save jonesmac/9ef456153c714db56be0ec24b61c6fbb to your computer and use it in GitHub Desktop.
Save jonesmac/9ef456153c714db56be0ec24b61c6fbb to your computer and use it in GitHub Desktop.
/*
* This plugin makes sure karma doesn't run any specs when there's a
* compilation error in a module by checking the finished compilation for warnings
* which would prevent tests from accurately running.
*
* Inspiration for looking at the warnings length
* https://gist.github.com/Stuk/6b574049435df532e905
*/
import { Compiler } from 'webpack';
export class WebpackKarmaWarningsPlugin {
public apply(compiler: Compiler) {
compiler.hooks.emit.tapAsync(
'WebpackKarmaWarningsPlugin',
(compilation, callback) => {
if (compilation.warnings.length) {
throw new Error(compilation.warnings.toString());
}
callback();
}
);
}
}
@TranquilMarmot
Copy link

This no longer works with Webpack 5 😭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment