Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// Workaround for https://github.com/webpack-contrib/karma-webpack/issues/66

export class KarmaWebpackFailureCb {
constructor(private callback: () => void) { }
constructor(private callback: (error: string | undefined, errors: string[]) => void) { }

apply(compiler: any): void {
compiler.hooks.done.tap('KarmaWebpackFailureCb', (stats: any) => {
if (stats.compilation.errors.length > 0) {
this.callback();
this.callback(undefined, stats.compilation.errors.map((error: any) => error.message? error.message : error.toString()));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,16 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
publicPath: '/_karma_webpack_/',
};

// Finish Karma run early in case of compilation error.
const compilationErrorCb = () => emitter.emit('run_complete', [], { exitCode: 1 });
const compilationErrorCb = (error: string | undefined, errors: string[]) => {
// Notify potential listeners of the compile error
emitter.emit('compile_error', errors);

// Finish Karma run early in case of compilation error.
emitter.emit('run_complete', [], { exitCode: 1 });

// Unblock any karma requests (potentially started using `karma run`)
unblock();
}
webpackConfig.plugins.push(new KarmaWebpackFailureCb(compilationErrorCb));

// Use existing config if any.
Expand Down Expand Up @@ -157,14 +165,18 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
});
});

function unblock(){
isBlocked = false;
blocked.forEach((cb) => cb());
blocked = [];
}

compiler.plugin('done', (stats: any) => {
// Don't refresh karma when there are webpack errors.
if (stats.compilation.errors.length === 0) {
emitter.refreshFiles();
isBlocked = false;
blocked.forEach((cb) => cb());
blocked = [];
}
unblock();
});

webpackMiddleware = new webpackDevMiddleware(compiler, webpackMiddlewareConfig);
Expand Down