@@ -13,16 +13,37 @@ export function assertRequest(ports: number[],
13
13
14
14
ports . forEach ( port => {
15
15
16
- it ( "asserting port " + port , ( ) => {
17
- if ( args === 4 ) {
18
- return chakram [ method ] ( `http://127.0.0.1:${ port } /${ route } ` ) . then ( dataOrCallback as Function ) ;
19
- } else if ( args === 5 ) {
20
- return chakram [ method ] ( `http://127.0.0.1:${ port } /${ route } ` , dataOrCallback as any ) . then ( dataOrRequestOptionsOrCallback as Function ) ;
21
- } else if ( args === 6 ) {
22
- return chakram [ method ] ( `http://127.0.0.1:${ port } /${ route } ` , dataOrCallback as any , dataOrRequestOptionsOrCallback as any ) . then ( maybeCallback ) ;
16
+ it ( "asserting port " + port , async ( ) => {
17
+ let unhandledRejection : Error = undefined ;
18
+ const captureRejection = ( e : Error ) => { unhandledRejection = e ; } ;
19
+ process . on ( "unhandledRejection" , captureRejection ) ;
20
+
21
+ try {
22
+ let r ;
23
+ if ( args === 4 ) {
24
+ r = await chakram [ method ] ( `http://127.0.0.1:${ port } /${ route } ` ) . then ( dataOrCallback as Function ) ;
25
+ }
26
+ else if ( args === 5 ) {
27
+ r = await chakram [ method ] ( `http://127.0.0.1:${ port } /${ route } ` , dataOrCallback as any ) . then ( dataOrRequestOptionsOrCallback as Function ) ;
28
+ }
29
+ else if ( args === 6 ) {
30
+ r = await chakram [ method ] ( `http://127.0.0.1:${ port } /${ route } ` , dataOrCallback as any , dataOrRequestOptionsOrCallback as any ) . then ( maybeCallback ) ;
31
+ }
32
+ else {
33
+ throw new Error ( "No assertion has been performed" ) ;
34
+ }
35
+
36
+ if ( unhandledRejection ) {
37
+ const e = new Error ( "There was an unhandled rejection while processing the request" ) ;
38
+ e . stack += "\nCaused by: " + unhandledRejection . stack ;
39
+ throw e ;
40
+ }
41
+
42
+ return r ;
43
+ }
44
+ finally {
45
+ process . removeListener ( "unhandledRejection" , captureRejection ) ;
23
46
}
24
-
25
- throw new Error ( "No assertion has been performed" ) ;
26
47
} ) ;
27
48
28
49
} ) ;
0 commit comments