File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { HttpCode } from "../common/http"
4
4
export const proxy = proxyServer . createProxyServer ( { } )
5
5
6
6
proxy . on ( "error" , ( error , _ , res ) => {
7
+ console . log ( "yoooo" )
7
8
res . writeHead ( HttpCode . ServerError )
8
9
res . end ( error . message )
9
10
} )
Original file line number Diff line number Diff line change @@ -157,9 +157,9 @@ describe("proxy (standalone)", () => {
157
157
158
158
beforeAll ( async ( ) => {
159
159
await testServer . listen ( ( req , res ) => {
160
+ proxyServer . web ( req , res , { target : `http://localhost:${ testServer . port ( ) } ` } )
160
161
expressServer ( req , res )
161
162
} )
162
- await proxyServer . listen ( testServer . port ( ) )
163
163
} )
164
164
165
165
afterAll ( async ( ) => {
@@ -190,3 +190,34 @@ describe("proxy (standalone)", () => {
190
190
expect ( resp . status ) . toBe ( 500 )
191
191
} )
192
192
} )
193
+
194
+ describe ( "test dummy" , ( ) => {
195
+ it ( "should return a 200" , async ( ) => {
196
+ const testServer = new httpserver . HttpServer ( )
197
+
198
+ await testServer . listen ( function ( req , res ) {
199
+ proxy . web ( req , res , {
200
+ target : `http://localhost:${ testServer . port ( ) } ` ,
201
+ } )
202
+
203
+ if ( req . url === "/error" ) {
204
+ res . statusCode = 500
205
+ res . end ( "ERROR" )
206
+ return
207
+ }
208
+
209
+ res . writeHead ( 200 , { "Content-Type" : "text/plain" } )
210
+ res . write ( "nice joe" )
211
+ res . end ( )
212
+ } )
213
+
214
+ const resp = await testServer . fetch ( `/wsup` )
215
+ expect ( resp . status ) . toBe ( 200 )
216
+ expect ( resp . statusText ) . toBe ( "OK" )
217
+
218
+ const errorResp = await testServer . fetch ( `/error` )
219
+ expect ( errorResp . status ) . toBe ( 500 )
220
+
221
+ await testServer . close ( )
222
+ } )
223
+ } )
You can’t perform that action at this time.
0 commit comments