@@ -109,45 +109,63 @@ export const action = (c) => c.json({ value: c.req.param(${JSON.stringify(name)}
109109 'about-title' ,
110110 ) ;
111111 } ) ;
112- it ( 'redirects to the page URL in dev and production and leaves API routes alone' , async ( ) => {
113- for ( const { base, mode } of servers ) {
114- const redirect = await fetch ( `${ base } /about?test=1` , { redirect : 'manual' } ) ;
115- expect ( [ 301 , 307 , 308 ] , mode ) . toContain ( redirect . status ) ;
116- expect ( new URL ( redirect . headers . get ( 'location' ) ! , base ) . href , mode ) . toBe (
117- `${ base } /about/?test=1` ,
118- ) ;
119- await redirect . text ( ) ;
120- const page = await fetch ( `${ base } /about/` ) ;
121- expect ( page . status ) . toBe ( 200 ) ;
122- expect ( await page . text ( ) ) . toContain ( 'about-title' ) ;
123- for ( const [ path , value ] of [
124- [ 'posts/hello' , 'hello' ] ,
125- [ 'files/guides/intro' , 'guides/intro' ] ,
126- ] ) {
127- const dynamicRedirect = await fetch ( `${ base } /${ path } ` , { redirect : 'manual' } ) ;
128- expect ( [ 301 , 307 , 308 ] , `${ mode } : ${ path } ` ) . toContain ( dynamicRedirect . status ) ;
129- await dynamicRedirect . text ( ) ;
130- const dynamicPage = await fetch ( `${ base } /${ path } /` ) ;
131- expect ( dynamicPage . status , `${ mode } : ${ path } ` ) . toBe ( 200 ) ;
132- expect ( await dynamicPage . text ( ) ) . toContain ( `<h1>${ value } </h1>` ) ;
112+ it . each ( [ 'GET' , 'HEAD' ] ) (
113+ 'redirects %s to the page URL and leaves API routes alone' ,
114+ async ( method ) => {
115+ for ( const { base, mode } of servers ) {
116+ const redirect = await fetch ( `${ base } /about?test=1` , { method, redirect : 'manual' } ) ;
117+ expect ( [ 301 , 307 , 308 ] , mode ) . toContain ( redirect . status ) ;
118+ expect ( new URL ( redirect . headers . get ( 'location' ) ! , base ) . href , mode ) . toBe (
119+ `${ base } /about/?test=1` ,
120+ ) ;
121+ await redirect . text ( ) ;
122+ const page = await fetch ( `${ base } /about/` , { method } ) ;
123+ expect ( page . status ) . toBe ( 200 ) ;
124+ const html = await page . text ( ) ;
125+ if ( method === 'HEAD' ) {
126+ expect ( html ) . toBe ( '' ) ;
127+ } else {
128+ expect ( html ) . toContain ( 'about-title' ) ;
129+ }
130+ for ( const [ path , value ] of [
131+ [ 'posts/hello' , 'hello' ] ,
132+ [ 'files/guides/intro' , 'guides/intro' ] ,
133+ ] ) {
134+ const dynamicRedirect = await fetch ( `${ base } /${ path } ` , { method, redirect : 'manual' } ) ;
135+ expect ( [ 301 , 307 , 308 ] , `${ mode } : ${ path } ` ) . toContain ( dynamicRedirect . status ) ;
136+ await dynamicRedirect . text ( ) ;
137+ const dynamicPage = await fetch ( `${ base } /${ path } /` , { method } ) ;
138+ expect ( dynamicPage . status , `${ mode } : ${ path } ` ) . toBe ( 200 ) ;
139+ const html = await dynamicPage . text ( ) ;
140+ if ( method === 'HEAD' ) {
141+ expect ( html ) . toBe ( '' ) ;
142+ } else {
143+ expect ( html ) . toContain ( `<h1>${ value } </h1>` ) ;
144+ }
145+ }
146+ const api = await fetch ( `${ base } /api/hello` , { method, redirect : 'manual' } ) ;
147+ expect ( api . status ) . toBe ( 200 ) ;
148+ await api . text ( ) ;
133149 }
134- const api = await fetch ( `${ base } /api/hello` , { redirect : 'manual' } ) ;
135- expect ( api . status ) . toBe ( 200 ) ;
136- await api . text ( ) ;
137- }
138- } ) ;
139- it ( 'keeps public files accessible beside a catch-all page' , async ( ) => {
140- for ( const { base, mode } of servers ) {
141- for ( const file of [ 'asset.js' , 'favicon.ico' , 'LICENSE' ] ) {
142- const response = await fetch ( `${ base } /${ file } ` , { redirect : 'manual' } ) ;
143- expect ( response . status , `${ mode } : ${ file } ` ) . toBe ( 200 ) ;
144- expect ( await response . text ( ) , `${ mode } : ${ file } ` ) . toBe ( 'public file' ) ;
150+ } ,
151+ ) ;
152+ it . each ( [ 'GET' , 'HEAD' ] ) (
153+ 'keeps public files accessible to %s beside a catch-all page' ,
154+ async ( method ) => {
155+ for ( const { base, mode } of servers ) {
156+ for ( const file of [ 'asset.js' , 'favicon.ico' , 'LICENSE' ] ) {
157+ const response = await fetch ( `${ base } /${ file } ` , { method, redirect : 'manual' } ) ;
158+ expect ( response . status , `${ mode } : ${ file } ` ) . toBe ( 200 ) ;
159+ expect ( await response . text ( ) , `${ mode } : ${ file } ` ) . toBe (
160+ method === 'HEAD' ? '' : 'public file' ,
161+ ) ;
162+ }
163+ const html = await fetch ( `${ base } /terms.html` , { method } ) ;
164+ expect ( html . status , mode ) . toBe ( 200 ) ;
165+ expect ( await html . text ( ) , mode ) . toBe ( method === 'HEAD' ? '' : 'public file' ) ;
145166 }
146- const html = await fetch ( `${ base } /terms.html` ) ;
147- expect ( html . status , mode ) . toBe ( 200 ) ;
148- expect ( await html . text ( ) , mode ) . toBe ( 'public file' ) ;
149- }
150- } ) ;
167+ } ,
168+ ) ;
151169 it ( 'preserves catch-all parameters in actions and supports empty anonymous catch-alls' , async ( ) => {
152170 for ( const { base, mode } of servers ) {
153171 const action = await fetch ( `${ base } /files/guides/intro/` , {
0 commit comments