Skip to content

Commit

Permalink
Set environment variable for Vitest to indicate Storybook integration
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Dec 13, 2024
1 parent 2511d20 commit fb986dc
Showing 1 changed file with 14 additions and 25 deletions.
39 changes: 14 additions & 25 deletions code/addons/test/src/node/vitest-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(() => {
Expand Down

0 comments on commit fb986dc

Please sign in to comment.