Skip to content

Commit 5ff83e8

Browse files
nicojsfilipesilva
authored andcommitted
feat(angular_devkit): stop blocking karma after compilation error
1 parent a7b33a9 commit 5ff83e8

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma-webpack-failure-cb.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
// Workaround for https://github.com/webpack-contrib/karma-webpack/issues/66
1313

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

1717
apply(compiler: any): void {
1818
compiler.hooks.done.tap('KarmaWebpackFailureCb', (stats: any) => {
1919
if (stats.compilation.errors.length > 0) {
20-
this.callback();
20+
this.callback(undefined, stats.compilation.errors.map((error: any) => error.message? error.message : error.toString()));
2121
}
2222
});
2323
}

packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,16 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
9191
publicPath: '/_karma_webpack_/',
9292
};
9393

94-
// Finish Karma run early in case of compilation error.
95-
const compilationErrorCb = () => emitter.emit('run_complete', [], { exitCode: 1 });
94+
const compilationErrorCb = (error: string | undefined, errors: string[]) => {
95+
// Notify potential listeners of the compile error
96+
emitter.emit('compile_error', errors);
97+
98+
// Finish Karma run early in case of compilation error.
99+
emitter.emit('run_complete', [], { exitCode: 1 });
100+
101+
// Unblock any karma requests (potentially started using `karma run`)
102+
unblock();
103+
}
96104
webpackConfig.plugins.push(new KarmaWebpackFailureCb(compilationErrorCb));
97105

98106
// Use existing config if any.
@@ -157,14 +165,18 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
157165
});
158166
});
159167

168+
function unblock(){
169+
isBlocked = false;
170+
blocked.forEach((cb) => cb());
171+
blocked = [];
172+
}
173+
160174
compiler.plugin('done', (stats: any) => {
161175
// Don't refresh karma when there are webpack errors.
162176
if (stats.compilation.errors.length === 0) {
163177
emitter.refreshFiles();
164-
isBlocked = false;
165-
blocked.forEach((cb) => cb());
166-
blocked = [];
167178
}
179+
unblock();
168180
});
169181

170182
webpackMiddleware = new webpackDevMiddleware(compiler, webpackMiddlewareConfig);

0 commit comments

Comments
 (0)