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
36 changes: 27 additions & 9 deletions code/addons/vitest/src/vitest-plugin/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,25 @@ export const convertToFilePath = (url: string): string => {
return normalizedPath.replace(/%20/g, ' ');
};

export const testStory = (
exportName: string,
story: ComposedStoryFn | Story<Renderer>,
meta: ComponentAnnotations | Meta<Renderer>,
skipTags: string[],
storyId: string,
testName?: string
) => {
export const testStory = ({
exportName,
story,
meta,
skipTags,
storyId,
componentPath,
testName,
componentName,
}: {
exportName: string;
story: ComposedStoryFn | Story<Renderer>;
meta: ComponentAnnotations | Meta<Renderer>;
skipTags: string[];
storyId: string;
componentPath?: string;
testName?: string;
componentName?: string;
}) => {
return async (context: TestContext & { story: ComposedStoryFn }) => {
const annotations = getCsfFactoryAnnotations(story, meta);

Expand All @@ -64,12 +75,19 @@ export const testStory = (
context.story = composedStory;

const _task = context.task as RunnerTask & {
meta: TaskMeta & { storyId: string; reports: Report[] };
meta: TaskMeta & {
storyId: string;
reports: Report[];
componentPath?: string;
componentName?: string;
};
};

// The id will always be present, calculated by CsfFile
// and is needed so that we can add the test to the story in Storybook's UI for the status
_task.meta.storyId = storyId;
_task.meta.componentPath = componentPath;
_task.meta.componentName = componentName;

await setViewport(composedStory.parameters, composedStory.globals);

Expand Down
Loading