From 01ec715d522721c777802229868a1a4d8a478287 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] 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. --- .../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');