There are 2 steps I need to take at the end of my consumer test:
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.