Skip to content

Commit 40e04f6

Browse files
clydindgp1130
authored andcommitted
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 5759cde)
1 parent 4fc5c6a commit 40e04f6

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

tests/legacy-cli/e2e/tests/packages/webpack/test-app.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { normalize } from 'path';
1+
import { join, normalize } from 'path';
22
import { createProjectFromAsset } from '../../../utils/assets';
33
import { expectFileSizeToBeUnder, expectFileToMatch, replaceInFile } from '../../../utils/fs';
44
import { execWithEnv } from '../../../utils/process';
5+
import { readdir } from 'node:fs/promises';
6+
import assert from 'node:assert';
57

68
export default async function () {
79
const webpackCLIBin = normalize('node_modules/.bin/webpack-cli');
@@ -14,9 +16,17 @@ export default async function () {
1416

1517
// Note: these sizes are without Build Optimizer or any advanced optimizations in the CLI.
1618
await expectFileSizeToBeUnder('dist/app.main.js', 650 * 1024);
17-
await expectFileSizeToBeUnder('dist/604.app.main.js', 1024);
18-
await expectFileSizeToBeUnder('dist/988.app.main.js', 1024);
19-
await expectFileSizeToBeUnder('dist/896.app.main.js', 1024);
19+
const outputFiles = await readdir('dist', { withFileTypes: true });
20+
let fileCount = 0;
21+
for (const outputFile of outputFiles) {
22+
if (outputFile.isFile() && outputFile.name.endsWith('.app.main.js')) {
23+
++fileCount;
24+
await expectFileSizeToBeUnder(join(outputFile.path, outputFile.name), 1024);
25+
}
26+
}
27+
if (fileCount !== 3) {
28+
assert.fail('Expected three additional Webpack output chunk files.');
29+
}
2030

2131
// test resource urls without ./
2232
await replaceInFile('app/app.component.ts', './app.component.html', 'app.component.html');

0 commit comments

Comments
 (0)