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
113 changes: 113 additions & 0 deletions code/core/src/csf-tools/vitest-plugin/transformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,62 @@ describe('transformer', () => {
}
`);
});

it('should pass skip tags to child .test() calls using tags.skip', async () => {
const code = `
export default {};
export const Primary = {};
Primary.test("runs", () => {});
Primary.test("skipped", { tags: ['skip-me'] }, () => {});
`;

const result = await transform({
code,
tagsFilter: { include: [Tag.TEST], exclude: [], skip: ['skip-me'] },
});

expect(result.code).toMatchInlineSnapshot(`
import { test as _test, expect as _expect, describe as _describe } from "vitest";
import { testStory as _testStory, convertToFilePath } from "@storybook/addon-vitest/internal/test-utils";
const _meta = {
title: "automatic/calculated/title"
};
export default _meta;
export const Primary = {};
Primary.test("runs", () => {});
Primary.test("skipped", {
tags: ['skip-me']
}, () => {});
const _isRunningFromThisFile = convertToFilePath(import.meta.url).includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath);
if (_isRunningFromThisFile) {
_describe("Primary ", () => {
_test("base story", _testStory({
exportName: "Primary",
story: Primary,
meta: _meta,
skipTags: ["skip-me"],
storyId: "automatic-calculated-title--primary"
}));
_test("runs", _testStory({
exportName: "Primary",
story: Primary,
meta: _meta,
skipTags: ["skip-me"],
storyId: "automatic-calculated-title--primary:runs",
testName: "runs"
}));
_test("skipped", _testStory({
exportName: "Primary",
story: Primary,
meta: _meta,
skipTags: ["skip-me"],
storyId: "automatic-calculated-title--primary:skipped",
testName: "skipped"
}));
});
}
`);
});
});

describe('component info extraction', () => {
Expand Down Expand Up @@ -1187,6 +1243,63 @@ describe('transformer', () => {
}
`);
});

it('should pass skip tags to child .test() calls using tags.skip', async () => {
const code = `
import { config } from '#.storybook/preview';
const meta = config.meta({});
export const Primary = meta.story({});
Primary.test("runs", () => {});
Primary.test("skipped", { tags: ['skip-me'] }, () => {});
`;

const result = await transform({
code,
tagsFilter: { include: [Tag.TEST], exclude: [], skip: ['skip-me'] },
});

expect(result.code).toMatchInlineSnapshot(`
import { test as _test, expect as _expect, describe as _describe } from "vitest";
import { testStory as _testStory, convertToFilePath } from "@storybook/addon-vitest/internal/test-utils";
import { config } from '#.storybook/preview';
const meta = config.meta({
title: "automatic/calculated/title"
});
export const Primary = meta.story({});
Primary.test("runs", () => {});
Primary.test("skipped", {
tags: ['skip-me']
}, () => {});
const _isRunningFromThisFile = convertToFilePath(import.meta.url).includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath);
if (_isRunningFromThisFile) {
_describe("Primary ", () => {
_test("base story", _testStory({
exportName: "Primary",
story: Primary,
meta: meta,
skipTags: ["skip-me"],
storyId: "automatic-calculated-title--primary"
}));
_test("runs", _testStory({
exportName: "Primary",
story: Primary,
meta: meta,
skipTags: ["skip-me"],
storyId: "automatic-calculated-title--primary:runs",
testName: "runs"
}));
_test("skipped", _testStory({
exportName: "Primary",
story: Primary,
meta: meta,
skipTags: ["skip-me"],
storyId: "automatic-calculated-title--primary:skipped",
testName: "skipped"
}));
});
}
`);
});
});

describe('source map calculation', () => {
Expand Down
2 changes: 1 addition & 1 deletion code/core/src/csf-tools/vitest-plugin/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export async function vitestTransform({
t.objectProperty(t.identifier('exportName'), t.stringLiteral(exportName)),
t.objectProperty(t.identifier('story'), t.identifier(localName)),
t.objectProperty(t.identifier('meta'), t.identifier(metaExportName)),
t.objectProperty(t.identifier('skipTags'), t.arrayExpression([])),
t.objectProperty(t.identifier('skipTags'), skipTagsId),
t.objectProperty(t.identifier('storyId'), t.stringLiteral(storyId)),
];

Expand Down
Loading