Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions code/addons/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@
"vitest": "^4.1.6"
},
"peerDependencies": {
"@vitest/browser": "^3.0.0 || ^4.0.0",
"@vitest/browser-playwright": "^4.0.0",
"@vitest/runner": "^3.0.0 || ^4.0.0",
"@vitest/browser": "^3.0.0 || ^4.0.0 || ^5.0.0",
"@vitest/browser-playwright": "^4.0.0 || ^5.0.0",
"@vitest/runner": "^3.0.0 || ^4.0.0 || ^5.0.0",
"storybook": "workspace:^",
"vitest": "^3.0.0 || ^4.0.0"
"vitest": "^3.0.0 || ^4.0.0 || ^5.0.0"
},
"peerDependenciesMeta": {
"@vitest/browser": {
Expand Down
1 change: 1 addition & 0 deletions code/addons/vitest/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const STORYBOOK_TEST_PROVIDE_KEY = 'storybook/test-provided';
export const STORYBOOK_CORE_GHOST_STORIES_PROVIDE_KEY = 'storybook/core-ghost-stories';
export const STORYBOOK_CORE_RENDER_ANALYSIS_PROVIDE_KEY = 'storybook/core-render-analysis';
export const STORYBOOK_TEST_INITIAL_GLOBALS_PROVIDE_KEY = 'storybook/test-initial-globals';
export const STORYBOOK_TEST_FEATURES_PROVIDE_KEY = 'storybook/test-features';

// Channel event names for programmatic test triggering
export const TRIGGER_TEST_RUN_REQUEST = `${ADDON_ID}/trigger-test-run-request`;
Expand Down
2 changes: 2 additions & 0 deletions code/addons/vitest/src/vitest-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { withoutVitePlugins } from '../../../../builders/builder-vite/src/utils/
import {
STORYBOOK_CORE_GHOST_STORIES_PROVIDE_KEY,
STORYBOOK_CORE_RENDER_ANALYSIS_PROVIDE_KEY,
STORYBOOK_TEST_FEATURES_PROVIDE_KEY,
STORYBOOK_TEST_INITIAL_GLOBALS_PROVIDE_KEY,
} from '../constants.ts';
import type { InternalOptions, UserOptions } from './types.ts';
Expand Down Expand Up @@ -391,6 +392,7 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin[]> =>
},

provide: {
[STORYBOOK_TEST_FEATURES_PROVIDE_KEY]: features,
[STORYBOOK_CORE_GHOST_STORIES_PROVIDE_KEY]: !!process.env.STORYBOOK_COMPONENT_PATHS,
[STORYBOOK_CORE_RENDER_ANALYSIS_PROVIDE_KEY]:
!!process.env.STORYBOOK_COMPONENT_PATHS || withinAgenticSetupSession,
Expand Down
11 changes: 9 additions & 2 deletions code/addons/vitest/src/vitest-plugin/setup-file.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { afterEach, beforeAll, vi } from 'vitest';
import { afterEach, beforeAll, beforeEach, inject, vi } from 'vitest';
import type { RunnerTask } from 'vitest';

import { Channel } from 'storybook/internal/channels';
import { getChannel, setChannel } from 'storybook/internal/channels';

import { COMPONENT_TESTING_PANEL_ID } from '../constants.ts';
import { COMPONENT_TESTING_PANEL_ID, STORYBOOK_TEST_FEATURES_PROVIDE_KEY } from '../constants.ts';

// Vitest 5 replaces the Vite define without exposing it on the runtime global.
const features = inject(STORYBOOK_TEST_FEATURES_PROVIDE_KEY);
if (features) {
vi.stubGlobal('FEATURES', features);
beforeEach(() => vi.stubGlobal('FEATURES', features));
}

declare global {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down
4 changes: 4 additions & 0 deletions code/addons/vitest/src/vitest-provided-context.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import 'vitest';

import type { StorybookConfigRaw } from 'storybook/internal/types';

import type {
STORYBOOK_CORE_GHOST_STORIES_PROVIDE_KEY,
STORYBOOK_CORE_RENDER_ANALYSIS_PROVIDE_KEY,
STORYBOOK_TEST_FEATURES_PROVIDE_KEY,
STORYBOOK_TEST_INITIAL_GLOBALS_PROVIDE_KEY,
STORYBOOK_TEST_PROVIDE_KEY,
} from './constants.ts';

declare module 'vitest' {
interface ProvidedContext {
[STORYBOOK_TEST_FEATURES_PROVIDE_KEY]: StorybookConfigRaw['features'];
[STORYBOOK_TEST_PROVIDE_KEY]: Record<string, unknown>;
[STORYBOOK_CORE_GHOST_STORIES_PROVIDE_KEY]: boolean;
[STORYBOOK_CORE_RENDER_ANALYSIS_PROVIDE_KEY]: boolean;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11168,11 +11168,11 @@ __metadata:
typescript: "npm:^6.0.3"
vitest: "npm:^4.1.6"
peerDependencies:
"@vitest/browser": ^3.0.0 || ^4.0.0
"@vitest/browser-playwright": ^4.0.0
"@vitest/runner": ^3.0.0 || ^4.0.0
"@vitest/browser": ^3.0.0 || ^4.0.0 || ^5.0.0
"@vitest/browser-playwright": ^4.0.0 || ^5.0.0
"@vitest/runner": ^3.0.0 || ^4.0.0 || ^5.0.0
storybook: "workspace:^"
vitest: ^3.0.0 || ^4.0.0
vitest: ^3.0.0 || ^4.0.0 || ^5.0.0
peerDependenciesMeta:
"@vitest/browser":
optional: true
Expand Down
Loading