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: Support Storybook environment variables in Vitest #29792

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions code/addons/test/src/vitest-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const storybookTest = (options?: UserOptions): Plugin => {

const framework = await presets.apply('framework', undefined);
const frameworkName = typeof framework === 'string' ? framework : framework.name;
const storybookEnv = await presets.apply('env', {});

// If we end up needing to know if we are running in browser mode later
// const isRunningInBrowserMode = config.plugins.find((plugin: Plugin) =>
Expand All @@ -96,6 +97,7 @@ export const storybookTest = (options?: UserOptions): Plugin => {

config.test.env ??= {};
config.test.env = {
...storybookEnv,
...config.test.env,
// To be accessed by the setup file
__STORYBOOK_URL__: storybookUrl,
Expand All @@ -104,6 +106,8 @@ export const storybookTest = (options?: UserOptions): Plugin => {
__VITEST_SKIP_TAGS__: finalOptions.tags.skip.join(','),
};

config.envPrefix = Array.from(new Set([...(config.envPrefix || []), 'STORYBOOK_', 'VITE_']));

if (config.test.browser) {
config.test.browser.screenshotFailures ??= false;
}
Expand Down
1 change: 1 addition & 0 deletions code/core/src/types/modules/core-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface Presets {
apply(extension: 'babel', config?: {}, args?: any): Promise<any>;
apply(extension: 'swc', config?: {}, args?: any): Promise<any>;
apply(extension: 'entries', config?: [], args?: any): Promise<unknown>;
apply(extension: 'env', config?: {}, args?: any): Promise<any>;
apply(extension: 'stories', config?: [], args?: any): Promise<StoriesEntry[]>;
apply(extension: 'managerEntries', config: [], args?: any): Promise<string[]>;
apply(extension: 'refs', config?: [], args?: any): Promise<StorybookConfigRaw['refs']>;
Expand Down
Loading