@@ -16,12 +16,6 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
1616describe ( 'redirects' , ( ) => {
1717 vi . setConfig ( { testTimeout : 3 * 60 * 1000 } )
1818
19- let redirects
20- beforeAll ( async ( ) => {
21- const res = await get ( '/en?json=redirects' )
22- redirects = JSON . parse ( res . body )
23- } )
24-
2519 test ( 'page.buildRedirects() returns an array' , async ( ) => {
2620 const page = await Page . init ( {
2721 relativePath :
@@ -94,6 +88,12 @@ describe('redirects', () => {
9488 } )
9589
9690 describe ( 'trailing slashes' , ( ) => {
91+ let redirects
92+ beforeAll ( async ( ) => {
93+ const res = await get ( '/en?json=redirects' )
94+ redirects = JSON . parse ( res . body )
95+ } )
96+
9797 test ( 'are absent from all redirected URLs' , async ( ) => {
9898 const keys = Object . keys ( redirects )
9999 expect ( keys . length ) . toBeGreaterThan ( 100 )
@@ -138,6 +138,12 @@ describe('redirects', () => {
138138 } )
139139
140140 describe ( 'external redirects' , ( ) => {
141+ let redirects
142+ beforeAll ( async ( ) => {
143+ const res = await get ( '/en?json=redirects' )
144+ redirects = JSON . parse ( res . body )
145+ } )
146+
141147 test ( 'no external redirect starts with a language prefix' , ( ) => {
142148 const values = Object . entries ( redirects )
143149 . filter ( ( [ , to ] ) => to . includes ( '://' ) )
@@ -425,6 +431,14 @@ describe('redirects', () => {
425431 expect ( res . headers . location ) . toBe ( `/en` )
426432 } )
427433
434+ test ( 'no domain redirect on //example.com/' , async ( ) => {
435+ const res = await get ( `//example.com/` )
436+ expect ( res . statusCode ) . toBe ( 301 )
437+ expect ( res . headers . location ) . toBe ( `/example.com` ) // should not be //example.com
438+ const res2 = await get ( res . headers . location )
439+ expect ( res2 . statusCode ) . toBe ( 404 )
440+ } )
441+
428442 test ( 'double-slash elsewhere in the URL' , async ( ) => {
429443 const res = await get ( `/en//rest` )
430444 expect ( res . statusCode ) . toBe ( 301 )
0 commit comments