Skip to content

Commit a3fe2cf

Browse files
committed
test(@angular/build): prevent flakiness in incremental-watch e2e test
In watch mode, 'Application bundle generation complete.' can be logged before all files have finished being emitted to disk. Sampling 'files.length > 0' initially could capture a partial file count, causing the final count comparison to time out once all assets are fully written. Update the test to only track JavaScript chunk files (.js), which prevents race conditions with unrelated asset emission and directly aligns with the test's intent of verifying chunk addition and removal for dynamic imports.
1 parent 0ad1409 commit a3fe2cf

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

tests/e2e/tests/build/incremental-watch.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ async function getOutputFiles(
3333
return files;
3434
}
3535

36+
async function getOutputChunks(
37+
dir: string,
38+
predicate: (chunks: string[]) => boolean,
39+
timeout = 10_000,
40+
): Promise<string[]> {
41+
const files = await getOutputFiles(
42+
dir,
43+
(files) => predicate(files.filter((file) => file.endsWith('.js'))),
44+
timeout,
45+
);
46+
47+
return files.filter((file) => file.endsWith('.js'));
48+
}
49+
3650
export default async function () {
3751
const usingApplicationBuilder = getGlobalVariable('argv')['esbuild'];
3852
assert(
@@ -46,9 +60,9 @@ export default async function () {
4660
['build', '--watch', '--configuration=development'],
4761
buildReadyRegEx,
4862
);
49-
const initialOutputFiles = await getOutputFiles(
63+
const initialOutputChunks = await getOutputChunks(
5064
'dist/test-project/browser',
51-
(files) => files.length > 0,
65+
(chunks) => chunks.length > 0,
5266
);
5367

5468
const originalMain = await readFile('src/main.ts');
@@ -66,12 +80,12 @@ export default async function () {
6680
),
6781
appendToFile('src/main.ts', `\nimport('./a').then((m) => m.sayHi());`),
6882
]);
69-
const intermediateOutputFiles = await getOutputFiles(
83+
const intermediateOutputChunks = await getOutputChunks(
7084
'dist/test-project/browser',
71-
(files) => files.length > initialOutputFiles.length,
85+
(chunks) => chunks.length > initialOutputChunks.length,
7286
);
7387
assert(
74-
initialOutputFiles.length < intermediateOutputFiles.length,
88+
initialOutputChunks.length < intermediateOutputChunks.length,
7589
'Additional chunks should be present',
7690
);
7791

@@ -80,13 +94,13 @@ export default async function () {
8094
waitForAnyProcessOutputToMatch(buildReadyRegEx),
8195
writeFile('src/main.ts', originalMain),
8296
]);
83-
const finalOutputFiles = await getOutputFiles(
97+
const finalOutputChunks = await getOutputChunks(
8498
'dist/test-project/browser',
85-
(files) => files.length === initialOutputFiles.length,
99+
(chunks) => chunks.length === initialOutputChunks.length,
86100
);
87101
assert.equal(
88-
initialOutputFiles.length,
89-
finalOutputFiles.length,
102+
initialOutputChunks.length,
103+
finalOutputChunks.length,
90104
'Final chunk count should be equal to initial chunk count.',
91105
);
92106
}

0 commit comments

Comments
 (0)