Skip to content

Commit 125bdd3

Browse files
authored
Merge pull request storybookjs#30193 from storybookjs/yann/addon-test-postinstall-msw-fix
Addon Test: Add prerequisite check for MSW
2 parents 77c0a57 + 987d698 commit 125bdd3

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

code/addons/test/src/postinstall.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ export default async function postInstall(options: PostinstallOptions) {
145145
`);
146146
}
147147

148+
const mswVersionSpecifier = await packageManager.getInstalledVersion('msw');
149+
const coercedMswVersion = mswVersionSpecifier ? coerce(mswVersionSpecifier) : null;
150+
151+
if (coercedMswVersion && !satisfies(coercedMswVersion, '>=2.0.0')) {
152+
reasons.push(dedent`
153+
• 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.
154+
Please update the 'msw' package and try again.
155+
`);
156+
}
157+
148158
if (info.frameworkPackageName === '@storybook/nextjs') {
149159
const nextVersion = await packageManager.getInstalledVersion('next');
150160
if (!nextVersion) {
@@ -159,6 +169,7 @@ export default async function postInstall(options: PostinstallOptions) {
159169
reasons.unshift(
160170
`Storybook Test's automated setup failed due to the following package incompatibilities:`
161171
);
172+
reasons.push('--------------------------------');
162173
reasons.push(
163174
dedent`
164175
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

code/lib/cli-storybook/src/add.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,19 @@ export async function add(
111111

112112
let shouldAddToMain = true;
113113
if (checkInstalled(addonName, requireMain(configDir))) {
114-
const { shouldForceInstall } = await prompts({
115-
type: 'confirm',
116-
name: 'shouldForceInstall',
117-
message: `The Storybook addon "${addonName}" is already present in ${mainConfig}. Do you wish to install it again?`,
118-
});
119-
120-
if (!shouldForceInstall) {
121-
return;
122-
}
123-
124114
shouldAddToMain = false;
115+
if (!yes) {
116+
logger.log(`The Storybook addon "${addonName}" is already present in ${mainConfig}.`);
117+
const { shouldForceInstall } = await prompts({
118+
type: 'confirm',
119+
name: 'shouldForceInstall',
120+
message: `Do you wish to install it again?`,
121+
});
122+
123+
if (!shouldForceInstall) {
124+
return;
125+
}
126+
}
125127
}
126128

127129
const main = await readConfig(mainConfig);

0 commit comments

Comments
 (0)