@@ -8,7 +8,7 @@ import { withSiteBuilder } from '../../utils/site-builder.js'
8
8
describe ( 'redirects' , ( ) => {
9
9
setupFixtureTests ( 'dev-server-with-functions' , { devServer : true } , ( ) => {
10
10
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` )
12
12
13
13
expect ( response . status ) . toBe ( 200 )
14
14
@@ -21,7 +21,7 @@ describe('redirects', () => {
21
21
test < FixtureTestContext > ( 'should send original query params to functions when using duplicate parameters' , async ( {
22
22
devServer,
23
23
} ) => {
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` )
25
25
26
26
expect ( response . status ) . toBe ( 200 )
27
27
@@ -33,23 +33,85 @@ describe('redirects', () => {
33
33
34
34
setupFixtureTests ( 'next-app' , { devServer : { env : { NETLIFY_DEV_SERVER_CHECK_SSG_ENDPOINTS : 1 } } } , ( ) => {
35
35
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` )
37
37
38
38
expect ( response . status ) . toBe ( 200 )
39
39
40
40
const result = await response . text ( )
41
41
expect ( result . trim ( ) ) . toEqual ( 'hello world' )
42
+ expect ( devServer ?. output ) . not . toContain ( 'Proxying to https://www.netlify.app' )
42
43
} )
43
44
44
45
test < FixtureTestContext > ( 'should check for the dynamic page existence before doing redirect' , async ( {
45
46
devServer,
46
47
} ) => {
47
- const response = await fetch ( `http://localhost:${ devServer . port } /` , { } )
48
+ const response = await fetch ( `http://localhost:${ devServer . port } /` )
48
49
49
50
expect ( response . status ) . toBe ( 200 )
50
51
51
52
const result = await response . text ( )
53
+ expect ( result . toLowerCase ( ) ) . toContain ( 'local site dev server' )
52
54
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 )
53
115
} )
54
116
} )
55
117
0 commit comments