From e5a2e62a75666351fb27d1c953efa76f65963940 Mon Sep 17 00:00:00 2001 From: OJ Kwon <1210596+kwonoj@users.noreply.github.com> Date: Thu, 28 May 2026 13:38:30 -0700 Subject: [PATCH] fix(csf): propagate skip tags to .test children --- .../vitest-plugin/transformer.test.ts | 113 ++++++++++++++++++ .../csf-tools/vitest-plugin/transformer.ts | 2 +- 2 files changed, 114 insertions(+), 1 deletion(-) diff --git a/code/core/src/csf-tools/vitest-plugin/transformer.test.ts b/code/core/src/csf-tools/vitest-plugin/transformer.test.ts index 7d27cc5a1dc8..bb62bd3b27bd 100644 --- a/code/core/src/csf-tools/vitest-plugin/transformer.test.ts +++ b/code/core/src/csf-tools/vitest-plugin/transformer.test.ts @@ -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', () => { @@ -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', () => { diff --git a/code/core/src/csf-tools/vitest-plugin/transformer.ts b/code/core/src/csf-tools/vitest-plugin/transformer.ts index c3a0a1a204e3..4fc8332b532e 100644 --- a/code/core/src/csf-tools/vitest-plugin/transformer.ts +++ b/code/core/src/csf-tools/vitest-plugin/transformer.ts @@ -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)), ];