Skip to content

Commit

Permalink
Merge pull request #30193 from storybookjs/yann/addon-test-postinstal…
Browse files Browse the repository at this point in the history
…l-msw-fix

Addon Test: Add prerequisite check for MSW
  • Loading branch information
JReinhold authored Jan 8, 2025
2 parents 77c0a57 + 987d698 commit 125bdd3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
11 changes: 11 additions & 0 deletions code/addons/test/src/postinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ export default async function postInstall(options: PostinstallOptions) {
`);
}

const mswVersionSpecifier = await packageManager.getInstalledVersion('msw');
const coercedMswVersion = mswVersionSpecifier ? coerce(mswVersionSpecifier) : null;

if (coercedMswVersion && !satisfies(coercedMswVersion, '>=2.0.0')) {
reasons.push(dedent`
• The addon uses Vitest behind the scenes, which supports only version 2 and above of MSW. However, we have detected version ${picocolors.bold(coercedMswVersion.version)} in this project.
Please update the 'msw' package and try again.
`);
}

if (info.frameworkPackageName === '@storybook/nextjs') {
const nextVersion = await packageManager.getInstalledVersion('next');
if (!nextVersion) {
Expand All @@ -159,6 +169,7 @@ export default async function postInstall(options: PostinstallOptions) {
reasons.unshift(
`Storybook Test's automated setup failed due to the following package incompatibilities:`
);
reasons.push('--------------------------------');
reasons.push(
dedent`
You can fix these issues and rerun the command to reinstall. If you wish to roll back the installation, remove ${picocolors.bold(colors.pink(ADDON_NAME))} from the "addons" array
Expand Down
22 changes: 12 additions & 10 deletions code/lib/cli-storybook/src/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,19 @@ export async function add(

let shouldAddToMain = true;
if (checkInstalled(addonName, requireMain(configDir))) {
const { shouldForceInstall } = await prompts({
type: 'confirm',
name: 'shouldForceInstall',
message: `The Storybook addon "${addonName}" is already present in ${mainConfig}. Do you wish to install it again?`,
});

if (!shouldForceInstall) {
return;
}

shouldAddToMain = false;
if (!yes) {
logger.log(`The Storybook addon "${addonName}" is already present in ${mainConfig}.`);
const { shouldForceInstall } = await prompts({
type: 'confirm',
name: 'shouldForceInstall',
message: `Do you wish to install it again?`,
});

if (!shouldForceInstall) {
return;
}
}
}

const main = await readConfig(mainConfig);
Expand Down

0 comments on commit 125bdd3

Please sign in to comment.