diff --git a/packages/schematics/angular/migrations/use-application-builder/migration.ts b/packages/schematics/angular/migrations/use-application-builder/migration.ts index 4bcf6d9e6ee6..396ba48430d2 100644 --- a/packages/schematics/angular/migrations/use-application-builder/migration.ts +++ b/packages/schematics/angular/migrations/use-application-builder/migration.ts @@ -217,6 +217,7 @@ function updateProjects(tree: Tree, context: SchematicContext) { case Builders.Application: case Builders.DevServer: case Builders.ExtractI18n: + case Builders.Karma: case Builders.NgPackagr: // Ignore application, dev server, and i18n extraction for devkit usage check. // Both will be replaced if no other usage is found. @@ -242,6 +243,13 @@ function updateProjects(tree: Tree, context: SchematicContext) { case Builders.ExtractI18n: target.builder = '@angular/build:extract-i18n'; break; + case Builders.Karma: + target.builder = '@angular/build:karma'; + // Remove "builderMode" option since the builder will always use "application" + for (const [, karmaOptions] of allTargetOptions(target)) { + delete karmaOptions['builderMode']; + } + break; case Builders.NgPackagr: target.builder = '@angular/build:ng-packagr'; break; diff --git a/packages/schematics/angular/migrations/use-application-builder/migration_spec.ts b/packages/schematics/angular/migrations/use-application-builder/migration_spec.ts index 587c60016ceb..3adef7d419eb 100644 --- a/packages/schematics/angular/migrations/use-application-builder/migration_spec.ts +++ b/packages/schematics/angular/migrations/use-application-builder/migration_spec.ts @@ -40,6 +40,15 @@ function createWorkSpaceConfig(tree: UnitTestTree) { tree.create('/package.json', JSON.stringify({}, undefined, 2)); } +function addWorkspaceTarget(tree: UnitTestTree, targetName: string, targetEntry: unknown): void { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const workspaceContent = tree.readJson('/angular.json') as Record; + + workspaceContent['projects']['app']['architect'][targetName] = targetEntry; + + tree.overwrite('/angular.json', JSON.stringify(workspaceContent)); +} + describe(`Migration to use the application builder`, () => { const schematicName = 'use-application-builder'; const schematicRunner = new SchematicTestRunner( @@ -102,6 +111,25 @@ describe(`Migration to use the application builder`, () => { }); }); + it(`should remove 'builderMode' from karma options`, async () => { + addWorkspaceTarget(tree, 'test', { + 'builder': Builders.Karma, + 'options': { + 'builderMode': 'detect', + 'polyfills': ['zone.js', 'zone.js/testing'], + 'tsConfig': 'projects/app-a/tsconfig.spec.json', + }, + }); + + const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); + const { + projects: { app }, + } = JSON.parse(newTree.readContent('/angular.json')); + + const { builderMode } = app.architect['test'].options; + expect(builderMode).toBeUndefined(); + }); + it('should remove tilde prefix from CSS @import specifiers', async () => { // Replace outputPath tree.create(