From fb986dc5e4ae6c6c729b8069930e7914ab489081 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Fri, 13 Dec 2024 09:53:18 +0100 Subject: [PATCH] Set environment variable for Vitest to indicate Storybook integration --- code/addons/test/src/node/vitest-manager.ts | 39 ++++++++------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/code/addons/test/src/node/vitest-manager.ts b/code/addons/test/src/node/vitest-manager.ts index 10700b97f71b..d55d3bc6d5b1 100644 --- a/code/addons/test/src/node/vitest-manager.ts +++ b/code/addons/test/src/node/vitest-manager.ts @@ -31,6 +31,9 @@ type TagsFilter = { const packageDir = dirname(require.resolve('@storybook/experimental-addon-test/package.json')); +// We have to tell Vitest that it runs as part of Storybook +process.env.VITEST_STORYBOOK = 'true'; + export class VitestManager { vitest: Vitest | null = null; @@ -65,31 +68,17 @@ export class VitestManager { : { enabled: false } ) as CoverageOptions; - this.vitest = await createVitest( - 'test', - { - watch: true, - passWithNoTests: false, - // TODO: - // Do we want to enable Vite's default reporter? - // The output in the terminal might be too spamy and it might be better to - // find a way to just show errors and warnings for example - // Otherwise it might be hard for the user to discover Storybook related logs - reporters: ['default', new StorybookReporter(this.testManager)], - coverage: coverageOptions, - }, - { - define: { - // polyfilling process.env.VITEST_STORYBOOK to 'true' in the browser - 'process.env.VITEST_STORYBOOK': 'true', - }, - } - ); - - this.vitest.configOverride.env = { - // We signal to the test runner that we are running it via Storybook - VITEST_STORYBOOK: 'true', - }; + this.vitest = await createVitest('test', { + watch: true, + passWithNoTests: false, + // TODO: + // Do we want to enable Vite's default reporter? + // The output in the terminal might be too spamy and it might be better to + // find a way to just show errors and warnings for example + // Otherwise it might be hard for the user to discover Storybook related logs + reporters: ['default', new StorybookReporter(this.testManager)], + coverage: coverageOptions, + }); if (this.vitest) { this.vitest.onCancel(() => {