简体   繁体   中英

pact: publish pact to broker before or after finalizing

There are 2 steps I need to take at the end of my consumer test:

  1. finalize the mock server
  2. publish the pact to the broker.

At first, I was publishing before finalizing, like this:

var opts = {
  //broker info
}
pact_node.publishPacts(opts).then(() => {
  provider.finalize()
}).catch(() => {
  console.error("Could not publish pact!")
  provider.finalize()
})

What I realized about this is that finalize() is where the pact file gets written. So if I do things in this order, the first time I run the test, nothing gets published, and each subsequent time, I publish the version of the contract from the previous run. So I tried reversing the order, to finalize the mock server first, then publish:

provider.finalize().then(() => {
  console.log("Publishing pact to broker")
  pact_node.publishPacts(opts)
}).catch(() => {
  console.error("Could not finalize provider!")
})

But with this, neither the then nor the catch block ever gets executed. I don't get any messages printed to the console.

What is going on? Which order should I call these functions in, and why is the second order not working?

Publishing pacts should be definitely done after the finalize.

I would recommend you do it in a separate task altogether, not in the same code as the tests, as it should only be done from the CI, not from your local machine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM