-
-
Notifications
You must be signed in to change notification settings - Fork 18
feat(npm): Add workspaces support #645
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1697123
feat(npm): Add workspaces support
BYK 657eef6
refactor
BYK 88d3667
break circular dep
BYK b99f30d
Merge branch 'master' into byk/feat/npm-workspaces
BYK 4807ec1
add dependency ordering
BYK 9142e34
Merge branch 'master' into byk/feat/npm-workspaces
BYK ff18486
some optimizations
BYK 71ee027
moar optimizations
BYK ef4f7db
fix targets command
BYK 5080dc6
send all logs to stderr to keep stdout pure, especially when we outpu…
BYK 3f2df2d
review comments
BYK 22d988e
fix misleading message
BYK 334803d
fix seer error
BYK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,117 @@ | ||
| import { handler } from '../targets'; | ||
|
|
||
| jest.mock('../../config', () => ({ | ||
| getConfiguration: jest.fn(), | ||
| expandWorkspaceTargets: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('../../targets', () => ({ | ||
| getAllTargetNames: jest.fn(), | ||
| })); | ||
|
|
||
| import { getConfiguration, expandWorkspaceTargets } from '../../config'; | ||
| import { getAllTargetNames } from '../../targets'; | ||
|
|
||
| describe('targets command', () => { | ||
| const mockedGetConfiguration = getConfiguration as jest.Mock; | ||
| const mockedExpandWorkspaceTargets = expandWorkspaceTargets as jest.Mock; | ||
| const mockedGetAllTargetNames = getAllTargetNames as jest.Mock; | ||
| let consoleSpy: jest.SpyInstance; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| consoleSpy = jest.spyOn(console, 'log').mockImplementation(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| consoleSpy.mockRestore(); | ||
| }); | ||
|
|
||
| test('lists targets without expansion when no workspaces', async () => { | ||
| const targets = [ | ||
| { name: 'npm' }, | ||
| { name: 'github' }, | ||
| ]; | ||
|
|
||
| mockedGetConfiguration.mockReturnValue({ targets }); | ||
| mockedExpandWorkspaceTargets.mockResolvedValue(targets); | ||
| mockedGetAllTargetNames.mockReturnValue(['npm', 'github', 'pypi']); | ||
|
|
||
| await handler(); | ||
|
|
||
| expect(mockedExpandWorkspaceTargets).toHaveBeenCalledWith(targets); | ||
| expect(consoleSpy).toHaveBeenCalled(); | ||
| const output = JSON.parse(consoleSpy.mock.calls[0][0]); | ||
| expect(output).toEqual(['npm', 'github']); | ||
| }); | ||
|
|
||
| test('lists expanded workspace targets', async () => { | ||
| const originalTargets = [ | ||
| { name: 'npm', workspaces: true }, | ||
| { name: 'github' }, | ||
| ]; | ||
|
|
||
| const expandedTargets = [ | ||
| { name: 'npm', id: '@sentry/core' }, | ||
| { name: 'npm', id: '@sentry/browser' }, | ||
| { name: 'github' }, | ||
| ]; | ||
|
|
||
| mockedGetConfiguration.mockReturnValue({ targets: originalTargets }); | ||
| mockedExpandWorkspaceTargets.mockResolvedValue(expandedTargets); | ||
| mockedGetAllTargetNames.mockReturnValue(['npm', 'github']); | ||
|
|
||
| await handler(); | ||
|
|
||
| expect(mockedExpandWorkspaceTargets).toHaveBeenCalledWith(originalTargets); | ||
| expect(consoleSpy).toHaveBeenCalled(); | ||
| const output = JSON.parse(consoleSpy.mock.calls[0][0]); | ||
| expect(output).toEqual([ | ||
| 'npm[@sentry/core]', | ||
| 'npm[@sentry/browser]', | ||
| 'github', | ||
| ]); | ||
| }); | ||
|
|
||
| test('filters out unknown target names', async () => { | ||
| const targets = [ | ||
| { name: 'npm' }, | ||
| { name: 'unknown-target' }, | ||
| { name: 'github' }, | ||
| ]; | ||
|
|
||
| mockedGetConfiguration.mockReturnValue({ targets }); | ||
| mockedExpandWorkspaceTargets.mockResolvedValue(targets); | ||
| mockedGetAllTargetNames.mockReturnValue(['npm', 'github']); | ||
|
|
||
| await handler(); | ||
|
|
||
| expect(consoleSpy).toHaveBeenCalled(); | ||
| const output = JSON.parse(consoleSpy.mock.calls[0][0]); | ||
| expect(output).toEqual(['npm', 'github']); | ||
| }); | ||
|
|
||
| test('handles empty targets list', async () => { | ||
| mockedGetConfiguration.mockReturnValue({ targets: [] }); | ||
| mockedExpandWorkspaceTargets.mockResolvedValue([]); | ||
| mockedGetAllTargetNames.mockReturnValue(['npm', 'github']); | ||
|
|
||
| await handler(); | ||
|
|
||
| expect(consoleSpy).toHaveBeenCalled(); | ||
| const output = JSON.parse(consoleSpy.mock.calls[0][0]); | ||
| expect(output).toEqual([]); | ||
| }); | ||
|
|
||
| test('handles undefined targets', async () => { | ||
| mockedGetConfiguration.mockReturnValue({}); | ||
| mockedExpandWorkspaceTargets.mockResolvedValue([]); | ||
| mockedGetAllTargetNames.mockReturnValue(['npm', 'github']); | ||
|
|
||
| await handler(); | ||
|
|
||
| expect(consoleSpy).toHaveBeenCalled(); | ||
| const output = JSON.parse(consoleSpy.mock.calls[0][0]); | ||
| expect(output).toEqual([]); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.