Skip to content

Commit 7408a1f

Browse files
cexbrayatalxhub
authored andcommitted
fix(localize): handle @angular/build:karma in ng add (#60513)
`ng add @angular/localize` now also adds the localize polyfill to the configuration of Karma if the `@angular/build:karma` builder is used (which is the default in Angular CLI v20) PR Close #60513
1 parent 9dbccae commit 7408a1f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/localize/schematics/ng-add/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function addPolyfillToConfig(projectName: string): Rule {
3636
for (const target of project.targets.values()) {
3737
switch (target.builder) {
3838
case AngularBuilder.Karma:
39+
case AngularBuilder.BuildKarma:
3940
case AngularBuilder.Server:
4041
case AngularBuilder.Browser:
4142
case AngularBuilder.BrowserEsbuild:

packages/localize/schematics/ng-add/index_spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ describe('ng-add schematic', () => {
7777
polyfills: 'zone.js',
7878
},
7979
},
80+
testKarmaBuild: {
81+
builder: '@angular/build:karma',
82+
options: {
83+
tsConfig: './tsconfig.spec.json',
84+
polyfills: 'zone.js',
85+
},
86+
},
8087
server: {
8188
builder: '@angular-devkit/build-angular:server',
8289
options: {
@@ -173,6 +180,13 @@ describe('ng-add schematic', () => {
173180
expect(polyfills).toEqual(['zone.js', '@angular/localize/init']);
174181
});
175182

183+
it(`should add '@angular/localize/init' in 'polyfills' in karma application builder`, async () => {
184+
host = await schematicRunner.runSchematic('ng-add', defaultOptions, host);
185+
const workspace = host.readJson('angular.json') as any;
186+
const polyfills = workspace.projects['demo'].architect.testKarmaBuild.options.polyfills;
187+
expect(polyfills).toEqual(['zone.js', '@angular/localize/init']);
188+
});
189+
176190
it(`should add '@angular/localize/init' in 'polyfills' in browser builder`, async () => {
177191
host = await schematicRunner.runSchematic('ng-add', defaultOptions, host);
178192
const workspace = host.readJson('angular.json') as any;

0 commit comments

Comments
 (0)