-
Notifications
You must be signed in to change notification settings - Fork 11.9k
test(@angular/build): add e2e test for animations chunk optimization #33035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alan-agius4
merged 1 commit into
angular:main
from
clydin:e2e/chunk-optimizer-animations
Apr 23, 2026
+76
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { readdir } from 'node:fs/promises'; | ||
| import { readFile, writeFile } from '../../utils/fs'; | ||
| import { installPackage } from '../../utils/packages'; | ||
| import { execWithEnv } from '../../utils/process'; | ||
|
|
||
| export default async function () { | ||
| // Read @angular/core version from test project's package.json | ||
| const projectJson = JSON.parse(await readFile('package.json')); | ||
| const ngCoreVersion = | ||
| projectJson.dependencies?.['@angular/core'] ?? | ||
| projectJson.devDependencies?.['@angular/core'] ?? | ||
| 'latest'; | ||
|
|
||
| // Install @angular/animations package with matching version | ||
| await installPackage(`@angular/animations@${ngCoreVersion}`); | ||
|
|
||
| // Configure app.config.ts with provideAnimationsAsync | ||
| const originalConfig = await readFile('src/app/app.config.ts'); | ||
| await writeFile( | ||
| 'src/app/app.config.ts', | ||
| ` | ||
| import { provideAnimationsAsync } from '@angular/platform-browser/animations/async'; | ||
| ${originalConfig.replace(/providers:\s*\[/, 'providers: [provideAnimationsAsync(),')} | ||
| `, | ||
| ); | ||
|
|
||
| const updatedConfig = await readFile('src/app/app.config.ts'); | ||
| assert.ok( | ||
| updatedConfig.includes('provideAnimationsAsync()'), | ||
| 'Expected src/app/app.config.ts to include provideAnimationsAsync().', | ||
| ); | ||
|
|
||
| // Build with chunk optimization | ||
| await execWithEnv('ng', ['build', '--output-hashing=none'], { | ||
| ...process.env, | ||
| NG_BUILD_OPTIMIZE_CHUNKS: '1', | ||
| }); | ||
| const optimizedFiles = await readdir('dist/test-project/browser'); | ||
| const optimizedJsFiles = optimizedFiles.filter((f) => f.endsWith('.js')); | ||
|
|
||
| // Read the optimized main.js file | ||
| const mainCode = await readFile('dist/test-project/browser/main.js'); | ||
|
|
||
| // Check that optimized chunks still contain more than 1 javascript file | ||
| assert.ok( | ||
| optimizedJsFiles.length > 1, | ||
| `Expected more than one chunk, but found ${optimizedJsFiles.length}.`, | ||
| ); | ||
|
|
||
| // Check that one of the lazy loaded chunks contains the animations package code | ||
| let foundAnimationsChunk = false; | ||
| for (const file of optimizedJsFiles) { | ||
| if (file === 'main.js') { | ||
| continue; | ||
| } | ||
| const code = await readFile(`dist/test-project/browser/${file}`); | ||
| if (code.includes('AnimationEngine')) { | ||
| foundAnimationsChunk = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| assert.ok( | ||
| foundAnimationsChunk, | ||
| 'Expected to find AnimationEngine in one of the optimized lazy chunks.', | ||
| ); | ||
|
|
||
| // The animations engine should not be bundled in main.js | ||
| assert.ok( | ||
| !mainCode.includes('AnimationEngine'), | ||
| 'Expected main.js not to contain AnimationEngine from @angular/animations/browser.', | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.