Pact-js: Question: Why is this being deprecated, what's the new functionality?

Created on 13 Jun 2019  路  9Comments  路  Source: pact-foundation/pact-js

In https://github.com/pact-foundation/pact-js/blob/master/src/pact-web.ts we see:

if (!isEmpty(this.opts.consumer) || !isEmpty(this.opts.provider)) {
      console.warn(`Passing in consumer/provider to PactWeb is deprecated, and will be removed in the next major version`)
}

If passing in the provider (or consumer) for an individual test is going to be removed, how do we write tests for different providers?

This works great but if it is actually going to be removed then how do we get the same results as passing in the provider like this?

All 9 comments

The reason is that when you actually start the mock server (I'm not sure how you're doing that in your specific scenario), you specify the consumer and provider there anyway. So this is just duplicating those parameters.

e.g. in Karma Pact you can start multiple providers, and you specify the consumer/provider there:

module.exports = function (config) {
  config.set({
    // in here we are simply telling to use Jasmine with Pact
    frameworks: ['jasmine', 'pact'],
    // the Pact options will go here, you can start
    // as many providers as you need
    pact: [{
        port: 1234,
        consumer: "some-consumer",
        provider: "some-provider",
        dir: "pact/files/go/here",
        log: "log/files/go/here"
    }],
    // ensure Pact and default karma plugins are loaded
    plugins: [
      'karma-*',
      '@pact-foundation/karma-pact',
    ],
  });
};

Thanks for the quick answer! I think I mainly missed where you can specify a directory.

Thanks!

No worries!

Hey looking at this again.

I thought the directory was where your test/spec files would go.

I have some specs that are for one provider, and some specs that are for another provider.
I can separate these into different directories, but how do I specify that one mock server uses one directory while the other uses a different one?

@mefellows

The deprecated functionality allowed me to mark in each of the spec what their provider was.

How do I do that now? Do I somehow reference one of the mock servers inside of my spec? Inside the Pact object?

The examples still reference the deprecated code, specifying which provider they are using

https://github.com/pact-foundation/pact-js/blob/master/examples/mocha/test/get-dogs.spec.js

I could specify the port of each of the specs to be the designated mock server. This may work.

Any better ideas?

I think specifying the ports works, from what I can tell.

Let me know if there's a better/different way.

No, that's the correct way. You setup separate mock servers for each consumer/provider pair, which gets allocated its own port. In the test, you just specify the correct port and you're good to go.

I'll fix the examples in the repo - you're quite right about that.

Was this page helpful?
0 / 5 - 0 ratings