Skip to content

Commit 394b984

Browse files
committed
Adjust spec
1 parent 51fcb1b commit 394b984

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

code/lib/cli/src/upgrade.test.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { describe, it, expect, vi } from 'vitest';
1+
import { describe, expect, it, vi } from 'vitest';
22
import * as sbcc from '@storybook/core-common';
3-
import {
4-
UpgradeStorybookToLowerVersionError,
5-
UpgradeStorybookToSameVersionError,
6-
} from '@storybook/core-events/server-errors';
3+
import { UpgradeStorybookToLowerVersionError } from '@storybook/core-events/server-errors';
74
import { doUpgrade, getStorybookVersion } from './upgrade';
5+
import { logger } from '@storybook/node-logger';
86

97
const findInstallationsMock = vi.fn<string[], Promise<sbcc.InstallationMetadata | undefined>>();
108

@@ -16,6 +14,8 @@ vi.mock('@storybook/core-common', async (importOriginal) => {
1614
JsPackageManagerFactory: {
1715
getPackageManager: () => ({
1816
findInstallations: findInstallationsMock,
17+
latestVersion: async () => '8.0.0',
18+
retrievePackageJson: async () => {},
1919
getAllDependencies: async () => ({ storybook: '8.0.0' }),
2020
}),
2121
},
@@ -68,7 +68,7 @@ describe('Upgrade errors', () => {
6868
await expect(doUpgrade({} as any)).rejects.toThrowError(UpgradeStorybookToLowerVersionError);
6969
expect(findInstallationsMock).toHaveBeenCalledWith(Object.keys(sbcc.versions));
7070
});
71-
it('should throw an error when upgrading to the same version number', async () => {
71+
it('should show a warning when upgrading to the same version number', async () => {
7272
findInstallationsMock.mockResolvedValue({
7373
dependencies: {
7474
'@storybook/cli': [
@@ -82,7 +82,15 @@ describe('Upgrade errors', () => {
8282
dedupeCommand: '',
8383
});
8484

85-
await expect(doUpgrade({} as any)).rejects.toThrowError(UpgradeStorybookToSameVersionError);
85+
// Mock as a throw, so that we don't have to mock the content of the doUpgrade fn that comes after it
86+
vi.spyOn(logger, 'warn').mockImplementation((error) => {
87+
// eslint-disable-next-line @typescript-eslint/no-throw-literal
88+
throw error;
89+
});
90+
91+
await expect(doUpgrade({ packageManager: 'npm' } as any)).rejects.toContain(
92+
'You are upgrading Storybook to the same version that is currently installed in the project'
93+
);
8694
expect(findInstallationsMock).toHaveBeenCalledWith(Object.keys(sbcc.versions));
8795
});
8896
});

0 commit comments

Comments
 (0)