Skip to content
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: Fix skip-install for stable latest releases #29133

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions code/core/src/common/js-package-manager/JsPackageManager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';

import { JsPackageManager } from './JsPackageManager';

vi.mock('../versions', () => ({
default: {
'@storybook/react': '8.3.0',
},
}));

describe('JsPackageManager', () => {
let jsPackageManager: JsPackageManager;
let mockLatestVersion: ReturnType<typeof vi.fn>;
let mockStorybookPackagesVersions: Record<string, string>;

beforeEach(() => {
mockLatestVersion = vi.fn();
mockStorybookPackagesVersions = {
'@storybook/react': '8.3.0',
};

// @ts-expect-error Ignore abstract class error
jsPackageManager = new JsPackageManager();
jsPackageManager.latestVersion = mockLatestVersion;

vi.clearAllMocks();
});

describe('getVersionedPackages method', () => {
it('should return the latest stable release version when current version is the latest stable release', async () => {
mockLatestVersion.mockResolvedValue('8.3.0');

const result = await jsPackageManager.getVersionedPackages(['@storybook/react']);

expect(result).toEqual(['@storybook/react@^8.3.0']);
});

it('should return the current version when it is not the latest stable release', async () => {
mockLatestVersion.mockResolvedValue('8.3.1');

const result = await jsPackageManager.getVersionedPackages(['@storybook/react']);

expect(result).toEqual(['@storybook/[email protected]']);
});

it('should return the latest stable release version when there is no current version', async () => {
mockLatestVersion.mockResolvedValue('2.0.0');

const result = await jsPackageManager.getVersionedPackages(['@storybook/new-addon@^8.3.0']);
valentinpalkovic marked this conversation as resolved.
Show resolved Hide resolved

expect(result).toEqual(['@storybook/new-addon@^2.0.0']);
});
});
});
12 changes: 6 additions & 6 deletions code/core/src/common/js-package-manager/JsPackageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,13 @@ export abstract class JsPackageManager {
const k = packageName as keyof typeof storybookPackagesVersions;
const currentVersion = storybookPackagesVersions[k];

if (currentVersion === latestInRange) {
return `${packageName}`;
}
if (currentVersion) {
return `${packageName}@${currentVersion}`;
const isLatestStableRelease = currentVersion === latestInRange;

if (isLatestStableRelease || !currentVersion) {
return `${packageName}@^${latestInRange}`;
valentinpalkovic marked this conversation as resolved.
Show resolved Hide resolved
}
return `${packageName}@^${latestInRange}`;

return `${packageName}@${currentVersion}`;
})
);
}
Expand Down