-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25553 from storybookjs/cli-versioned-upgrade
CLI: Versioned upgrade of monorepo packages
- Loading branch information
Showing
11 changed files
with
156 additions
and
195 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
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.