Skip to content

fix(@schematics/angular): application migration should migrate karma builder package #30084

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
merged 1 commit into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>;

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(
Expand Down Expand Up @@ -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(
Expand Down