jeudi 22 février 2018

In node, how do I test that an external process makes an http request to a server run by my test code?

I'm writing some end-to-end tests in node. I'm spinning up a server that posts results to a configurable endpoint (kinda like a web hook). I'm trying to write tests that verify that when I send an http request to this server that the s.u.t. (system/server under test) eventually sends an http request to the specified server, which I want to be a server running in my test code (preferably, or that my test code can verify some other way). The system I'm testing is an external process (and it has a mechanism to specify where the results are sent).

the test would be something like this:

  • test code starts up server to test
  • test code sends request to s.u.t.
  • s.u.t. (hopefully) makes a request to specified endpoint
  • test code checks and verifies that s.u.t. made the correct request

Normally, you'd do something like this with nock or another http mocking tool. However, since the s.u.t. is a separate process, this doesn't help.

What is the best way to go about this? I have some idea of how to do this (make a basic server in my test code to receive requests and then check them), but I was wondering if there were tools or techniques to make this easier, particularly if there was a way to await a request to that server in my test. What would be really cool would be a tool that had an assertion library built for this purpose. Does that exist?

Aucun commentaire:

Enregistrer un commentaire