Skip to content

Commit 5cd7a50

Browse files
alan-agius4clydin
authored andcommitted
test: remove hardcoded worker chunk id
This commit changes how we retrieve the worker chunk Id. Prior to this change we hard coded the value, now we get it by reading the file names on disk. (cherry picked from commit 2925f06)
1 parent b8e391b commit 5cd7a50

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

tests/legacy-cli/e2e/tests/build/worker.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import { readdir } from 'fs/promises';
910
import { expectFileToExist, expectFileToMatch, replaceInFile, writeFile } from '../../utils/fs';
1011
import { ng } from '../../utils/process';
1112

@@ -26,7 +27,8 @@ export default async function () {
2627
await expectFileToMatch('dist/test-project/main.js', 'src_app_app_worker_ts');
2728

2829
await ng('build', '--output-hashing=none');
29-
const chunkId = '151';
30+
31+
const chunkId = await getWorkerChunkId();
3032
await expectFileToExist(`dist/test-project/${chunkId}.js`);
3133
await expectFileToMatch('dist/test-project/main.js', chunkId);
3234

@@ -53,3 +55,14 @@ export default async function () {
5355

5456
await ng('e2e');
5557
}
58+
59+
async function getWorkerChunkId(): Promise<string> {
60+
const files = await readdir('dist/test-project');
61+
const fileName = files.find((f) => /^\d{3}\.js$/.test(f));
62+
63+
if (!fileName) {
64+
throw new Error('Cannot determine worker chunk Id.');
65+
}
66+
67+
return fileName.substring(0, 3);
68+
}

0 commit comments

Comments
 (0)