vendredi 21 septembre 2018

Black box testing a Node process making external requests with Jest

I am currently working on a project where we have a backend process running (with process.env.NODE_ENV = 'test') and then test the backend by running a Jest instance which makes calls to the backend process. The current code base is not unit testable in its current state. There is a lot of technical debt, and we have only started implementing black box tests recently in an effort to help our team move faster.

One of the things that we are having trouble testing is whether the backend process makes a proper request, appropriate amount of times, to external source under specific conditions. Additionally, to help us implement new features and make changes with confidence, we would really like a way to peer into the black box internals to at least test if certain blocks of code have been hit.

We thought about the following solutions, but are unsure if they are good practices or how to best implement them with Node and Jest:

1) Build a socket utility that for the backend that will only run when NODE_ENV==='test'. The socket utility will emit events that we can listen for within Jest to confirm the correct actions are occurring.

2) Running the backend process through a proxy and somehow configuring Jest to see outbound requests the backend makes.

Any advice or tools we could use would be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire