@@ -6,7 +6,7 @@ import fetch from 'node-fetch'
6
6
describe ( 'redirects' , ( ) => {
7
7
setupFixtureTests ( 'dev-server-with-functions' , { devServer : true } , ( ) => {
8
8
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` )
10
10
11
11
expect ( response . status ) . toBe ( 200 )
12
12
@@ -19,7 +19,7 @@ describe('redirects', () => {
19
19
test < FixtureTestContext > ( 'should send original query params to functions when using duplicate parameters' , async ( {
20
20
devServer,
21
21
} ) => {
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` )
23
23
24
24
expect ( response . status ) . toBe ( 200 )
25
25
@@ -31,23 +31,85 @@ describe('redirects', () => {
31
31
32
32
setupFixtureTests ( 'next-app' , { devServer : { env : { NETLIFY_DEV_SERVER_CHECK_SSG_ENDPOINTS : 1 } } } , ( ) => {
33
33
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` )
35
35
36
36
expect ( response . status ) . toBe ( 200 )
37
37
38
38
const result = await response . text ( )
39
39
expect ( result . trim ( ) ) . toEqual ( 'hello world' )
40
+ expect ( devServer ?. output ) . not . toContain ( 'Proxying to https://www.netlify.app' )
40
41
} )
41
42
42
43
test < FixtureTestContext > ( 'should check for the dynamic page existence before doing redirect' , async ( {
43
44
devServer,
44
45
} ) => {
45
- const response = await fetch ( `http://localhost:${ devServer . port } /` , { } )
46
+ const response = await fetch ( `http://localhost:${ devServer . port } /` )
46
47
47
48
expect ( response . status ) . toBe ( 200 )
48
49
49
50
const result = await response . text ( )
51
+ expect ( result . toLowerCase ( ) ) . toContain ( 'local site dev server' )
50
52
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 ( { devServer } ) => {
57
+ let response = await fetch ( `http://localhost:${ devServer . port } /test/exists` )
58
+ expect ( response . status ) . toBe ( 200 )
59
+
60
+ let result = await response . text ( )
61
+ expect ( result . toLowerCase ( ) ) . toContain ( 'exists page' )
62
+ expect ( devServer ?. output ) . not . toContain ( 'Proxying to https://www.netlify.app/exists' )
63
+
64
+ response = await fetch ( `http://localhost:${ devServer . port } /test/about` )
65
+ expect ( response . status ) . toBe ( 200 )
66
+
67
+ result = await response . text ( )
68
+ expect ( result . toLowerCase ( ) ) . toContain ( 'netlify' )
69
+
70
+ expect ( devServer ?. output ) . toContain ( 'Proxying to https://www.netlify.app/about' )
71
+ } )
72
+
73
+ test < FixtureTestContext > ( 'should do local redirect' , async ( { devServer } ) => {
74
+ const response = await fetch ( `http://localhost:${ devServer . port } /local/test/exists` )
75
+
76
+ expect ( response . status ) . toBe ( 200 )
77
+
78
+ const result = await response . text ( )
79
+ expect ( response . headers . get ( 'location' ) ) . toBeNull ( )
80
+ expect ( response . status ) . toBe ( 200 )
81
+ expect ( result . toLowerCase ( ) ) . toContain ( 'exists page' )
82
+ expect ( result . toLowerCase ( ) ) . not . toContain ( 'netlify' )
83
+ expect ( devServer ?. output ) . not . toContain ( 'Proxying to https://www.netlify.app/test' )
84
+ } )
85
+ } )
86
+
87
+ setupFixtureTests ( 'site-with-redirect' , { devServer : true } , ( ) => {
88
+ test < FixtureTestContext > ( 'should do local redirect' , async ( { devServer } ) => {
89
+ const response = await fetch ( `http://localhost:${ devServer . port } /local/test/exists` )
90
+
91
+ expect ( response . status ) . toBe ( 200 )
92
+
93
+ const result = await response . text ( )
94
+ expect ( response . url ) . toEqual ( `http://localhost:${ devServer . port } /local/test/exists` )
95
+ expect ( response . status ) . toBe ( 200 )
96
+ expect ( result . toLowerCase ( ) ) . toContain ( 'exists page' )
97
+ expect ( result . toLowerCase ( ) ) . not . toContain ( 'netlify' )
98
+ expect ( devServer ?. output ) . not . toContain ( 'Proxying to https://www.netlify.app' )
99
+ } )
100
+
101
+ test < FixtureTestContext > ( 'should pass proper status code of the redirected page' , async ( { devServer } ) => {
102
+ let response = await fetch ( `http://localhost:${ devServer . port } /local/test/not-allowed` )
103
+
104
+ expect ( response . status ) . toBe ( 405 )
105
+ const result = await response . text ( )
106
+ expect ( result . toLowerCase ( ) ) . toContain ( 'this not allowed' )
107
+
108
+ response = await fetch ( `http://localhost:${ devServer . port } /local/test/not-found` )
109
+ expect ( response . status ) . toBe ( 404 )
110
+
111
+ response = await fetch ( `http://localhost:${ devServer . port } /local-force/test/exists` )
112
+ expect ( response . status ) . toBe ( 402 )
51
113
} )
52
114
} )
53
115
} )
0 commit comments