grpc-node icon indicating copy to clipboard operation
grpc-node copied to clipboard

mock grpc response

Open jmjpro opened this issue 2 years ago • 1 comments

I would like the ability to provide a mocked gRPC API response instead of calling the real gRPC API.

As much as possible, I would like to call the gRPC API in the same way as I call it now, with the obvious difference of specifying the response that I want (as a JSON object).

I searched, but I haven't seen anyone discussing this. Does it exist already?

jmjpro avatar Jun 19 '23 15:06 jmjpro

I can share my method, calling to a mock server. Example code:

      import { startServerDynamically } from 'grpc-test-helper';

      const { server, port } = await startServerDynamically({
        PBFile: pb,
        serviceName,
      });

I used it to test my in-house load balancer. You can check the source code here

edvardchen avatar Jul 17 '23 04:07 edvardchen