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
feat(schematics): list schematics from extended collections #2096
Open
xdissent
wants to merge
3
commits into
nestjs:master
Choose a base branch
from
xdissent:feat/list-extended-schematics
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { resolve } from 'path'; | ||
import { AbstractRunner } from '../../../lib/runners'; | ||
import { CustomCollection } from '../../../lib/schematics/custom.collection'; | ||
|
||
describe('Custom Collection', () => { | ||
it(`should list schematics from simple collection`, async () => { | ||
const mock = jest.fn(); | ||
mock.mockImplementation(() => { | ||
return { | ||
logger: {}, | ||
run: jest.fn().mockImplementation(() => Promise.resolve()), | ||
}; | ||
}); | ||
const mockedRunner = mock(); | ||
const collection = new CustomCollection( | ||
require.resolve('./fixtures/simple/collection.json'), | ||
mockedRunner as AbstractRunner, | ||
); | ||
const schematics = collection.getSchematics(); | ||
expect(schematics).toEqual([ | ||
{ name: 'simple1', alias: 's1', description: 'Simple schematic 1' }, | ||
{ name: 'simple2', alias: 's2', description: 'Simple schematic 2' }, | ||
{ name: 'simple3', alias: 's3', description: 'Simple schematic 3' }, | ||
]); | ||
}); | ||
|
||
it(`should list schematics from extended collection`, async () => { | ||
const mock = jest.fn(); | ||
mock.mockImplementation(() => { | ||
return { | ||
logger: {}, | ||
run: jest.fn().mockImplementation(() => Promise.resolve()), | ||
}; | ||
}); | ||
const mockedRunner = mock(); | ||
const collection = new CustomCollection( | ||
require.resolve('./fixtures/extended/collection.json'), | ||
mockedRunner as AbstractRunner, | ||
); | ||
const schematics = collection.getSchematics(); | ||
expect(schematics).toEqual([ | ||
{ name: 'extend1', alias: 'x1', description: 'Extended schematic 1' }, | ||
{ name: 'extend2', alias: 'x2', description: 'Extended schematic 2' }, | ||
{ name: 'simple1', alias: 's1', description: 'Override schematic 1' }, | ||
{ | ||
name: 'simple2', | ||
alias: 'os2', | ||
description: 'Override schematic 2', | ||
}, | ||
{ | ||
name: 'simple3', | ||
alias: 'simple3', | ||
description: 'Simple schematic 3', | ||
}, | ||
]); | ||
}); | ||
|
||
it(`should list schematics from package with collection.json path in package.json`, async () => { | ||
const mock = jest.fn(); | ||
mock.mockImplementation(() => { | ||
return { | ||
logger: {}, | ||
run: jest.fn().mockImplementation(() => Promise.resolve()), | ||
}; | ||
}); | ||
const mockedRunner = mock(); | ||
const collection = new CustomCollection( | ||
'package', | ||
mockedRunner as AbstractRunner, | ||
); | ||
const schematics = collection.getSchematics(); | ||
expect(schematics).toEqual([ | ||
{ name: 'package1', alias: 'pkg1', description: 'Package schematic 1' }, | ||
]); | ||
}); | ||
}); |
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,26 @@ | ||
{ | ||
"$schema": "../../../../../node_modules/@angular-devkit/schematics/collection-schema.json", | ||
"extends": ["../simple/collection.json"], | ||
"schematics": { | ||
"simple1": { | ||
"factory": "factory", | ||
"description": "Override schematic 1", | ||
"aliases": ["s1", "simp1"] | ||
}, | ||
"simple2": { | ||
"factory": "factory", | ||
"description": "Override schematic 2", | ||
"aliases": ["os2", "s2", "simp2"] | ||
}, | ||
"extend1": { | ||
"factory": "factory", | ||
"description": "Extended schematic 1", | ||
"aliases": ["x1", "ext1"] | ||
}, | ||
"extend2": { | ||
"factory": "factory", | ||
"description": "Extended schematic 2", | ||
"aliases": ["x2", "ext2", "s3", "simp3"] | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
test/lib/schematics/fixtures/package/a/b/c/collection.json
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,10 @@ | ||
{ | ||
"$schema": "../../../../../../../../node_modules/@angular-devkit/schematics/collection-schema.json", | ||
"schematics": { | ||
"package1": { | ||
"factory": "factory", | ||
"description": "Package schematic 1", | ||
"aliases": ["pkg1"] | ||
} | ||
} | ||
} |
Empty file.
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,5 @@ | ||
{ | ||
"name": "package", | ||
"version": "0.0.0", | ||
"schematics": "./a/b/c/collection.json" | ||
} |
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,20 @@ | ||
{ | ||
"$schema": "../../../../../node_modules/@angular-devkit/schematics/collection-schema.json", | ||
"schematics": { | ||
"simple1": { | ||
"factory": "factory", | ||
"description": "Simple schematic 1", | ||
"aliases": ["s1", "simp1"] | ||
}, | ||
"simple2": { | ||
"factory": "factory", | ||
"description": "Simple schematic 2", | ||
"aliases": ["s2", "simp2"] | ||
}, | ||
"simple3": { | ||
"factory": "factory", | ||
"description": "Simple schematic 3", | ||
"aliases": ["s3", "simp3"] | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit