Skip to content

Commit a743a22

Browse files
authored
ci: Storybook VRTのindex.json取得を待つ (#3038)
1 parent 16045c7 commit a743a22

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

tests/e2e/storybook/スクリーンショット.spec.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ type Theme = "light" | "dark";
3232
const toSnapshotFileName = (story: Story, theme: Theme) =>
3333
`${story.id}-${theme}.png`;
3434

35+
// fetchが成功するまで待つ。
36+
const fetchStorybookIndex = async (): Promise<Response> => {
37+
const timeoutAt = Date.now() + 30 * 1000;
38+
39+
while (true) {
40+
try {
41+
return await fetch("http://localhost:7357/index.json");
42+
} catch (e) {
43+
if (Date.now() >= timeoutAt) {
44+
throw e;
45+
}
46+
47+
await new Promise<void>((resolve) => setTimeout(resolve, 500));
48+
}
49+
}
50+
};
51+
3552
// テスト対象のStory一覧を取得する。
3653
// play-fnが付いているStoryはUnit Test用Storyとみなしてスクリーンショットを撮らない
3754
const getStoriesToTest = (index: StorybookIndex) =>
@@ -46,7 +63,7 @@ let index: StorybookIndex;
4663

4764
try {
4865
index = storybookIndexSchema.parse(
49-
await fetch("http://localhost:7357/index.json").then((res) => res.json()),
66+
await fetchStorybookIndex().then((res) => res.json()),
5067
);
5168
} catch (e) {
5269
throw new Error(`Storybookのindex.jsonの取得に失敗しました`, {

0 commit comments

Comments
 (0)