@@ -6,7 +6,7 @@ import fetch from 'node-fetch'
66describe ( 'redirects' , ( ) => {
77 setupFixtureTests ( 'dev-server-with-functions' , { devServer : true } , ( ) => {
88 test < FixtureTestContext > ( 'should send original query params to functions' , async ( { devServer } ) => {
9- const response = await fetch ( `http://localhost:${ devServer . port } /with-params?param2=world&other=1` , { } )
9+ const response = await fetch ( `http://localhost:${ devServer . port } /with-params?param2=world&other=1` )
1010
1111 expect ( response . status ) . toBe ( 200 )
1212
@@ -19,7 +19,7 @@ describe('redirects', () => {
1919 test < FixtureTestContext > ( 'should send original query params to functions when using duplicate parameters' , async ( {
2020 devServer,
2121 } ) => {
22- const response = await fetch ( `http://localhost:${ devServer . port } /api/echo?param=hello¶m=world` , { } )
22+ const response = await fetch ( `http://localhost:${ devServer . port } /api/echo?param=hello¶m=world` )
2323
2424 expect ( response . status ) . toBe ( 200 )
2525
@@ -31,23 +31,77 @@ describe('redirects', () => {
3131
3232 setupFixtureTests ( 'next-app' , { devServer : { env : { NETLIFY_DEV_SERVER_CHECK_SSG_ENDPOINTS : 1 } } } , ( ) => {
3333 test < FixtureTestContext > ( 'should prefer local files instead of redirect when not forced' , async ( { devServer } ) => {
34- const response = await fetch ( `http://localhost:${ devServer . port } /test.txt` , { } )
34+ const response = await fetch ( `http://localhost:${ devServer . port } /test.txt` )
3535
3636 expect ( response . status ) . toBe ( 200 )
3737
3838 const result = await response . text ( )
3939 expect ( result . trim ( ) ) . toEqual ( 'hello world' )
40+ expect ( devServer ?. output ) . not . toContain ( 'Proxying to https://www.netlify.app' ) ;
4041 } )
4142
4243 test < FixtureTestContext > ( 'should check for the dynamic page existence before doing redirect' , async ( {
4344 devServer,
4445 } ) => {
45- const response = await fetch ( `http://localhost:${ devServer . port } /` , { } )
46+ const response = await fetch ( `http://localhost:${ devServer . port } /` )
4647
4748 expect ( response . status ) . toBe ( 200 )
4849
4950 const result = await response . text ( )
51+ expect ( result . toLowerCase ( ) ) . toContain ( 'local site dev server' )
5052 expect ( result . toLowerCase ( ) ) . not . toContain ( 'netlify' )
53+ expect ( devServer ?. output ) . not . toContain ( 'Proxying to https://www.netlify.app' ) ;
54+ } )
55+
56+ test < FixtureTestContext > ( 'nested route redirect check for the page existence' , async ( {
57+ devServer,
58+ } ) => {
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 ( {
76+ devServer,
77+ } ) => {
78+ const response = await fetch ( `http://localhost:${ devServer . port } /local/test/exists` )
79+
80+ expect ( response . status ) . toBe ( 200 )
81+
82+ const result = await response . text ( )
83+ expect ( response . headers . get ( 'location' ) ) . toBeNull ( )
84+ expect ( response . status ) . toBe ( 200 )
85+ expect ( result . toLowerCase ( ) ) . toContain ( 'exists page' )
86+ expect ( result . toLowerCase ( ) ) . not . toContain ( 'netlify' )
87+ expect ( devServer ?. output ) . not . toContain ( 'Proxying to https://www.netlify.app/test' ) ;
88+ } )
89+ } )
90+
91+ setupFixtureTests ( 'site-with-redirect' , { devServer : true } , ( ) => {
92+ test < FixtureTestContext > ( 'should do local redirect' , async ( {
93+ devServer,
94+ } ) => {
95+ const response = await fetch ( `http://localhost:${ devServer . port } /local/test/exists` )
96+
97+ expect ( response . status ) . toBe ( 200 )
98+
99+ const result = await response . text ( )
100+ expect ( response . url ) . toEqual ( `http://localhost:${ devServer . port } /local/test/exists` )
101+ expect ( response . status ) . toBe ( 200 )
102+ expect ( result . toLowerCase ( ) ) . toContain ( 'exists page' )
103+ expect ( result . toLowerCase ( ) ) . not . toContain ( 'netlify' )
104+ expect ( devServer ?. output ) . not . toContain ( 'Proxying to https://www.netlify.app' ) ;
51105 } )
52106 } )
53107} )
0 commit comments