Skip to content

Commit

Permalink
refactor(transformCsf): Simplify makePlayTest function and remove unn…
Browse files Browse the repository at this point in the history
…ecessary conditional

The makePlayTest function in the transformCsf file has been simplified to remove an unnecessary conditional statement. The metaOrStoryPlay parameter is now optional, indicated by the use of the "?" symbol. This change was made to improve code readability and reduce complexity.
  • Loading branch information
bryanjtc committed Nov 16, 2023
1 parent 1e3e564 commit de631e4
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/csf/transformCsf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const makePlayTest = ({
}: {
key: string;
title: string;
metaOrStoryPlay: t.Node;
metaOrStoryPlay?: t.Node;
testPrefix?: TestPrefixer;
shouldSkip?: boolean;
}): t.Statement[] => {
Expand Down Expand Up @@ -147,22 +147,17 @@ export const transformCsf = (
.map((key: string) => {
let tests: t.Statement[] = [];
const shouldSkip = skipTags.some((tag) => storyAnnotations[key].tags?.includes(tag));
const playFunctions = storyAnnotations[key]?.play;
if (title) {
tests = [
...tests,
...(playFunctions !== undefined
? [
makePlayTest({
key,
title,
metaOrStoryPlay: playFunctions,
testPrefix: testPrefixer,
shouldSkip,
}),
]
: []),
].flat();
...makePlayTest({
key,
title,
metaOrStoryPlay: storyAnnotations[key]?.play,
testPrefix: testPrefixer,
shouldSkip,
}),
];
}

if (tests.length) {
Expand Down

0 comments on commit de631e4

Please sign in to comment.