-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(angular): remove deprecated simpleModuleName option from library…
… generator (#16219)
- Loading branch information
1 parent
c4d9a5b
commit c8a2f50
Showing
7 changed files
with
349 additions
and
18 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
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
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
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
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
277 changes: 277 additions & 0 deletions
277
...r/src/migrations/update-16-0-0/remove-library-generator-simple-module-name-option.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,277 @@ | ||
import type { Tree } from '@nrwl/devkit'; | ||
import { | ||
addProjectConfiguration, | ||
readNxJson, | ||
readProjectConfiguration, | ||
updateNxJson, | ||
} from '@nrwl/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
import removeLibraryGeneratorSimpleModuleNameOption from './remove-library-generator-simple-module-name-option'; | ||
|
||
describe('removeLibraryGeneratorSimpleModuleNameOption', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
describe('nx.json', () => { | ||
it('should replace simpleModuleName with simpleName', async () => { | ||
const nxJson = readNxJson(tree); | ||
updateNxJson(tree, { | ||
...nxJson, | ||
generators: { | ||
'@nrwl/angular:library': { | ||
simpleModuleName: true, | ||
}, | ||
}, | ||
}); | ||
|
||
await removeLibraryGeneratorSimpleModuleNameOption(tree); | ||
|
||
const updatedNxJson = readNxJson(tree); | ||
expect(updatedNxJson.generators['@nrwl/angular:library']).toStrictEqual({ | ||
simpleName: true, | ||
}); | ||
}); | ||
|
||
it('should support nested library generator default', async () => { | ||
const nxJson = readNxJson(tree); | ||
updateNxJson(tree, { | ||
...nxJson, | ||
generators: { | ||
'@nrwl/angular': { | ||
library: { | ||
simpleModuleName: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
await removeLibraryGeneratorSimpleModuleNameOption(tree); | ||
|
||
const updatedNxJson = readNxJson(tree); | ||
expect(updatedNxJson.generators['@nrwl/angular']).toStrictEqual({ | ||
library: { | ||
simpleName: true, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should keep simpleName if defined and remove simpleModuleName', async () => { | ||
const nxJson = readNxJson(tree); | ||
updateNxJson(tree, { | ||
...nxJson, | ||
generators: { | ||
'@nrwl/angular:library': { | ||
simpleModuleName: true, | ||
simpleName: false, | ||
}, | ||
}, | ||
}); | ||
|
||
await removeLibraryGeneratorSimpleModuleNameOption(tree); | ||
|
||
const updatedNxJson = readNxJson(tree); | ||
expect(updatedNxJson.generators['@nrwl/angular:library']).toStrictEqual({ | ||
simpleName: false, | ||
}); | ||
}); | ||
|
||
it('should do nothing if simpleModuleName is not set', async () => { | ||
const nxJson = readNxJson(tree); | ||
updateNxJson(tree, { | ||
...nxJson, | ||
generators: { | ||
'@nrwl/angular:library': { | ||
simpleName: true, | ||
}, | ||
}, | ||
}); | ||
|
||
await removeLibraryGeneratorSimpleModuleNameOption(tree); | ||
|
||
const updatedNxJson = readNxJson(tree); | ||
expect(updatedNxJson.generators['@nrwl/angular:library']).toStrictEqual({ | ||
simpleName: true, | ||
}); | ||
}); | ||
|
||
it('should not throw when library generator defaults are not set', async () => { | ||
const nxJson = readNxJson(tree); | ||
updateNxJson(tree, { | ||
...nxJson, | ||
generators: { | ||
'@nrwl/angular:component': { | ||
standalone: true, | ||
}, | ||
}, | ||
}); | ||
|
||
await expect( | ||
removeLibraryGeneratorSimpleModuleNameOption(tree) | ||
).resolves.not.toThrow(); | ||
|
||
const updatedNxJson = readNxJson(tree); | ||
expect(updatedNxJson.generators).toStrictEqual({ | ||
'@nrwl/angular:component': { | ||
standalone: true, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should not throw when generators defaults are not set', async () => { | ||
const nxJson = readNxJson(tree); | ||
updateNxJson(tree, { ...nxJson, generators: undefined }); | ||
|
||
await expect( | ||
removeLibraryGeneratorSimpleModuleNameOption(tree) | ||
).resolves.not.toThrow(); | ||
|
||
const updatedNxJson = readNxJson(tree); | ||
expect(updatedNxJson.generators).toBeUndefined(); | ||
}); | ||
|
||
it('should not throw when nx.json does not exist', async () => { | ||
tree.delete('nx.json'); | ||
|
||
await expect( | ||
removeLibraryGeneratorSimpleModuleNameOption(tree) | ||
).resolves.not.toThrow(); | ||
|
||
expect(tree.exists('nx.json')).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('project configs', () => { | ||
it('should replace simpleModuleName with simpleName', async () => { | ||
const project = { | ||
name: 'project', | ||
root: '/', | ||
targets: {}, | ||
generators: { | ||
'@nrwl/angular:library': { | ||
simpleModuleName: true, | ||
}, | ||
}, | ||
}; | ||
addProjectConfiguration(tree, 'project', project); | ||
|
||
await removeLibraryGeneratorSimpleModuleNameOption(tree); | ||
|
||
const updatedProject = readProjectConfiguration(tree, 'project'); | ||
expect(updatedProject.generators['@nrwl/angular:library']).toStrictEqual({ | ||
simpleName: true, | ||
}); | ||
}); | ||
|
||
it('should support nested library generator default', async () => { | ||
const project = { | ||
name: 'project', | ||
root: '/', | ||
targets: {}, | ||
generators: { | ||
'@nrwl/angular': { | ||
library: { | ||
simpleModuleName: true, | ||
}, | ||
}, | ||
}, | ||
}; | ||
addProjectConfiguration(tree, 'project', project); | ||
|
||
await removeLibraryGeneratorSimpleModuleNameOption(tree); | ||
|
||
const updatedProject = readProjectConfiguration(tree, 'project'); | ||
expect(updatedProject.generators['@nrwl/angular']).toStrictEqual({ | ||
library: { | ||
simpleName: true, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should keep simpleName if defined and remove simpleModuleName', async () => { | ||
const project = { | ||
name: 'project', | ||
root: '/', | ||
targets: {}, | ||
generators: { | ||
'@nrwl/angular:library': { | ||
simpleModuleName: true, | ||
simpleName: false, | ||
}, | ||
}, | ||
}; | ||
addProjectConfiguration(tree, 'project', project); | ||
|
||
await removeLibraryGeneratorSimpleModuleNameOption(tree); | ||
|
||
const updatedProject = readProjectConfiguration(tree, 'project'); | ||
expect(updatedProject.generators['@nrwl/angular:library']).toStrictEqual({ | ||
simpleName: false, | ||
}); | ||
}); | ||
|
||
it('should do nothing if simpleModuleName is not set', async () => { | ||
const project = { | ||
name: 'project', | ||
root: '/', | ||
targets: {}, | ||
generators: { | ||
'@nrwl/angular:library': { | ||
simpleName: true, | ||
}, | ||
}, | ||
}; | ||
addProjectConfiguration(tree, 'project', project); | ||
|
||
await removeLibraryGeneratorSimpleModuleNameOption(tree); | ||
|
||
const updatedProject = readProjectConfiguration(tree, 'project'); | ||
expect(updatedProject.generators['@nrwl/angular:library']).toStrictEqual({ | ||
simpleName: true, | ||
}); | ||
}); | ||
|
||
it('should not throw when library generator defaults are not set', async () => { | ||
const project = { | ||
name: 'project', | ||
root: '/', | ||
targets: {}, | ||
generators: { | ||
'@nrwl/angular:component': { | ||
standalone: true, | ||
}, | ||
}, | ||
}; | ||
addProjectConfiguration(tree, 'project', project); | ||
|
||
await expect( | ||
removeLibraryGeneratorSimpleModuleNameOption(tree) | ||
).resolves.not.toThrow(); | ||
|
||
const updatedProject = readProjectConfiguration(tree, 'project'); | ||
expect(updatedProject.generators).toStrictEqual({ | ||
'@nrwl/angular:component': { | ||
standalone: true, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should not throw when generators defaults are not set', async () => { | ||
const project = { | ||
name: 'project', | ||
root: '/', | ||
targets: {}, | ||
}; | ||
addProjectConfiguration(tree, 'project', project); | ||
|
||
await expect( | ||
removeLibraryGeneratorSimpleModuleNameOption(tree) | ||
).resolves.not.toThrow(); | ||
|
||
const updatedProject = readProjectConfiguration(tree, 'project'); | ||
expect(updatedProject.generators).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.