Skip to content

Commit

Permalink
Change: toSnapshotFileNameに分ける
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Dec 3, 2024
1 parent 3f73fc7 commit 717f742
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/e2e/storybook/スクリーンショット.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const storybookIndexSchema = z.object({
});
type StorybookIndex = z.infer<typeof storybookIndexSchema>;
type Story = StorybookIndex["entries"][string];
type Theme = "light" | "dark";

const toSnapshotFileName = (story: Story, theme: Theme) =>
`${story.id}-${theme}.png`;

// テスト対象のStory一覧を取得する。
// play-fnが付いているStoryはUnit Test用Storyとみなしてスクリーンショットを撮らない
Expand Down Expand Up @@ -61,7 +65,7 @@ for (const [story, stories] of Object.entries(allStories)) {
for (const [theme, name] of [
["light", "ライト"],
["dark", "ダーク"],
]) {
] as const) {
test(`テーマ:${name}`, async ({ page }) => {
test.skip(
process.platform !== "win32",
Expand Down Expand Up @@ -97,7 +101,7 @@ for (const [story, stories] of Object.entries(allStories)) {
elementToScreenshot = root;
}
await expect(elementToScreenshot).toHaveScreenshot(
`${story.id}-${theme}.png`,
toSnapshotFileName(story, theme),
);
});
}
Expand All @@ -114,8 +118,8 @@ test("スクリーンショットの一覧に過不足が無い", async () => {
);

const expectedScreenshots = currentStories.flatMap((story) =>
["light", "dark"].map((theme) =>
test.info().snapshotPath(`${story.id}-${theme}.png`),
(["light", "dark"] as const).map((theme) =>
test.info().snapshotPath(toSnapshotFileName(story, theme)),
),
);

Expand Down

0 comments on commit 717f742

Please sign in to comment.