-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@schematics/angular): add migration to remove
skipTests
from `@…
- Loading branch information
1 parent
43926a2
commit 1080a52
Showing
3 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/schematics/angular/migrations/update-12/schematic-options.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { json } from '@angular-devkit/core'; | ||
import { Rule } from '@angular-devkit/schematics'; | ||
import { updateWorkspace } from '../../utility/workspace'; | ||
|
||
export default function (): Rule { | ||
return updateWorkspace((workspace) => { | ||
// Update root level schematics options if present | ||
const rootSchematics = workspace.extensions.schematics; | ||
if (rootSchematics && json.isJsonObject(rootSchematics)) { | ||
updateSchematicsField(rootSchematics); | ||
} | ||
|
||
// Update project level schematics options if present | ||
for (const [, project] of workspace.projects) { | ||
const projectSchematics = project.extensions.schematics; | ||
if (projectSchematics && json.isJsonObject(projectSchematics)) { | ||
updateSchematicsField(projectSchematics); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
function updateSchematicsField(schematics: json.JsonObject): void { | ||
for (const [schematicName, schematicOptions] of Object.entries(schematics)) { | ||
if (!json.isJsonObject(schematicOptions)) { | ||
continue; | ||
} | ||
|
||
if (schematicName === '@schematics/angular:module') { | ||
delete schematicOptions.skipTests; | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
packages/schematics/angular/migrations/update-12/schematic-options_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { EmptyTree } from '@angular-devkit/schematics'; | ||
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; | ||
|
||
describe('Migration to remove schematics old options in angular.json', () => { | ||
const workspacePath = '/angular.json'; | ||
const schematicName = 'schematic-options-12'; | ||
|
||
const schematicRunner = new SchematicTestRunner( | ||
'migrations', | ||
require.resolve('../migration-collection.json'), | ||
); | ||
|
||
let tree: UnitTestTree; | ||
|
||
beforeEach(async () => { | ||
tree = new UnitTestTree(new EmptyTree()); | ||
tree = await schematicRunner | ||
.runExternalSchematicAsync( | ||
require.resolve('../../collection.json'), | ||
'ng-new', | ||
{ | ||
name: 'migration-test', | ||
version: '1.2.3', | ||
directory: '.', | ||
}, | ||
tree, | ||
) | ||
.toPromise(); | ||
}); | ||
|
||
describe('schematic options', () => { | ||
it('should remove `skipTests` from `@schematics/angular:module`', async () => { | ||
const workspace = JSON.parse(tree.readContent(workspacePath)); | ||
workspace.schematics = { | ||
'@schematics/angular:module': { | ||
skipTests: true, | ||
}, | ||
}; | ||
tree.overwrite(workspacePath, JSON.stringify(workspace, undefined, 2)); | ||
|
||
const tree2 = await schematicRunner | ||
.runSchematicAsync(schematicName, {}, tree.branch()) | ||
.toPromise(); | ||
const { schematics } = JSON.parse(tree2.readContent(workspacePath)); | ||
expect(schematics['@schematics/angular:module'].skipTests).toBeUndefined(); | ||
}); | ||
|
||
it('should not remove `skipTests` from non `@schematics/angular:module` schematic', async () => { | ||
const workspace = JSON.parse(tree.readContent(workspacePath)); | ||
workspace.schematics = { | ||
'@schematics/angular:component': { | ||
skipTests: true, | ||
}, | ||
'@schematics/some-other:module': { | ||
skipTests: true, | ||
}, | ||
}; | ||
tree.overwrite(workspacePath, JSON.stringify(workspace, undefined, 2)); | ||
|
||
const tree2 = await schematicRunner | ||
.runSchematicAsync(schematicName, {}, tree.branch()) | ||
.toPromise(); | ||
const { schematics } = JSON.parse(tree2.readContent(workspacePath)); | ||
expect(schematics['@schematics/angular:component'].skipTests).toBeTrue(); | ||
expect(schematics['@schematics/some-other:module'].skipTests).toBeTrue(); | ||
}); | ||
}); | ||
}); |