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';
66export async function mockGrpcUnary (
77 page : Page ,
88 rpc : UnaryMethodDefinitionish ,
9- response : GrpcResponse | ( ( request : Uint8Array | null ) => GrpcResponse ) ,
9+ response :
10+ | GrpcResponse
11+ | Promise < GrpcResponse >
12+ | ( ( request : Uint8Array | null ) => GrpcResponse | Promise < GrpcResponse > ) ,
1013 mockAtContextLevel : boolean = false ,
1114) : Promise < MockedGrpcCall > {
1215 const url = `/${ rpc . service . serviceName } /${ rpc . methodName } ` ;
1316
1417 // 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 ) => {
1619 expect ( route . request ( ) . method ( ) , 'ALL gRPC requests should be a POST request' ) . toBe ( 'POST' ) ;
1720
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 ) ;
1923
2024 const grpcResponseBody = grpcResponseToBuffer ( grpcResponse ) ;
2125
22- return route . fulfill ( {
26+ return await route . fulfill ( {
2327 body : grpcResponseBody ,
2428 contentType : 'application/grpc-web+proto' ,
2529 headers : {
You can’t perform that action at this time.
0 commit comments