Search code examples
mocha.jspact

All pact-js tests are failing with same errors


I am using Pact.js first time for microservice testing. I tried to follow these following examples:

  1. https://github.com/lucasmajerowicz/pact-node-example

  2. https://github.com/pact-foundation/pact-js/tree/master/examples/e2e

  3. https://github.com/pact-foundation/pact-js/tree/master/examples/mocha

In example 3; I navigate into test folder and run mocha index.spec.js But it throws the following error:

[2017-02-27T21:37:52.426Z]  INFO: pact-node@4.8.0/38629 on Meliss-MacBook-Pro.local: Creating Pact with PID: 38630
    1) "before all" hook
    2) "after all" hook


  0 passing (2s)
  2 failing

  1) The Dog API "before all" hook:
     Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.


  2) The Dog API "after all" hook:
     Error: connect ECONNREFUSED 127.0.0.1:8989
      at Object.exports._errnoException (util.js:1022:11)
      at exports._exceptionWithHostPort (util.js:1045:20)
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)

It creates the log and pact folders as expected, but it neither creates a pact.json file in the pact folder nor logs files in the log folder.

What confuses me more is I get the exact same error in examples 1 and 2. This tells me that I have an issue on my side but I don't know what it is. Can someone help me to debug the issue?


Solution

  • Can you please try the following?

    1. Increase the tests timeout (currently at 2s)
    2. set logLevel: 'DEBUG' in any pact({...}) declarations
    3. Re-run the tests

    And provide us a gist of the output.

    It seems the Ruby mock server is not starting or is taking longer than 2 seconds, and the node process is timing out waiting for it to come up.

    If that doesn't work, please try manually starting the mock service ./node_modules/bin/pact-mock-service --port 1234 and when it comes up, run the command netstat -an | grep LISTEN | grep 1234 so that we can see what network it is binding to.