1

I have an application which uses NodeJs Cluster module to fork multiple processes of the app, each of these process send out post request to an endpoint which i want to nock.

Now i understand that nock works by overwriting the nodes process http.request methods, but since I am using Cluster.fork which in turn spawns a new NodeJs process which are independent of the parent NodeJs process.

Is there anyway i can nock out this request that my forked processes make ?

  • I'm curious if you've tried it yet and if there were any errors thrown? I don't know how Cluster works that well, but I would be surprised if the node procs where sharing a module cache, which is what what need to happen for Nock to work. – Matt R. Wilson Apr 30 '20 at 15:22
  • Yes i have tried it, with no success the nocked endpoint is not called. Yeh this is what i assumed that underlying fork which creates new node process will create its own module cache. I assume this is not a feature that nock will be looking to support in the future. – Cameron Newby May 01 '20 at 09:17
  • "looking to support in the future": Maybe, I recommenced opening a feature request here https://github.com/nock/nock/issues but from a technical POV I'm not sure it's possible. The only discussion remotely related I see was here https://github.com/nock/nock/issues/990 – Matt R. Wilson May 02 '20 at 01:42

0 Answers0