Skip to content

Commit 8654b3f

Browse files
clydinalan-agius4
authored andcommitted
fix(@schematics/angular): application migration should migrate karma builder package
The `use-application-builder` update migration will now attempt to migrate the `karma` builder to use the `@angular/build` package if no other `@angular-devkit/build-angular` usage is present.
1 parent 807ba25 commit 8654b3f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Diff for: packages/schematics/angular/migrations/use-application-builder/migration.ts

+8
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ function updateProjects(tree: Tree, context: SchematicContext) {
217217
case Builders.Application:
218218
case Builders.DevServer:
219219
case Builders.ExtractI18n:
220+
case Builders.Karma:
220221
case Builders.NgPackagr:
221222
// Ignore application, dev server, and i18n extraction for devkit usage check.
222223
// Both will be replaced if no other usage is found.
@@ -242,6 +243,13 @@ function updateProjects(tree: Tree, context: SchematicContext) {
242243
case Builders.ExtractI18n:
243244
target.builder = '@angular/build:extract-i18n';
244245
break;
246+
case Builders.Karma:
247+
target.builder = '@angular/build:karma';
248+
// Remove "builderMode" option since the builder will always use "application"
249+
for (const [, karmaOptions] of allTargetOptions(target)) {
250+
delete karmaOptions['builderMode'];
251+
}
252+
break;
245253
case Builders.NgPackagr:
246254
target.builder = '@angular/build:ng-packagr';
247255
break;

Diff for: packages/schematics/angular/migrations/use-application-builder/migration_spec.ts

+28
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ function createWorkSpaceConfig(tree: UnitTestTree) {
4040
tree.create('/package.json', JSON.stringify({}, undefined, 2));
4141
}
4242

43+
function addWorkspaceTarget(tree: UnitTestTree, targetName: string, targetEntry: unknown): void {
44+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
45+
const workspaceContent = tree.readJson('/angular.json') as Record<string, any>;
46+
47+
workspaceContent['projects']['app']['architect'][targetName] = targetEntry;
48+
49+
tree.overwrite('/angular.json', JSON.stringify(workspaceContent));
50+
}
51+
4352
describe(`Migration to use the application builder`, () => {
4453
const schematicName = 'use-application-builder';
4554
const schematicRunner = new SchematicTestRunner(
@@ -102,6 +111,25 @@ describe(`Migration to use the application builder`, () => {
102111
});
103112
});
104113

114+
it(`should remove 'builderMode' from karma options`, async () => {
115+
addWorkspaceTarget(tree, 'test', {
116+
'builder': Builders.Karma,
117+
'options': {
118+
'builderMode': 'detect',
119+
'polyfills': ['zone.js', 'zone.js/testing'],
120+
'tsConfig': 'projects/app-a/tsconfig.spec.json',
121+
},
122+
});
123+
124+
const newTree = await schematicRunner.runSchematic(schematicName, {}, tree);
125+
const {
126+
projects: { app },
127+
} = JSON.parse(newTree.readContent('/angular.json'));
128+
129+
const { builderMode } = app.architect['test'].options;
130+
expect(builderMode).toBeUndefined();
131+
});
132+
105133
it('should remove tilde prefix from CSS @import specifiers', async () => {
106134
// Replace outputPath
107135
tree.create(

0 commit comments

Comments
 (0)