File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -6,20 +6,24 @@ import { readGrpcRequest } from './read-grpc-request';
6
6
export async function mockGrpcUnary (
7
7
page : Page ,
8
8
rpc : UnaryMethodDefinitionish ,
9
- response : GrpcResponse | ( ( request : Uint8Array | null ) => GrpcResponse ) ,
9
+ response :
10
+ | GrpcResponse
11
+ | Promise < GrpcResponse >
12
+ | ( ( request : Uint8Array | null ) => GrpcResponse | Promise < GrpcResponse > ) ,
10
13
mockAtContextLevel : boolean = false ,
11
14
) : Promise < MockedGrpcCall > {
12
15
const url = `/${ rpc . service . serviceName } /${ rpc . methodName } ` ;
13
16
14
17
// note this wildcard route url base is done in order to match both localhost and deployed service usages.
15
- await ( mockAtContextLevel ? page . context ( ) : page ) . route ( '**' + url , ( route ) => {
18
+ await ( mockAtContextLevel ? page . context ( ) : page ) . route ( '**' + url , async ( route ) => {
16
19
expect ( route . request ( ) . method ( ) , 'ALL gRPC requests should be a POST request' ) . toBe ( 'POST' ) ;
17
20
18
- const grpcResponse = typeof response === 'function' ? response ( readGrpcRequest ( route . request ( ) ) ) : response ;
21
+ const grpcResponseWrapped = typeof response === 'function' ? response ( readGrpcRequest ( route . request ( ) ) ) : response ;
22
+ const grpcResponse = await Promise . resolve ( grpcResponseWrapped ) ;
19
23
20
24
const grpcResponseBody = grpcResponseToBuffer ( grpcResponse ) ;
21
25
22
- return route . fulfill ( {
26
+ return await route . fulfill ( {
23
27
body : grpcResponseBody ,
24
28
contentType : 'application/grpc-web+proto' ,
25
29
headers : {
You can’t perform that action at this time.
0 commit comments