@@ -65,14 +65,14 @@ describe('E2E http-proxy-middleware', () => {
65
65
} ) ;
66
66
67
67
it ( 'should have response body: "HELLO WEB"' , async ( ) => {
68
- await mockTargetServer . get ( '/api' ) . thenReply ( 200 , 'HELLO WEB' ) ;
68
+ await mockTargetServer . forGet ( '/api' ) . thenReply ( 200 , 'HELLO WEB' ) ;
69
69
const response = await agent . get ( `/api` ) . expect ( 200 ) ;
70
70
expect ( response . text ) . toBe ( 'HELLO WEB' ) ;
71
71
} ) ;
72
72
73
73
it ( 'should have proxied the uri-path and uri-query, but not the uri-hash' , async ( ) => {
74
74
await mockTargetServer
75
- . get ( '/api/b/c/dp' )
75
+ . forGet ( '/api/b/c/dp' )
76
76
. withExactQuery ( '?q=1&r=[2,3]' )
77
77
. thenReply ( 200 , 'OK' ) ;
78
78
@@ -99,8 +99,8 @@ describe('E2E http-proxy-middleware', () => {
99
99
)
100
100
) ;
101
101
102
- await mockTargetServer . post ( '/api' ) . thenCallback ( ( req ) => {
103
- expect ( req . body . text ) . toBe ( 'foo=bar&bar=baz' ) ;
102
+ await mockTargetServer . forPost ( '/api' ) . thenCallback ( async ( req ) => {
103
+ expect ( await req . body . getText ( ) ) . toBe ( 'foo=bar&bar=baz' ) ;
104
104
return { status : 200 } ;
105
105
} ) ;
106
106
await agent . post ( '/api' ) . send ( 'foo=bar' ) . send ( 'bar=baz' ) . expect ( 200 ) ;
@@ -120,8 +120,8 @@ describe('E2E http-proxy-middleware', () => {
120
120
)
121
121
) ;
122
122
123
- await mockTargetServer . post ( '/api' ) . thenCallback ( ( req ) => {
124
- expect ( req . body . json ) . toEqual ( { foo : 'bar' , bar : 'baz' , doubleByte : '文' } ) ;
123
+ await mockTargetServer . forPost ( '/api' ) . thenCallback ( async ( req ) => {
124
+ expect ( await req . body . getJson ( ) ) . toEqual ( { foo : 'bar' , bar : 'baz' , doubleByte : '文' } ) ;
125
125
return { status : 200 } ;
126
126
} ) ;
127
127
await agent . post ( '/api' ) . send ( { foo : 'bar' , bar : 'baz' , doubleByte : '文' } ) . expect ( 200 ) ;
@@ -143,7 +143,7 @@ describe('E2E http-proxy-middleware', () => {
143
143
)
144
144
) ;
145
145
146
- await mockTargetServer . get ( '/api/b/c/d' ) . thenReply ( 200 , 'HELLO WEB' ) ;
146
+ await mockTargetServer . forGet ( '/api/b/c/d' ) . thenReply ( 200 , 'HELLO WEB' ) ;
147
147
const response = await agent . get ( `/api/b/c/d` ) . expect ( 200 ) ;
148
148
expect ( response . text ) . toBe ( 'HELLO WEB' ) ;
149
149
} ) ;
@@ -162,7 +162,7 @@ describe('E2E http-proxy-middleware', () => {
162
162
)
163
163
) ;
164
164
165
- await mockTargetServer . get ( '/api/b/c/d' ) . thenReply ( 200 , 'HELLO WEB' ) ;
165
+ await mockTargetServer . forGet ( '/api/b/c/d' ) . thenReply ( 200 , 'HELLO WEB' ) ;
166
166
const response = await agent . get ( `/api/b/c/d` ) . expect ( 404 ) ;
167
167
expect ( response . status ) . toBe ( 404 ) ;
168
168
} ) ;
@@ -181,13 +181,13 @@ describe('E2E http-proxy-middleware', () => {
181
181
} ) ;
182
182
183
183
it ( 'should proxy to path /api' , async ( ) => {
184
- await mockTargetServer . get ( / \/ a p i \/ .+ / ) . thenReply ( 200 , 'HELLO /API' ) ;
184
+ await mockTargetServer . forGet ( / \/ a p i \/ .+ / ) . thenReply ( 200 , 'HELLO /API' ) ;
185
185
const response = await agent . get ( `/api/b/c/d` ) . expect ( 200 ) ;
186
186
expect ( response . text ) . toBe ( 'HELLO /API' ) ;
187
187
} ) ;
188
188
189
189
it ( 'should proxy to path /ajax' , async ( ) => {
190
- await mockTargetServer . get ( / \/ a j a x \/ .+ / ) . thenReply ( 200 , 'HELLO /AJAX' ) ;
190
+ await mockTargetServer . forGet ( / \/ a j a x \/ .+ / ) . thenReply ( 200 , 'HELLO /AJAX' ) ;
191
191
const response = await agent . get ( `/ajax/b/c/d` ) . expect ( 200 ) ;
192
192
expect ( response . text ) . toBe ( 'HELLO /AJAX' ) ;
193
193
} ) ;
@@ -211,7 +211,7 @@ describe('E2E http-proxy-middleware', () => {
211
211
} ) ;
212
212
213
213
it ( 'should proxy to path' , async ( ) => {
214
- await mockTargetServer . get ( / \/ a p i \/ .+ / ) . thenReply ( 200 , 'HELLO /api' ) ;
214
+ await mockTargetServer . forGet ( / \/ a p i \/ .+ / ) . thenReply ( 200 , 'HELLO /api' ) ;
215
215
const response = await agent . get ( `/api/b/c/d` ) . expect ( 200 ) ;
216
216
expect ( response . text ) . toBe ( 'HELLO /api' ) ;
217
217
} ) ;
@@ -230,13 +230,13 @@ describe('E2E http-proxy-middleware', () => {
230
230
} ) ;
231
231
232
232
it ( 'should proxy to paths ending with *.html' , async ( ) => {
233
- await mockTargetServer . get ( / .+ h t m l $ / ) . thenReply ( 200 , 'HELLO .html' ) ;
233
+ await mockTargetServer . forGet ( / .+ h t m l $ / ) . thenReply ( 200 , 'HELLO .html' ) ;
234
234
const response = await agent . get ( `/api/some/endpoint/index.html` ) . expect ( 200 ) ;
235
235
expect ( response . text ) . toBe ( 'HELLO .html' ) ;
236
236
} ) ;
237
237
238
238
it ( 'should not proxy to paths ending with *.json' , async ( ) => {
239
- await mockTargetServer . get ( / .+ j s o n $ / ) . thenReply ( 200 , 'HELLO .html' ) ;
239
+ await mockTargetServer . forGet ( / .+ j s o n $ / ) . thenReply ( 200 , 'HELLO .html' ) ;
240
240
const response = await agent . get ( `/api/some/endpoint/data.json` ) . expect ( 404 ) ;
241
241
expect ( response . status ) . toBe ( 404 ) ;
242
242
} ) ;
@@ -258,7 +258,7 @@ describe('E2E http-proxy-middleware', () => {
258
258
it ( 'should send request header "host" to target server' , async ( ) => {
259
259
let completedRequest : CompletedRequest ;
260
260
261
- await mockTargetServer . get ( ) . thenCallback ( ( req ) => {
261
+ await mockTargetServer . forGet ( ) . thenCallback ( ( req ) => {
262
262
completedRequest = req ;
263
263
return { statusCode : 200 , body : 'OK' } ;
264
264
} ) ;
@@ -337,13 +337,13 @@ describe('E2E http-proxy-middleware', () => {
337
337
} ) ;
338
338
339
339
it ( 'should add `x-added` as custom header to response"' , async ( ) => {
340
- await mockTargetServer . get ( ) . thenReply ( 200 , 'HELLO .html' ) ;
340
+ await mockTargetServer . forGet ( ) . thenReply ( 200 , 'HELLO .html' ) ;
341
341
const response = await agent . get ( `/api/some/endpoint/index.html` ) . expect ( 200 ) ;
342
342
expect ( response . header [ 'x-added' ] ) . toBe ( 'foobar' ) ;
343
343
} ) ;
344
344
345
345
it ( 'should remove `x-removed` field from response header"' , async ( ) => {
346
- await mockTargetServer . get ( ) . thenCallback ( ( req ) => {
346
+ await mockTargetServer . forGet ( ) . thenCallback ( ( req ) => {
347
347
return {
348
348
statusCode : 200 ,
349
349
headers : {
@@ -375,7 +375,7 @@ describe('E2E http-proxy-middleware', () => {
375
375
376
376
it ( 'should add `x-added` as custom header to request"' , async ( ) => {
377
377
let completedRequest : CompletedRequest ;
378
- await mockTargetServer . get ( ) . thenCallback ( ( req ) => {
378
+ await mockTargetServer . forGet ( ) . thenCallback ( ( req ) => {
379
379
completedRequest = req ;
380
380
return { statusCode : 200 } ;
381
381
} ) ;
@@ -402,13 +402,13 @@ describe('E2E http-proxy-middleware', () => {
402
402
} ) ;
403
403
404
404
it ( 'should have rewritten path from "/api/foo/bar" to "/rest/foo/bar"' , async ( ) => {
405
- await mockTargetServer . get ( '/rest/foo/bar' ) . thenReply ( 200 , 'HELLO /rest/foo/bar' ) ;
405
+ await mockTargetServer . forGet ( '/rest/foo/bar' ) . thenReply ( 200 , 'HELLO /rest/foo/bar' ) ;
406
406
const response = await agent . get ( `/api/foo/bar` ) . expect ( 200 ) ;
407
407
expect ( response . text ) . toBe ( 'HELLO /rest/foo/bar' ) ;
408
408
} ) ;
409
409
410
410
it ( 'should have removed path from "/remove/api/lipsum" to "/api/lipsum"' , async ( ) => {
411
- await mockTargetServer . get ( '/api/lipsum' ) . thenReply ( 200 , 'HELLO /api/lipsum' ) ;
411
+ await mockTargetServer . forGet ( '/api/lipsum' ) . thenReply ( 200 , 'HELLO /api/lipsum' ) ;
412
412
const response = await agent . get ( `/remove/api/lipsum` ) . expect ( 200 ) ;
413
413
expect ( response . text ) . toBe ( 'HELLO /api/lipsum' ) ;
414
414
} ) ;
@@ -425,7 +425,7 @@ describe('E2E http-proxy-middleware', () => {
425
425
} ) ;
426
426
427
427
it ( 'should proxy to target with the baseUrl' , async ( ) => {
428
- await mockTargetServer . get ( '/api/foo/bar' ) . thenReply ( 200 , 'HELLO /api/foo/bar' ) ;
428
+ await mockTargetServer . forGet ( '/api/foo/bar' ) . thenReply ( 200 , 'HELLO /api/foo/bar' ) ;
429
429
const response = await agent . get ( `/api/foo/bar` ) . expect ( 200 ) ;
430
430
expect ( response . text ) . toBe ( 'HELLO /api/foo/bar' ) ;
431
431
} ) ;
@@ -454,7 +454,7 @@ describe('E2E http-proxy-middleware', () => {
454
454
} ) ;
455
455
456
456
it ( 'should have logged messages' , async ( ) => {
457
- await mockTargetServer . get ( '/api/foo/bar' ) . thenReply ( 200 ) ;
457
+ await mockTargetServer . forGet ( '/api/foo/bar' ) . thenReply ( 200 ) ;
458
458
await agent . get ( `/api/foo/bar` ) . expect ( 200 ) ;
459
459
460
460
expect ( logMessages ) . not . toBeUndefined ( ) ;
0 commit comments