DiUS / pact-consumer-js-dsl

*DEPRECATED* A Javascript DSL for creating pacts, superceded by Pact JS
https://github.com/pact-foundation/pact-js
Other
56 stars 26 forks source link

Clarify example to cause a pact file to be written #51

Closed rgm closed 8 years ago

rgm commented 8 years ago

Without all three of the --consumer, --producer, and --pact-dir flags, it appears that the mock service won't actually write a pact file on shutdown.

I spelunked the source of pact-mock-provider a while scratching my head on why I wasn't getting anything written.

bethesque commented 8 years ago

Hm, it should. The JS DSL should send through that information.

bethesque commented 8 years ago

There should be a "write" call at the end of the suite (or somewhere) that causes the pact to be written. The "write on shutdown" was just a nice to have feature.

rgm commented 8 years ago

Sorry, I must not be understanding something right... it looked to me like run would do this on cleanup by calling into verifyAndWrite:

https://github.com/DiUS/pact-consumer-js-dsl/blob/f40d40b9433f1d65a13d8b5f956669e23ac268c4/src/mockService.js#L95

bethesque commented 8 years ago

Yes, there is an explicit call from the JS code to write the pact, that's why the hook on shutdown isn't needed by the JS DSL. This line sends through the consumer and provider, that's why they aren't needed as arguments when starting the mock service: https://github.com/DiUS/pact-consumer-js-dsl/blob/f40d40b9433f1d65a13d8b5f956669e23ac268c4/src/mockService.js#L60

rgm commented 8 years ago

OK, thanks for your help. I added a Mocha hook

after(() => {
  mockProvider.verifyAndWrite((err) => {
    if (err) {
      console.warn('Pact wasn\'t able to verify the interactions: \n' + err);
    } else {
      console.log('Pact verified and written.');
    }
  });
});

which seems to work so I don't need to give those flags. I'm adding a link to the relevant spot in the node example, just in case anyone else happens along this PR, and closing without merge.