Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon Test: Fix environment variable for Vitest Storybook integration #30054

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading