Skip to content

Commit b05aaed

Browse files
committed
fix(@angular-devkit/build-angular): remove double-watch in karma
The Karma file watching was racing with the file writes done by the application builder. Since we already tell Karma when to reun via `.refeshFiles()`, disabling Karma's own file watcher should make things more reliable. This allows removing a weird special-case in the test case and removes the noisy "File chaned" logs generated by Karma. Fixes #28755
1 parent daea0ab commit b05aaed

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

packages/angular_devkit/build_angular/src/builders/karma/application_builder.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,28 +265,33 @@ async function initializeApplication(
265265
karmaOptions.files ??= [];
266266
karmaOptions.files.push(
267267
// Serve polyfills first.
268-
{ pattern: `${outputPath}/polyfills.js`, type: 'module' },
268+
{ pattern: `${outputPath}/polyfills.js`, type: 'module', watched: false },
269269
// Serve global setup script.
270-
{ pattern: `${outputPath}/${mainName}.js`, type: 'module' },
270+
{ pattern: `${outputPath}/${mainName}.js`, type: 'module', watched: false },
271271
// Serve all source maps.
272-
{ pattern: `${outputPath}/*.map`, included: false },
272+
{ pattern: `${outputPath}/*.map`, included: false, watched: false },
273273
);
274274

275275
if (hasChunkOrWorkerFiles(buildOutput.files)) {
276276
karmaOptions.files.push(
277277
// Allow loading of chunk-* files but don't include them all on load.
278-
{ pattern: `${outputPath}/{chunk,worker}-*.js`, type: 'module', included: false },
278+
{
279+
pattern: `${outputPath}/{chunk,worker}-*.js`,
280+
type: 'module',
281+
included: false,
282+
watched: false,
283+
},
279284
);
280285
}
281286

282287
karmaOptions.files.push(
283288
// Serve remaining JS on page load, these are the test entrypoints.
284-
{ pattern: `${outputPath}/*.js`, type: 'module' },
289+
{ pattern: `${outputPath}/*.js`, type: 'module', watched: false },
285290
);
286291

287292
if (options.styles?.length) {
288293
// Serve CSS outputs on page load, these are the global styles.
289-
karmaOptions.files.push({ pattern: `${outputPath}/*.css`, type: 'css' });
294+
karmaOptions.files.push({ pattern: `${outputPath}/*.css`, type: 'css', watched: false });
290295
}
291296

292297
const parsedKarmaConfig: Config & ConfigOptions = await karma.config.parseConfig(

packages/angular_devkit/build_angular/src/builders/karma/tests/behavior/rebuilds_spec.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { execute } from '../../index';
1111
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeKarmaBuilder } from '../setup';
1212
import { BuilderOutput } from '@angular-devkit/architect';
1313

14-
describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget, isApplicationBuilder) => {
14+
describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => {
1515
describe('Behavior: "Rebuilds"', () => {
1616
beforeEach(async () => {
1717
await setupTarget(harness);
@@ -45,13 +45,6 @@ describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget, isAppli
4545
expect(result?.success).toBeTrue();
4646
},
4747
];
48-
if (isApplicationBuilder) {
49-
expectedSequence.unshift(async (result) => {
50-
// This is the initial Karma run, it should succeed.
51-
// For simplicity, we trigger a run the first time we build in watch mode.
52-
expect(result?.success).toBeTrue();
53-
});
54-
}
5548

5649
const buildCount = await harness
5750
.execute({ outputLogsOnFailure: false })

0 commit comments

Comments
 (0)