@@ -8,7 +8,7 @@ import { withSiteBuilder } from '../../utils/site-builder.js'
88describe ( 'redirects' , ( ) => {
99 setupFixtureTests ( 'dev-server-with-functions' , { devServer : true } , ( ) => {
1010 test < FixtureTestContext > ( 'should send original query params to functions' , async ( { devServer } ) => {
11- const response = await fetch ( `http://localhost:${ devServer . port } /with-params?param2=world&other=1` , { } )
11+ const response = await fetch ( `http://localhost:${ devServer . port } /with-params?param2=world&other=1` )
1212
1313 expect ( response . status ) . toBe ( 200 )
1414
@@ -21,7 +21,7 @@ describe('redirects', () => {
2121 test < FixtureTestContext > ( 'should send original query params to functions when using duplicate parameters' , async ( {
2222 devServer,
2323 } ) => {
24- const response = await fetch ( `http://localhost:${ devServer . port } /api/echo?param=hello¶m=world` , { } )
24+ const response = await fetch ( `http://localhost:${ devServer . port } /api/echo?param=hello¶m=world` )
2525
2626 expect ( response . status ) . toBe ( 200 )
2727
@@ -33,23 +33,85 @@ describe('redirects', () => {
3333
3434 setupFixtureTests ( 'next-app' , { devServer : { env : { NETLIFY_DEV_SERVER_CHECK_SSG_ENDPOINTS : 1 } } } , ( ) => {
3535 test < FixtureTestContext > ( 'should prefer local files instead of redirect when not forced' , async ( { devServer } ) => {
36- const response = await fetch ( `http://localhost:${ devServer . port } /test.txt` , { } )
36+ const response = await fetch ( `http://localhost:${ devServer . port } /test.txt` )
3737
3838 expect ( response . status ) . toBe ( 200 )
3939
4040 const result = await response . text ( )
4141 expect ( result . trim ( ) ) . toEqual ( 'hello world' )
42+ expect ( devServer ?. output ) . not . toContain ( 'Proxying to https://www.netlify.app' )
4243 } )
4344
4445 test < FixtureTestContext > ( 'should check for the dynamic page existence before doing redirect' , async ( {
4546 devServer,
4647 } ) => {
47- const response = await fetch ( `http://localhost:${ devServer . port } /` , { } )
48+ const response = await fetch ( `http://localhost:${ devServer . port } /` )
4849
4950 expect ( response . status ) . toBe ( 200 )
5051
5152 const result = await response . text ( )
53+ expect ( result . toLowerCase ( ) ) . toContain ( 'local site dev server' )
5254 expect ( result . toLowerCase ( ) ) . not . toContain ( 'netlify' )
55+ expect ( devServer ?. output ) . not . toContain ( 'Proxying to https://www.netlify.app' )
56+ } )
57+
58+ test < FixtureTestContext > ( 'nested route redirect check for the page existence' , async ( { devServer } ) => {
59+ let response = await fetch ( `http://localhost:${ devServer . port } /test/exists` )
60+ expect ( response . status ) . toBe ( 200 )
61+
62+ let result = await response . text ( )
63+ expect ( result . toLowerCase ( ) ) . toContain ( 'exists page' )
64+ expect ( devServer ?. output ) . not . toContain ( 'Proxying to https://www.netlify.app/exists' )
65+
66+ response = await fetch ( `http://localhost:${ devServer . port } /test/about` )
67+ expect ( response . status ) . toBe ( 200 )
68+
69+ result = await response . text ( )
70+ expect ( result . toLowerCase ( ) ) . toContain ( 'netlify' )
71+
72+ expect ( devServer ?. output ) . toContain ( 'Proxying to https://www.netlify.app/about' )
73+ } )
74+
75+ test < FixtureTestContext > ( 'should do local redirect' , async ( { devServer } ) => {
76+ const response = await fetch ( `http://localhost:${ devServer . port } /local/test/exists` )
77+
78+ expect ( response . status ) . toBe ( 200 )
79+
80+ const result = await response . text ( )
81+ expect ( response . headers . get ( 'location' ) ) . toBeNull ( )
82+ expect ( response . status ) . toBe ( 200 )
83+ expect ( result . toLowerCase ( ) ) . toContain ( 'exists page' )
84+ expect ( result . toLowerCase ( ) ) . not . toContain ( 'netlify' )
85+ expect ( devServer ?. output ) . not . toContain ( 'Proxying to https://www.netlify.app/test' )
86+ } )
87+ } )
88+
89+ setupFixtureTests ( 'site-with-redirect' , { devServer : true } , ( ) => {
90+ test < FixtureTestContext > ( 'should do local redirect' , async ( { devServer } ) => {
91+ const response = await fetch ( `http://localhost:${ devServer . port } /local/test/exists` )
92+
93+ expect ( response . status ) . toBe ( 200 )
94+
95+ const result = await response . text ( )
96+ expect ( response . url ) . toEqual ( `http://localhost:${ devServer . port } /local/test/exists` )
97+ expect ( response . status ) . toBe ( 200 )
98+ expect ( result . toLowerCase ( ) ) . toContain ( 'exists page' )
99+ expect ( result . toLowerCase ( ) ) . not . toContain ( 'netlify' )
100+ expect ( devServer ?. output ) . not . toContain ( 'Proxying to https://www.netlify.app' )
101+ } )
102+
103+ test < FixtureTestContext > ( 'should pass proper status code of the redirected page' , async ( { devServer } ) => {
104+ let response = await fetch ( `http://localhost:${ devServer . port } /local/test/not-allowed` )
105+
106+ expect ( response . status ) . toBe ( 405 )
107+ const result = await response . text ( )
108+ expect ( result . toLowerCase ( ) ) . toContain ( 'this not allowed' )
109+
110+ response = await fetch ( `http://localhost:${ devServer . port } /local/test/not-found` )
111+ expect ( response . status ) . toBe ( 404 )
112+
113+ response = await fetch ( `http://localhost:${ devServer . port } /local-force/test/exists` )
114+ expect ( response . status ) . toBe ( 402 )
53115 } )
54116 } )
55117
0 commit comments