From 5cd7a50b728b8b025b3f1372fd370e5550f188b3 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Fri, 26 Aug 2022 08:27:46 +0000 Subject: [PATCH] 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 2925f067da487cd75678eba805d835a70c7279bb) --- tests/legacy-cli/e2e/tests/build/worker.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/legacy-cli/e2e/tests/build/worker.ts b/tests/legacy-cli/e2e/tests/build/worker.ts index a930a8ce3ff2..a8dc02e0b4f9 100644 --- a/tests/legacy-cli/e2e/tests/build/worker.ts +++ b/tests/legacy-cli/e2e/tests/build/worker.ts @@ -6,6 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ +import { readdir } from 'fs/promises'; import { expectFileToExist, expectFileToMatch, replaceInFile, writeFile } from '../../utils/fs'; import { ng } from '../../utils/process'; @@ -26,7 +27,8 @@ export default async function () { await expectFileToMatch('dist/test-project/main.js', 'src_app_app_worker_ts'); await ng('build', '--output-hashing=none'); - const chunkId = '151'; + + const chunkId = await getWorkerChunkId(); await expectFileToExist(`dist/test-project/${chunkId}.js`); await expectFileToMatch('dist/test-project/main.js', chunkId); @@ -53,3 +55,14 @@ export default async function () { await ng('e2e'); } + +async function getWorkerChunkId(): Promise { + const files = await readdir('dist/test-project'); + const fileName = files.find((f) => /^\d{3}\.js$/.test(f)); + + if (!fileName) { + throw new Error('Cannot determine worker chunk Id.'); + } + + return fileName.substring(0, 3); +}