@@ -15,204 +15,214 @@ const PORT = await getTestServerPort(packageJson.name)
1515const  EXTERNAL_HOST_PORT  =  await  getDummyServerPort ( packageJson . name ) 
1616
1717test . describe ( 'redirects' ,  ( )  =>  { 
18-   const  internalNavigationTestMatrix  =  combinate ( { 
19-     thrower : [ 'beforeLoad' ,  'loader' ]  as  const , 
20-     reloadDocument : [ false ,  true ]  as  const , 
21-     preload : [ false ,  true ]  as  const , 
22-   } ) 
18+   test . describe ( 'internal' ,  ( )  =>  { 
19+     const  internalNavigationTestMatrix  =  combinate ( { 
20+       thrower : [ 'beforeLoad' ,  'loader' ]  as  const , 
21+       reloadDocument : [ false ,  true ]  as  const , 
22+       preload : [ false ,  true ]  as  const , 
23+     } ) 
2324
24-   internalNavigationTestMatrix . forEach ( 
25-     ( {  thrower,  reloadDocument,  preload } )  =>  { 
26-       test ( `internal target, navigation: thrower: ${ thrower } ${ reloadDocument } ${ preload }  ,  async  ( { 
27-         page, 
28-       } )  =>  { 
29-         await  page . goto ( 
30-           `/redirect/internal${ preload  ===  false  ? '?preload=false'  : '' }  , 
31-         ) 
32-         const  link  =  page . getByTestId ( 
33-           `via-${ thrower } ${ reloadDocument  ? '-reloadDocument'  : '' }  , 
34-         ) 
25+      internalNavigationTestMatrix . forEach ( 
26+        ( {  thrower,  reloadDocument,  preload } )  =>  { 
27+          test ( `internal target, navigation: thrower: ${ thrower } ${ reloadDocument } ${ preload }  ,  async  ( { 
28+            page, 
29+          } )  =>  { 
30+            await  page . goto ( 
31+              `/redirect/internal${ preload  ===  false  ? '?preload=false'  : '' }  , 
32+            ) 
33+            const  link  =  page . getByTestId ( 
34+              `via-${ thrower } ${ reloadDocument  ? '-reloadDocument'  : '' }  , 
35+            ) 
3536
36-         await  page . waitForLoadState ( 'networkidle' ) 
37-         let  requestHappened  =  false 
38- 
39-         const  requestPromise  =  new  Promise < void > ( ( resolve )  =>  { 
40-           page . on ( 'request' ,  ( request )  =>  { 
41-             if  ( 
42-               request . url ( ) . startsWith ( `http://localhost:${ PORT }  ) 
43-             )  { 
44-               requestHappened  =  true 
45-               resolve ( ) 
46-             } 
37+           await  page . waitForLoadState ( 'networkidle' ) 
38+           let  requestHappened  =  false 
39+ 
40+           const  requestPromise  =  new  Promise < void > ( ( resolve )  =>  { 
41+             page . on ( 'request' ,  ( request )  =>  { 
42+               if  ( 
43+                 request . url ( ) . startsWith ( `http://localhost:${ PORT }  ) 
44+               )  { 
45+                 requestHappened  =  true 
46+                 resolve ( ) 
47+               } 
48+             } ) 
4749          } ) 
48-         } ) 
49-         await  link . focus ( ) 
50- 
51-         const  expectRequestHappened  =  preload  &&  ! reloadDocument 
52-         const  timeoutPromise  =  new  Promise ( ( resolve )  => 
53-           setTimeout ( resolve ,  expectRequestHappened  ? 5000  : 500 ) , 
54-         ) 
55-         await  Promise . race ( [ requestPromise ,  timeoutPromise ] ) 
56-         expect ( requestHappened ) . toBe ( expectRequestHappened ) 
57-         let  fullPageLoad  =  false 
58-         page . on ( 'domcontentloaded' ,  ( )  =>  { 
59-           fullPageLoad  =  true 
60-         } ) 
50+           await  link . focus ( ) 
6151
62-         await  link . click ( ) 
52+           const  expectRequestHappened  =  preload  &&  ! reloadDocument 
53+           const  timeoutPromise  =  new  Promise ( ( resolve )  => 
54+             setTimeout ( resolve ,  expectRequestHappened  ? 5000  : 500 ) , 
55+           ) 
56+           await  Promise . race ( [ requestPromise ,  timeoutPromise ] ) 
57+           expect ( requestHappened ) . toBe ( expectRequestHappened ) 
58+           let  fullPageLoad  =  false 
59+           page . on ( 'domcontentloaded' ,  ( )  =>  { 
60+             fullPageLoad  =  true 
61+           } ) 
6362
64-         const   url   =   `http://localhost: ${ PORT } /posts` 
63+            await   link . click ( ) 
6564
66-         await  page . waitForURL ( url ) 
67-         expect ( page . url ( ) ) . toBe ( url ) 
68-         await  expect ( page . getByTestId ( 'PostsIndexComponent' ) ) . toBeInViewport ( ) 
69-         expect ( fullPageLoad ) . toBe ( reloadDocument ) 
70-       } ) 
71-     } , 
72-   ) 
65+           const  url  =  `http://localhost:${ PORT }  
7366
74-   const  internalDirectVisitTestMatrix  =  combinate ( { 
75-     thrower : [ 'beforeLoad' ,  'loader' ]  as  const , 
76-     reloadDocument : [ false ,  true ]  as  const , 
77-   } ) 
67+           await  page . waitForURL ( url ) 
68+           expect ( page . url ( ) ) . toBe ( url ) 
69+           await  expect ( page . getByTestId ( 'PostsIndexComponent' ) ) . toBeInViewport ( ) 
70+           expect ( fullPageLoad ) . toBe ( reloadDocument ) 
71+         } ) 
72+       } , 
73+     ) 
7874
79-   internalDirectVisitTestMatrix . forEach ( ( {  thrower,  reloadDocument } )  =>  { 
80-     if  ( process . env . NODE_ENV  ===  'development' )  { 
81-       test . use ( { 
82-         whitelistErrors : [ 
83-           / A   t r e e   h y d r a t e d   b u t   s o m e   a t t r i b u t e s   o f   t h e   s e r v e r   r e n d e r e d   H T M L / , 
84-         ] , 
85-       } ) 
86-     } 
87-     test ( `internal target, direct visit: thrower: ${ thrower } ${ reloadDocument }  ,  async  ( { 
88-       page, 
89-     } )  =>  { 
90-       await  page . goto ( `/redirect/internal/via-${ thrower }  ) 
91-       await  page . waitForLoadState ( 'networkidle' ) 
92- 
93-       const  url  =  `http://localhost:${ PORT }  
94- 
95-       await  page . waitForURL ( url ) 
96-       expect ( page . url ( ) ) . toBe ( url ) 
97-       await  page . waitForLoadState ( 'networkidle' ) 
98-       await  expect ( page . getByTestId ( 'PostsIndexComponent' ) ) . toBeInViewport ( ) 
75+     const  internalDirectVisitTestMatrix  =  combinate ( { 
76+       thrower : [ 'beforeLoad' ,  'loader' ]  as  const , 
77+       reloadDocument : [ false ,  true ]  as  const , 
9978    } ) 
100-   } ) 
10179
102-   const  externalTestMatrix  =  combinate ( { 
103-     scenario : [ 'navigate' ,  'direct_visit' ]  as  const , 
104-     thrower : [ 'beforeLoad' ,  'loader' ]  as  const , 
105-   } ) 
106- 
107-   externalTestMatrix . forEach ( ( {  scenario,  thrower } )  =>  { 
108-     test ( `external target: scenario: ${ scenario } ${ thrower }  ,  async  ( { 
109-       page, 
110-     } )  =>  { 
111-       const  q  =  queryString . stringify ( { 
112-         externalHost : `http://localhost:${ EXTERNAL_HOST_PORT }  , 
113-       } ) 
114- 
115-       if  ( scenario  ===  'navigate' )  { 
116-         await  page . goto ( `/redirect/external?${ q }  ) 
117-         await  page . waitForLoadState ( 'networkidle' ) 
118-         const  link  =  page . getByTestId ( `via-${ thrower }  ) 
119-         await  link . focus ( ) 
120-         await  link . click ( ) 
121-       }  else  { 
122-         await  page . goto ( `/redirect/external/via-${ thrower } ${ q }  ) 
80+     internalDirectVisitTestMatrix . forEach ( ( {  thrower,  reloadDocument } )  =>  { 
81+       if  ( process . env . NODE_ENV  ===  'development' )  { 
82+         test . use ( { 
83+           whitelistErrors : [ 
84+             / A   t r e e   h y d r a t e d   b u t   s o m e   a t t r i b u t e s   o f   t h e   s e r v e r   r e n d e r e d   H T M L / , 
85+           ] , 
86+         } ) 
12387      } 
88+       test ( `internal target, direct visit: thrower: ${ thrower } ${ reloadDocument }  ,  async  ( { 
89+         page, 
90+       } )  =>  { 
91+         await  page . goto ( `/redirect/internal/via-${ thrower }  ) 
92+         await  page . waitForLoadState ( 'networkidle' ) 
12493
125-       const  url  =  `http://localhost:${ EXTERNAL_HOST_PORT } / ` 
94+          const  url  =  `http://localhost:${ PORT } /posts ` 
12695
127-       await  page . waitForURL ( url ) 
128-       expect ( page . url ( ) ) . toBe ( url ) 
96+         await  page . waitForURL ( url ) 
97+         expect ( page . url ( ) ) . toBe ( url ) 
98+         await  page . waitForLoadState ( 'networkidle' ) 
99+         await  expect ( page . getByTestId ( 'PostsIndexComponent' ) ) . toBeInViewport ( ) 
100+       } ) 
129101    } ) 
130102  } ) 
131103
132-   const  serverFnTestMatrix  =  combinate ( { 
133-     target : [ 'internal' ,  'external' ]  as  const , 
134-     scenario : [ 'navigate' ,  'direct_visit' ]  as  const , 
135-     thrower : [ 'beforeLoad' ,  'loader' ]  as  const , 
136-     reloadDocument : [ false ,  true ]  as  const , 
137-   } ) 
104+   test . describe ( 'external' ,  ( )  =>  { 
105+     const  externalTestMatrix  =  combinate ( { 
106+       scenario : [ 'navigate' ,  'direct_visit' ]  as  const , 
107+       thrower : [ 'beforeLoad' ,  'loader' ]  as  const , 
108+     } ) 
138109
139-   serverFnTestMatrix . forEach ( 
140-     ( {  target,  thrower,  scenario,  reloadDocument } )  =>  { 
141-       test ( `serverFn redirects to target: ${ target } ${ scenario } ${ thrower } ${ reloadDocument }  ,  async  ( { 
110+     externalTestMatrix . forEach ( ( {  scenario,  thrower } )  =>  { 
111+       test ( `external target: scenario: ${ scenario } ${ thrower }  ,  async  ( { 
142112        page, 
143113      } )  =>  { 
144-         let  fullPageLoad  =  false 
145114        const  q  =  queryString . stringify ( { 
146115          externalHost : `http://localhost:${ EXTERNAL_HOST_PORT }  , 
147-           reloadDocument, 
148116        } ) 
149117
150118        if  ( scenario  ===  'navigate' )  { 
151-           await  page . goto ( `/redirect/${ target } /serverFn ?${ q }  ) 
119+           await  page . goto ( `/redirect/external ?${ q }  ) 
152120          await  page . waitForLoadState ( 'networkidle' ) 
153-           const  link  =  page . getByTestId ( 
154-             `via-${ thrower } ${ reloadDocument  ? '-reloadDocument'  : '' }  , 
155-           ) 
156-           page . on ( 'domcontentloaded' ,  ( )  =>  { 
157-             fullPageLoad  =  true 
158-           } ) 
121+           const  link  =  page . getByTestId ( `via-${ thrower }  ) 
159122          await  link . focus ( ) 
160123          await  link . click ( ) 
161124        }  else  { 
162-           await  page . goto ( `/redirect/${ target } /serverFn /via-${ thrower } ${ q }  ) 
125+           await  page . goto ( `/redirect/external /via-${ thrower } ${ q }  ) 
163126        } 
164127
165-         const  url  = 
166-           target  ===  'internal' 
167-             ? `http://localhost:${ PORT }  
168-             : `http://localhost:${ EXTERNAL_HOST_PORT }  
128+         const  url  =  `http://localhost:${ EXTERNAL_HOST_PORT }  
129+ 
169130        await  page . waitForURL ( url ) 
170131        expect ( page . url ( ) ) . toBe ( url ) 
171-         if  ( target  ===  'internal'  &&  scenario  ===  'navigate' )  { 
172-           await  expect ( page . getByTestId ( 'PostsIndexComponent' ) ) . toBeInViewport ( ) 
173-           expect ( fullPageLoad ) . toBe ( reloadDocument ) 
174-         } 
175132      } ) 
176-     } , 
177-   ) 
133+     } ) 
134+   } ) 
135+ 
136+   test . describe ( 'serverFn' ,  ( )  =>  { 
137+     const  serverFnTestMatrix  =  combinate ( { 
138+       target : [ 'internal' ,  'external' ]  as  const , 
139+       scenario : [ 'navigate' ,  'direct_visit' ]  as  const , 
140+       thrower : [ 'beforeLoad' ,  'loader' ]  as  const , 
141+       reloadDocument : [ false ,  true ]  as  const , 
142+     } ) 
178143
179-   const  useServerFnTestMatrix  =  combinate ( { 
180-     target : [ 'internal' ,  'external' ]  as  const , 
181-     reloadDocument : [ false ,  true ]  as  const , 
144+     serverFnTestMatrix . forEach ( 
145+       ( {  target,  thrower,  scenario,  reloadDocument } )  =>  { 
146+         test ( `serverFn redirects to target: ${ target } ${ scenario } ${ thrower } ${ reloadDocument }  ,  async  ( { 
147+           page, 
148+         } )  =>  { 
149+           let  fullPageLoad  =  false 
150+           const  q  =  queryString . stringify ( { 
151+             externalHost : `http://localhost:${ EXTERNAL_HOST_PORT }  , 
152+             reloadDocument, 
153+           } ) 
154+ 
155+           if  ( scenario  ===  'navigate' )  { 
156+             await  page . goto ( `/redirect/${ target } ${ q }  ) 
157+             await  page . waitForLoadState ( 'networkidle' ) 
158+             const  link  =  page . getByTestId ( 
159+               `via-${ thrower } ${ reloadDocument  ? '-reloadDocument'  : '' }  , 
160+             ) 
161+             page . on ( 'domcontentloaded' ,  ( )  =>  { 
162+               fullPageLoad  =  true 
163+             } ) 
164+             await  link . focus ( ) 
165+             await  link . click ( ) 
166+           }  else  { 
167+             await  page . goto ( `/redirect/${ target } ${ thrower } ${ q }  ) 
168+           } 
169+ 
170+           const  url  = 
171+             target  ===  'internal' 
172+               ? `http://localhost:${ PORT }  
173+               : `http://localhost:${ EXTERNAL_HOST_PORT }  
174+           await  page . waitForURL ( url ) 
175+           expect ( page . url ( ) ) . toBe ( url ) 
176+           if  ( target  ===  'internal'  &&  scenario  ===  'navigate' )  { 
177+             await  expect ( 
178+               page . getByTestId ( 'PostsIndexComponent' ) , 
179+             ) . toBeInViewport ( ) 
180+             expect ( fullPageLoad ) . toBe ( reloadDocument ) 
181+           } 
182+         } ) 
183+       } , 
184+     ) 
182185  } ) 
183186
184-   useServerFnTestMatrix . forEach ( ( {  target,  reloadDocument } )  =>  { 
185-     test ( `useServerFn redirects to target: ${ target } ${ reloadDocument }  ,  async  ( { 
186-       page, 
187-     } )  =>  { 
188-       const  q  =  queryString . stringify ( { 
189-         externalHost : `http://localhost:${ EXTERNAL_HOST_PORT }  , 
190-         reloadDocument, 
191-       } ) 
187+   test . describe ( 'useServerFn' ,  ( )  =>  { 
188+     const  useServerFnTestMatrix  =  combinate ( { 
189+       target : [ 'internal' ,  'external' ]  as  const , 
190+       reloadDocument : [ false ,  true ]  as  const , 
191+     } ) 
192192
193-       await  page . goto ( `/redirect/${ target } ${ q }  ) 
193+     useServerFnTestMatrix . forEach ( ( {  target,  reloadDocument } )  =>  { 
194+       test ( `useServerFn redirects to target: ${ target } ${ reloadDocument }  ,  async  ( { 
195+         page, 
196+       } )  =>  { 
197+         const  q  =  queryString . stringify ( { 
198+           externalHost : `http://localhost:${ EXTERNAL_HOST_PORT }  , 
199+           reloadDocument, 
200+         } ) 
194201
195-       await  page . waitForLoadState ( 'networkidle' ) 
202+          await  page . goto ( `/redirect/ ${ target } /serverFn/via-useServerFn? ${ q } ` ) 
196203
197-       const   button   =  page . getByTestId ( 'redirect-on-click ') 
204+          await  page . waitForLoadState ( 'networkidle ') 
198205
199-       let  fullPageLoad  =  false 
200-       page . on ( 'domcontentloaded' ,  ( )  =>  { 
201-         fullPageLoad  =  true 
202-       } ) 
206+         const  button  =  page . getByTestId ( 'redirect-on-click' ) 
203207
204-       await  button . click ( ) 
208+         let  fullPageLoad  =  false 
209+         page . on ( 'domcontentloaded' ,  ( )  =>  { 
210+           fullPageLoad  =  true 
211+         } ) 
205212
206-       const  url  = 
207-         target  ===  'internal' 
208-           ? `http://localhost:${ PORT }  
209-           : `http://localhost:${ EXTERNAL_HOST_PORT }  
210-       await  page . waitForURL ( url ) 
211-       expect ( page . url ( ) ) . toBe ( url ) 
212-       if  ( target  ===  'internal' )  { 
213-         await  expect ( page . getByTestId ( 'PostsIndexComponent' ) ) . toBeInViewport ( ) 
214-         expect ( fullPageLoad ) . toBe ( reloadDocument ) 
215-       } 
213+         await  button . click ( ) 
214+ 
215+         const  url  = 
216+           target  ===  'internal' 
217+             ? `http://localhost:${ PORT }  
218+             : `http://localhost:${ EXTERNAL_HOST_PORT }  
219+         await  page . waitForURL ( url ) 
220+         expect ( page . url ( ) ) . toBe ( url ) 
221+         if  ( target  ===  'internal' )  { 
222+           await  expect ( page . getByTestId ( 'PostsIndexComponent' ) ) . toBeInViewport ( ) 
223+           expect ( fullPageLoad ) . toBe ( reloadDocument ) 
224+         } 
225+       } ) 
216226    } ) 
217227  } ) 
218228} ) 
0 commit comments