Skip to content

Commit 0422141

Browse files
committed
debug
1 parent aadadd2 commit 0422141

File tree

1 file changed

+38
-36
lines changed

1 file changed

+38
-36
lines changed

code/addons/vitest/src/postinstall.ts

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { readConfig, writeConfig } from 'storybook/internal/csf-tools';
1919
import { colors, logger } from 'storybook/internal/node-logger';
2020

2121
// eslint-disable-next-line depend/ban-dependencies
22-
import { $ } from 'execa';
22+
import { execa } from 'execa';
2323
import { findUp } from 'find-up';
2424
import { dirname, extname, join, relative, resolve } from 'pathe';
2525
import picocolors from 'picocolors';
@@ -330,41 +330,6 @@ export default async function postInstall(options: PostinstallOptions) {
330330
`
331331
);
332332

333-
const a11yAddon = info.addons.find((addon) => addon.includes(addonA11yName));
334-
335-
if (a11yAddon) {
336-
try {
337-
logger.plain(`${step} Setting up ${addonA11yName} for @storybook/addon-vitest:`);
338-
const command = ['storybook', 'automigrate', 'addonA11yAddonTest'];
339-
340-
if (options.yes) {
341-
command.push('--yes');
342-
}
343-
344-
if (options.packageManager) {
345-
command.push('--package-manager', options.packageManager);
346-
}
347-
348-
if (options.configDir) {
349-
command.push('--config-dir', options.configDir);
350-
}
351-
352-
await $({
353-
stdio: 'inherit',
354-
})`${command.join(' ')}`;
355-
} catch (e) {
356-
printError(
357-
'🚨 Oh no!',
358-
dedent`
359-
We have detected that you have ${addonA11yName} installed but could not automatically set it up for @storybook/addon-vitest.
360-
361-
Please refer to the documentation to complete the setup manually:
362-
${picocolors.cyan(`https://storybook.js.org/docs/writing-tests/accessibility-testing#test-addon-integration`)}
363-
`
364-
);
365-
}
366-
}
367-
368333
const vitestWorkspaceFile = await findFile('vitest.workspace', ['.ts', '.js', '.json']);
369334
const viteConfigFile = await findFile('vite.config');
370335
const vitestConfigFile = await findFile('vitest.config');
@@ -505,6 +470,43 @@ export default async function postInstall(options: PostinstallOptions) {
505470
await writeFile(newConfigFile, formattedContent);
506471
}
507472

473+
const a11yAddon = info.addons.find((addon) => addon.includes(addonA11yName));
474+
475+
if (a11yAddon) {
476+
try {
477+
logger.plain(`${step} Setting up ${addonA11yName} for @storybook/addon-vitest:`);
478+
const command = ['automigrate', 'addonA11yAddonTest'];
479+
480+
if (options.yes) {
481+
command.push('--yes');
482+
}
483+
484+
if (options.packageManager) {
485+
command.push('--package-manager', options.packageManager);
486+
}
487+
488+
if (options.configDir !== '.storybook') {
489+
command.push('--config-dir', options.configDir);
490+
}
491+
492+
await execa('storybook', command, {
493+
stdio: 'inherit',
494+
});
495+
} catch (e: unknown) {
496+
printError(
497+
'🚨 Oh no!',
498+
dedent`
499+
We have detected that you have ${addonA11yName} installed but could not automatically set it up for @storybook/addon-vitest:
500+
501+
${e instanceof Error ? e.message : String(e)}
502+
503+
Please refer to the documentation to complete the setup manually:
504+
${picocolors.cyan(`https://storybook.js.org/docs/writing-tests/accessibility-testing#test-addon-integration`)}
505+
`
506+
);
507+
}
508+
}
509+
508510
const runCommand = rootConfig ? `npx vitest --project=storybook` : `npx vitest`;
509511

510512
printSuccess(

0 commit comments

Comments
 (0)