-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
CLI: Versioned upgrade of monorepo packages #25553
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
03c2ffb
new upgrade flow
JReinhold 52cc5e1
add better messages and errors
JReinhold 9e716e2
test upgrade errors
JReinhold 00ca44c
cleanup
JReinhold 92c285b
Merge branch 'next' of github.com:storybookjs/storybook into cli-vers…
JReinhold dfa3e99
remove unused upgrade error
JReinhold e3a0ac4
Merge branch 'next' into cli-versioned-upgrade
JReinhold c592054
remove bad prerelease variable from telemetry
JReinhold cdccd47
fix automigrations and readmes
JReinhold 803fbc9
Merge branch 'cli-versioned-upgrade' of github.com:storybookjs/storyb…
JReinhold 49e2b62
update message matches new upgrade API
JReinhold 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 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
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 |
---|---|---|
@@ -1,5 +1,22 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { addExtraFlags, addNxPackagesToReject, getStorybookVersion } from './upgrade'; | ||
import { describe, it, expect, vi } from 'vitest'; | ||
import { getStorybookCoreVersion } from '@storybook/telemetry'; | ||
import { | ||
UpgradeStorybookToLowerVersionError, | ||
UpgradeStorybookToSameVersionError, | ||
} from '@storybook/core-events/server-errors'; | ||
import { doUpgrade, getStorybookVersion } from './upgrade'; | ||
import type versions from './versions'; | ||
|
||
vi.mock('@storybook/telemetry'); | ||
vi.mock('./versions', async (importOriginal) => { | ||
const originalVersions = ((await importOriginal()) as { default: typeof versions }).default; | ||
return { | ||
default: Object.keys(originalVersions).reduce((acc, key) => { | ||
acc[key] = '8.0.0'; | ||
return acc; | ||
}, {} as Record<string, string>), | ||
}; | ||
}); | ||
|
||
describe.each([ | ||
['│ │ │ ├── @babel/[email protected] deduped', null], | ||
|
@@ -22,68 +39,15 @@ describe.each([ | |
}); | ||
}); | ||
|
||
describe('extra flags', () => { | ||
const extraFlags = { | ||
'react-scripts@<5': ['--foo'], | ||
}; | ||
const devDependencies = {}; | ||
it('package matches constraints', () => { | ||
expect( | ||
addExtraFlags(extraFlags, [], { dependencies: { 'react-scripts': '4' }, devDependencies }) | ||
).toEqual(['--foo']); | ||
}); | ||
it('package prerelease matches constraints', () => { | ||
expect( | ||
addExtraFlags(extraFlags, [], { | ||
dependencies: { 'react-scripts': '4.0.0-alpha.0' }, | ||
devDependencies, | ||
}) | ||
).toEqual(['--foo']); | ||
}); | ||
it('package not matches constraints', () => { | ||
expect( | ||
addExtraFlags(extraFlags, [], { | ||
dependencies: { 'react-scripts': '5.0.0-alpha.0' }, | ||
devDependencies, | ||
}) | ||
).toEqual([]); | ||
}); | ||
it('no package not matches constraints', () => { | ||
expect( | ||
addExtraFlags(extraFlags, [], { | ||
dependencies: {}, | ||
devDependencies, | ||
}) | ||
).toEqual([]); | ||
}); | ||
}); | ||
describe('Upgrade errors', () => { | ||
it('should throw an error when upgrading to a lower version number', async () => { | ||
vi.mocked(getStorybookCoreVersion).mockResolvedValue('8.1.0'); | ||
|
||
describe('addNxPackagesToReject', () => { | ||
it('reject exists and is in regex pattern', () => { | ||
const flags = ['--reject', '/preset-create-react-app/', '--some-flag', 'hello']; | ||
expect(addNxPackagesToReject(flags)).toMatchObject([ | ||
'--reject', | ||
'"/(preset-create-react-app|@nrwl/storybook|@nx/storybook)/"', | ||
'--some-flag', | ||
'hello', | ||
]); | ||
await expect(doUpgrade({} as any)).rejects.toThrowError(UpgradeStorybookToLowerVersionError); | ||
}); | ||
it('reject exists and is in unknown pattern', () => { | ||
const flags = ['--some-flag', 'hello', '--reject', '@storybook/preset-create-react-app']; | ||
expect(addNxPackagesToReject(flags)).toMatchObject([ | ||
'--some-flag', | ||
'hello', | ||
'--reject', | ||
'@storybook/preset-create-react-app,@nrwl/storybook,@nx/storybook', | ||
]); | ||
}); | ||
it('reject does not exist', () => { | ||
const flags = ['--some-flag', 'hello']; | ||
expect(addNxPackagesToReject(flags)).toMatchObject([ | ||
'--some-flag', | ||
'hello', | ||
'--reject', | ||
'@nrwl/storybook,@nx/storybook', | ||
]); | ||
it('should throw an error when upgrading to the same version number', async () => { | ||
vi.mocked(getStorybookCoreVersion).mockResolvedValue('8.0.0'); | ||
|
||
await expect(doUpgrade({} as any)).rejects.toThrowError(UpgradeStorybookToSameVersionError); | ||
}); | ||
}); |
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.
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.
this adds a newline so that the package manager's install logs are not written to the same line