@@ -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,77 @@ 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 ( {
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' ) ;
51
105
} )
52
106
} )
53
107
} )
0 commit comments