Open GHERWQ opened 3 years ago
I couldn't agree more but I'm concerned that the framework may not be ready to handle microservices testing requirements.
I especially think about how we can test the most essential part of an application: routing.
We are struggling right now to implement integration tests for our microservices because we have no idea how to trigger a dispatch command to the application. We want to test that our routing configuration is correct - i.e. that when our microservice receives a given message pattern, the expected controller is triggered.
We have no idea how to test this because we don't know:
So, basically, we start a NestJS application and after that point, we can't communicate with it because it got no entry point for dispatching messages. At least, that's what we believe. We hopefully are wrong and have missed something obvious here.
What I've done for testing microservices, at least when it came to my OgmaInterceptor, is I created a client that would call off to my microservice server based on HTTP requests, and then made requests to the client server to trigger the rpc server. You can see the dynamic approach I took here, with the tests living here.
Another option would be to use the RPC transport's package directly (like amqp-connection-manager
, nats
, etc) and make sure to emit an event with the format Nest is expecting to see as mentioned in this tutorial. That format could definitely be added to the docs, to ensure that it's first class information, and it would allow easier integration with the framework from servers not using Nest.
Feature Request
Is your feature request related to a problem? Please describe.
Hello there. While developing a GRPC microservice, I wanted to cover the controller with tests, but unfortunately, I found very little information on the topic of testing microservices with Nest (especially when it comes to GRPC - I found only one question on StackOverflow while trying to write a simple test. Moreover, the answer linked to Nest source code..)
Describe the solution you'd like
I'd love to have some examples of tests for microservices in documentation that would ease the testing process for developers.
What is the motivation / use case for changing the behavior?
I spent whole day trying to code one test, but I didn't manage to do so :( While the docs for coding the microservice itself are available, testing is a huge part of it as well, so adding more info on testing would be a great idea IMO.