File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,6 +32,23 @@ type Theme = "light" | "dark";
3232const 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とみなしてスクリーンショットを撮らない
3754const getStoriesToTest = ( index : StorybookIndex ) =>
@@ -46,7 +63,7 @@ let index: StorybookIndex;
4663
4764try {
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の取得に失敗しました` , {
You can’t perform that action at this time.
0 commit comments