From 8fef7191dc8953c3b0ed79870ff79343f7af37c9 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Tue, 20 Feb 2024 14:28:04 -0500 Subject: [PATCH 1/2] test: generalize webpack direct E2E chunk size testing Updates to `webpack` or any of the used Webpack plugins can cause output chunk identifiers to change. The `packages/webpack/test-app` E2E test previously hard coded these file name identifiers into the test which can cause unexpected test failures when packages are updated. To remedy this situation, the output file contents are now checked to discover any files. (cherry picked from commit 5759cde13e6eebb24e687a7cb0841756a206884b) --- .../e2e/tests/packages/webpack/test-app.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/legacy-cli/e2e/tests/packages/webpack/test-app.ts b/tests/legacy-cli/e2e/tests/packages/webpack/test-app.ts index 23014a148836..63b797883f83 100644 --- a/tests/legacy-cli/e2e/tests/packages/webpack/test-app.ts +++ b/tests/legacy-cli/e2e/tests/packages/webpack/test-app.ts @@ -1,7 +1,9 @@ -import { normalize } from 'path'; +import { join, normalize } from 'path'; import { createProjectFromAsset } from '../../../utils/assets'; import { expectFileSizeToBeUnder, expectFileToMatch, replaceInFile } from '../../../utils/fs'; import { execWithEnv } from '../../../utils/process'; +import { readdir } from 'node:fs/promises'; +import assert from 'node:assert'; export default async function () { const webpackCLIBin = normalize('node_modules/.bin/webpack-cli'); @@ -14,9 +16,17 @@ export default async function () { // Note: these sizes are without Build Optimizer or any advanced optimizations in the CLI. await expectFileSizeToBeUnder('dist/app.main.js', 650 * 1024); - await expectFileSizeToBeUnder('dist/604.app.main.js', 1024); - await expectFileSizeToBeUnder('dist/988.app.main.js', 1024); - await expectFileSizeToBeUnder('dist/896.app.main.js', 1024); + const outputFiles = await readdir('dist', { withFileTypes: true }); + let fileCount = 0; + for (const outputFile of outputFiles) { + if (outputFile.isFile() && outputFile.name.endsWith('.app.main.js')) { + ++fileCount; + await expectFileSizeToBeUnder(join(outputFile.path, outputFile.name), 1024); + } + } + if (fileCount !== 3) { + assert.fail('Expected three additional Webpack output chunk files.'); + } // test resource urls without ./ await replaceInFile('app/app.component.ts', './app.component.html', 'app.component.html'); From 4b0fbca1a1155ef9c250b2a436f7d4aff7fc6674 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Tue, 20 Feb 2024 14:28:04 -0500 Subject: [PATCH 2/2] test: avoid new Node.js properties in webpack direct E2E chunk size testing Avoid using `fs.Dirent.path` in the `packages/webpack/test-app` E2E test to ensure the test executes properly on Node.js v18.13. The property was not added until v18.17. (cherry picked from commit 26092376109ee604d7586021ac01012c65c3417a) --- tests/legacy-cli/e2e/tests/packages/webpack/test-app.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/legacy-cli/e2e/tests/packages/webpack/test-app.ts b/tests/legacy-cli/e2e/tests/packages/webpack/test-app.ts index 63b797883f83..e4f6b5fe71f6 100644 --- a/tests/legacy-cli/e2e/tests/packages/webpack/test-app.ts +++ b/tests/legacy-cli/e2e/tests/packages/webpack/test-app.ts @@ -21,7 +21,7 @@ export default async function () { for (const outputFile of outputFiles) { if (outputFile.isFile() && outputFile.name.endsWith('.app.main.js')) { ++fileCount; - await expectFileSizeToBeUnder(join(outputFile.path, outputFile.name), 1024); + await expectFileSizeToBeUnder(join('dist', outputFile.name), 1024); } } if (fileCount !== 3) {