Skip to content

Commit d213df7

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 17d2187 commit d213df7

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import { execAndWaitForOutputToMatch, waitForAnyProcessOutputToMatch } from '../
77

88
const buildReadyRegEx = /Application bundle generation complete\./;
99

10-
async function getOutputFiles(
10+
async function getOutputChunks(
1111
dir: string,
12-
predicate: (files: string[]) => boolean,
12+
predicate: (chunks: string[]) => boolean,
1313
timeout = 10_000,
1414
): Promise<string[]> {
1515
const start = Date.now();
1616
while (Date.now() - start < timeout) {
1717
try {
18-
const files = await readdir(dir);
19-
if (predicate(files)) {
20-
return files;
18+
const chunks = (await readdir(dir)).filter((file) => file.endsWith('.js'));
19+
if (predicate(chunks)) {
20+
return chunks;
2121
}
2222
} catch (err: any) {
2323
if (err?.code !== 'ENOENT') {
@@ -27,10 +27,10 @@ async function getOutputFiles(
2727
await setTimeout(50);
2828
}
2929

30-
const files = await readdir(dir);
31-
assert(predicate(files), `Condition not met for files in ${dir}: ${JSON.stringify(files)}`);
30+
const chunks = (await readdir(dir)).filter((file) => file.endsWith('.js'));
31+
assert(predicate(chunks), `Condition not met for chunks in ${dir}: ${JSON.stringify(chunks)}`);
3232

33-
return files;
33+
return chunks;
3434
}
3535

3636
export default async function () {
@@ -46,9 +46,9 @@ export default async function () {
4646
['build', '--watch', '--configuration=development'],
4747
buildReadyRegEx,
4848
);
49-
const initialOutputFiles = await getOutputFiles(
49+
const initialOutputChunks = await getOutputChunks(
5050
'dist/test-project/browser',
51-
(files) => files.length > 0,
51+
(chunks) => chunks.length > 0,
5252
);
5353

5454
const originalMain = await readFile('src/main.ts');
@@ -66,12 +66,12 @@ export default async function () {
6666
),
6767
appendToFile('src/main.ts', `\nimport('./a').then((m) => m.sayHi());`),
6868
]);
69-
const intermediateOutputFiles = await getOutputFiles(
69+
const intermediateOutputChunks = await getOutputChunks(
7070
'dist/test-project/browser',
71-
(files) => files.length > initialOutputFiles.length,
71+
(chunks) => chunks.length > initialOutputChunks.length,
7272
);
7373
assert(
74-
initialOutputFiles.length < intermediateOutputFiles.length,
74+
initialOutputChunks.length < intermediateOutputChunks.length,
7575
'Additional chunks should be present',
7676
);
7777

@@ -80,13 +80,13 @@ export default async function () {
8080
waitForAnyProcessOutputToMatch(buildReadyRegEx),
8181
writeFile('src/main.ts', originalMain),
8282
]);
83-
const finalOutputFiles = await getOutputFiles(
83+
const finalOutputChunks = await getOutputChunks(
8484
'dist/test-project/browser',
85-
(files) => files.length === initialOutputFiles.length,
85+
(chunks) => chunks.length === initialOutputChunks.length,
8686
);
8787
assert.equal(
88-
initialOutputFiles.length,
89-
finalOutputFiles.length,
88+
initialOutputChunks.length,
89+
finalOutputChunks.length,
9090
'Final chunk count should be equal to initial chunk count.',
9191
);
9292
}

0 commit comments

Comments
 (0)