Skip to content

Commit 6720482

Browse files
committed
fix(@angular-devkit/build-angular): don't rerun tests on unchanged compilation
Fix angular#11880
1 parent 8150838 commit 6720482

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,11 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
174174
blocked = [];
175175
}
176176

177+
let lastCompilationHash: string | undefined;
177178
compiler.hooks.done.tap('karma', (stats: any) => {
178-
// Don't refresh karma when there are webpack errors.
179-
if (stats.compilation.errors.length === 0) {
179+
// Refresh karma only when there are no webpack errors, and if the compilation changed.
180+
if (stats.compilation.errors.length === 0 && stats.hash != lastCompilationHash) {
181+
lastCompilationHash = stats.hash;
180182
emitter.refreshFiles();
181183
}
182184
unblock();

packages/angular_devkit/build_angular/test/karma/rebuilds_spec_large.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import { host, karmaTargetSpec } from '../utils';
1313

1414
// Karma watch mode is currently bugged:
1515
// - errors print a huge stack trace
16-
// - karma does not have a way to close the server gracefully.
16+
// - karma does not have a way to close the server
17+
// gracefully (https://github.com/karma-runner/karma-jasmine/issues/219)
1718
// TODO: fix these before 6.0 final.
1819
xdescribe('Karma Builder watch mode', () => {
1920
beforeEach(done => host.initialize().toPromise().then(done, done.fail));
@@ -64,4 +65,9 @@ xdescribe('Karma Builder watch mode', () => {
6465
take(3),
6566
).toPromise().then(done, done.fail);
6667
}, 30000);
68+
69+
it('does not rebuild when nothing changed', (done) => {
70+
// Start the server in watch mode, wait for the first build to finish, touch
71+
// test.js without changing it, wait 5s then exit unsuscribe, verify only one event was emitted.
72+
}, 30000);
6773
});

0 commit comments

Comments
 (0)