Skip to content

Commit

Permalink
Merge pull request #419 from storybookjs/feat/support-meta-id
Browse files Browse the repository at this point in the history
Support stories with meta id for permalinking
  • Loading branch information
yannbf authored Dec 22, 2023
2 parents 6624c5e + 49762ec commit bb536d6
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/csf/transformCsf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,23 @@ export interface TransformOptions {
skipTags?: string[];
}

export const prefixFunction = (key: string, title: string, testPrefixer: TestPrefixer) => {
export const prefixFunction = ({
key,
testPrefixer,
title,
id,
}: {
key: string;
title: string;
testPrefixer: TestPrefixer;
id?: string;
}) => {
const name = storyNameFromExport(key);
const context: TestContext = {
storyExport: t.identifier(key),
name: t.stringLiteral(name), // FIXME .name annotation
title: t.stringLiteral(title),
id: t.stringLiteral(toId(title, name)),
id: t.stringLiteral(toId(id ?? title, name)),
};

const result = makeArray(testPrefixer(context));
Expand All @@ -46,11 +56,13 @@ const makePlayTest = ({
key,
metaOrStoryPlay,
title,
id,
testPrefix,
shouldSkip,
}: {
key: string;
title: string;
id?: string;
metaOrStoryPlay?: boolean;
testPrefix: TestPrefixer;
shouldSkip?: boolean;
Expand All @@ -59,7 +71,7 @@ const makePlayTest = ({
t.expressionStatement(
t.callExpression(shouldSkip ? t.identifier('it.skip') : t.identifier('it'), [
t.stringLiteral(metaOrStoryPlay ? 'play-test' : 'smoke-test'),
prefixFunction(key, title, testPrefix),
prefixFunction({ key, title, testPrefixer: testPrefix, id }),
])
),
];
Expand Down Expand Up @@ -141,6 +153,7 @@ export const transformCsf = (
...makePlayTest({
key,
title,
id: csf.meta.id,
metaOrStoryPlay: !!storyAnnotations[key]?.play,
testPrefix: testPrefixer,
shouldSkip,
Expand Down

0 comments on commit bb536d6

Please sign in to comment.