Skip to content

Commit

Permalink
fix(angular): fix chalk import and correctly skip invalid projects in…
Browse files Browse the repository at this point in the history
… ng-add generator
  • Loading branch information
leosvelperez committed Jun 25, 2024
1 parent 47dfdcf commit 589ab2f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ describe('app migrator', () => {
jest.clearAllMocks();
});

it('should not migrate project when validation fails', async () => {
// add project with no root
const project = addProject('app1', {} as any);
const migrator = new AppMigrator(tree, {}, project);

await migrator.migrate();

expect(tree.exists('apps/app1/project.json')).toBe(false);
const { projects } = readJson(tree, 'angular.json');
expect(projects.app1).toBeDefined();
});

describe('validation', () => {
it('should fail validation when the project root is not specified', async () => {
const project = addProject('app1', {} as any);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ export class AppMigrator extends ProjectMigrator<SupportedTargets> {
}

override async migrate(): Promise<void> {
await super.migrate();

if (this.skipMigration === true) {
return;
}

await super.migrate();

this.updateProjectConfiguration();

await this.e2eMigrator.migrate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ describe('lib migrator', () => {
jest.clearAllMocks();
});

it('should not migrate project when validation fails', async () => {
// add project with no root
const project = addProject('lib1', {} as any);
const migrator = new LibMigrator(tree, {}, project);

await migrator.migrate();

expect(tree.exists('libs/lib1/project.json')).toBe(false);
const { projects } = readJson(tree, 'angular.json');
expect(projects.lib1).toBeDefined();
});

describe('validation', () => {
it('should fail validation when the project root is not specified', async () => {
const project = addProject('lib1', {} as any);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ export class LibMigrator extends ProjectMigrator {
}

override async migrate(): Promise<void> {
await super.migrate();

if (this.skipMigration === true) {
return;
}

await super.migrate();

await this.updateProjectConfiguration();
this.moveProjectFiles();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as chalk from 'chalk';
import chalk = require('chalk');
import {
arrayToString,
getProjectValidationResultMessage,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as chalk from 'chalk';
import chalk = require('chalk');
import type { ValidationError } from './types';

export function arrayToString(array: string[]): string {
Expand Down

0 comments on commit 589ab2f

Please sign in to comment.