Skip to content

Commit 98576ce

Browse files
committed
Addon Vitest: Add component info to task meta
1 parent badd420 commit 98576ce

File tree

3 files changed

+370
-57
lines changed

3 files changed

+370
-57
lines changed

code/addons/vitest/src/vitest-plugin/test-utils.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,25 @@ export const convertToFilePath = (url: string): string => {
3131
return normalizedPath.replace(/%20/g, ' ');
3232
};
3333

34-
export const testStory = (
35-
exportName: string,
36-
story: ComposedStoryFn | Story<Renderer>,
37-
meta: ComponentAnnotations | Meta<Renderer>,
38-
skipTags: string[],
39-
storyId: string,
40-
testName?: string
41-
) => {
34+
export const testStory = ({
35+
exportName,
36+
story,
37+
meta,
38+
skipTags,
39+
storyId,
40+
componentPath,
41+
testName,
42+
componentName,
43+
}: {
44+
exportName: string;
45+
story: ComposedStoryFn | Story<Renderer>;
46+
meta: ComponentAnnotations | Meta<Renderer>;
47+
skipTags: string[];
48+
storyId: string;
49+
componentPath?: string;
50+
testName?: string;
51+
componentName?: string;
52+
}) => {
4253
return async (context: TestContext & { story: ComposedStoryFn }) => {
4354
const annotations = getCsfFactoryAnnotations(story, meta);
4455

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

6677
const _task = context.task as RunnerTask & {
67-
meta: TaskMeta & { storyId: string; reports: Report[] };
78+
meta: TaskMeta & {
79+
storyId: string;
80+
reports: Report[];
81+
componentPath?: string;
82+
componentName?: string;
83+
};
6884
};
6985

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

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

0 commit comments

Comments
 (0)