@@ -4,7 +4,7 @@ import {of} from '../../util/of';
44import { RpcError } from '../caller' ;
55
66export interface ApiTestSetupResult {
7- client : Pick < StreamingRpcClient , 'call$' > ;
7+ client : Pick < StreamingRpcClient , 'call$' | 'stop' > ;
88}
99
1010export type ApiTestSetup = ( ) => ApiTestSetupResult | Promise < ApiTestSetupResult > ;
@@ -15,18 +15,21 @@ export const runApiTests = (setup: ApiTestSetup, params: {staticOnly?: boolean}
1515 const { client} = await setup ( ) ;
1616 const result = await firstValueFrom ( client . call$ ( 'ping' , { } ) ) ;
1717 expect ( result ) . toBe ( 'pong' ) ;
18+ await client . stop ( ) ;
1819 } , 15_000 ) ;
1920
2021 test ( 'can execute without payload' , async ( ) => {
2122 const { client} = await setup ( ) ;
2223 const result = await firstValueFrom ( client . call$ ( 'ping' , undefined ) ) ;
2324 expect ( result ) . toBe ( 'pong' ) ;
25+ await client . stop ( ) ;
2426 } ) ;
2527
2628 test ( 'can execute with unexpected payload' , async ( ) => {
2729 const { client} = await setup ( ) ;
2830 const result = await firstValueFrom ( client . call$ ( 'ping' , 'VERY_UNEXPECTED' ) ) ;
2931 expect ( result ) . toBe ( 'pong' ) ;
32+ await client . stop ( ) ;
3033 } ) ;
3134 } ) ;
3235
@@ -35,6 +38,7 @@ export const runApiTests = (setup: ApiTestSetup, params: {staticOnly?: boolean}
3538 const { client} = await setup ( ) ;
3639 const result = await firstValueFrom ( client . call$ ( 'double' , { num : 1.2 } ) ) ;
3740 expect ( result ) . toEqual ( { num : 2.4 } ) ;
41+ await client . stop ( ) ;
3842 } ) ;
3943
4044 test ( 'can execute two request in parallel' , async ( ) => {
@@ -44,13 +48,15 @@ export const runApiTests = (setup: ApiTestSetup, params: {staticOnly?: boolean}
4448 const [ res1 , res2 ] = await Promise . all ( [ promise1 , promise2 ] ) ;
4549 expect ( res1 [ 0 ] ) . toEqual ( { num : 2 } ) ;
4650 expect ( res2 [ 0 ] ) . toEqual ( { num : 4 } ) ;
51+ await client . stop ( ) ;
4752 } ) ;
4853
4954 test ( 'throws error when validation fails' , async ( ) => {
5055 const { client} = await setup ( ) ;
5156 const [ , error ] = await of ( firstValueFrom ( client . call$ ( 'double' , { num : { } } ) ) ) ;
5257 expect ( ( error as RpcError ) . code ) . toBe ( 'BAD_REQUEST' ) ;
5358 expect ( ( error as RpcError ) . message ) . toBe ( 'Payload .num field missing.' ) ;
59+ await client . stop ( ) ;
5460 } ) ;
5561 } ) ;
5662
@@ -59,6 +65,7 @@ export const runApiTests = (setup: ApiTestSetup, params: {staticOnly?: boolean}
5965 const { client} = await setup ( ) ;
6066 const [ , error ] = await of ( firstValueFrom ( client . call$ ( 'error' , { } ) ) ) ;
6167 expect ( error ) . toMatchObject ( { message : 'this promise can throw' } ) ;
68+ await client . stop ( ) ;
6269 } ) ;
6370 } ) ;
6471
@@ -67,6 +74,7 @@ export const runApiTests = (setup: ApiTestSetup, params: {staticOnly?: boolean}
6774 const { client} = await setup ( ) ;
6875 const [ , error ] = await of ( lastValueFrom ( client . call$ ( 'streamError' , { } ) ) ) ;
6976 expect ( error ) . toMatchObject ( { message : 'Stream always errors' } ) ;
77+ await client . stop ( ) ;
7078 } ) ;
7179 } ) ;
7280
@@ -79,6 +87,7 @@ export const runApiTests = (setup: ApiTestSetup, params: {staticOnly?: boolean}
7987 commit : 'AAAAAAAAAAAAAAAAAAA' ,
8088 sha1 : 'BBBBBBBBBBBBBBBBBBB' ,
8189 } ) ;
90+ await client . stop ( ) ;
8291 } ) ;
8392 } ) ;
8493
@@ -89,6 +98,7 @@ export const runApiTests = (setup: ApiTestSetup, params: {staticOnly?: boolean}
8998 expect ( result ) . toEqual ( {
9099 bar : 'aa' ,
91100 } ) ;
101+ await client . stop ( ) ;
92102 } ) ;
93103
94104 test ( 'throws on invalid data' , async ( ) => {
@@ -97,6 +107,7 @@ export const runApiTests = (setup: ApiTestSetup, params: {staticOnly?: boolean}
97107 expect ( error ) . toMatchObject ( {
98108 message : '"foo" property missing.' ,
99109 } ) ;
110+ await client . stop ( ) ;
100111 } ) ;
101112 } ) ;
102113
@@ -110,6 +121,7 @@ export const runApiTests = (setup: ApiTestSetup, params: {staticOnly?: boolean}
110121 expect ( result ) . toEqual ( {
111122 bar : 'aa' ,
112123 } ) ;
124+ await client . stop ( ) ;
113125 } ) ;
114126
115127 test ( 'throws on invalid data' , async ( ) => {
@@ -118,6 +130,7 @@ export const runApiTests = (setup: ApiTestSetup, params: {staticOnly?: boolean}
118130 expect ( error ) . toMatchObject ( {
119131 message : '"foo" property missing.' ,
120132 } ) ;
133+ await client . stop ( ) ;
121134 } ) ;
122135 } ) ;
123136 }
0 commit comments