Skip to content

Commit

Permalink
test: generalize webpack direct E2E chunk size testing
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
clydin authored and dgp1130 committed Feb 22, 2024
1 parent 4fc5c6a commit 40e04f6
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions tests/legacy-cli/e2e/tests/packages/webpack/test-app.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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');
Expand Down

0 comments on commit 40e04f6

Please sign in to comment.