Skip to content

fix(@angular/build): auto-inject localize/init in library unit tests#33453

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
clydin:fix-vitest-localize-libraries
Jun 25, 2026
Merged

fix(@angular/build): auto-inject localize/init in library unit tests#33453
alan-agius4 merged 1 commit into
angular:mainfrom
clydin:fix-vitest-localize-libraries

Conversation

@clydin

@clydin clydin commented Jun 24, 2026

Copy link
Copy Markdown
Member

Injects '@angular/localize/init' at the top of the internal virtual initialization file (angular:test-bed-init) if '@angular/localize' is installed in the workspace. This prevents ReferenceErrors when testing libraries that consume localization APIs.

Also updates the warning plugin to skip internal imports originating from the 'angular:' namespace.

@clydin clydin added the target: patch This PR is targeted for the next patch release label Jun 24, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request conditionally imports @angular/localize/init in virtual test bed initialization files for both Karma and Vitest builders if @angular/localize is installed in the project. It also updates the Angular localize init warning plugin to skip files with an angular: namespace. Feedback was provided to use optional chaining when checking args.namespace to prevent potential runtime errors if the namespace is undefined.

Comment thread packages/angular/build/src/tools/esbuild/angular-localize-init-warning-plugin.ts Outdated
Injects '@angular/localize/init' at the top of the internal virtual initialization file (angular:test-bed-init) if '@angular/localize' is installed in the workspace. This prevents ReferenceErrors when testing libraries that consume localization APIs.

Also updates the warning plugin to skip internal imports originating from the 'angular:' namespace.
@clydin clydin force-pushed the fix-vitest-localize-libraries branch from 5016561 to 95c6426 Compare June 24, 2026 20:48
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Jun 24, 2026
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jun 25, 2026
@alan-agius4 alan-agius4 merged commit 75c1dce into angular:main Jun 25, 2026
41 checks passed
@alan-agius4

Copy link
Copy Markdown
Collaborator

This PR was merged into the repository. The changes were merged into the following branches:

@clydin clydin deleted the fix-vitest-localize-libraries branch June 25, 2026 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unit-test builder with vitest fails to properly handle $localize call's in library projects

2 participants