Pact-js: It's unclear where `Pact` constructor comes from in `pact-js/karma/jasmine/client-spec.js`

Created on 9 Oct 2017  路  8Comments  路  Source: pact-foundation/pact-js

Where does this type come from if it's not imported into the spec file? I am using Typescript and tslint and it complains that this object doesn't exist. There's not much detail as far as how to scaffold your testing suite in order to use this object aside from including pact-web.js in the files attrbiute of the karma config.

documentation question

All 8 comments

I'd also like to point out that the setup example for the karma.config file here conflicts with what is in karma/jasmine in that the former says to use pact: {} in the config yet the example in the latter does not

Yep, after the recent upgrade the documentation and examples appear to be out of date. The examples use the previous version and need to be updated (See https://github.com/pact-foundation/pact-js/issues/106#issuecomment-334727899).

Karma is a bit funny the way it works, the Pact constructor in the examples come from '../../dist-web/pact-web.js', (see https://github.com/pact-foundation/pact-js/blob/master/karma/jasmine/karma.conf.js#L16).

If you're willing and able, I'd happily accept a PR to bring these examples up to date.

I may contribute that update as part of my work using karma-pact. So if that's the new preferred way to start up the mock server in Karma, how do we access the server instance that's created through the karma config? From looking through the code it appears using Pact({consumer: ..., provider: ...}) as in the example creates a _new_ instance of the provider, in fact it says as much in pact-web.js on line 72 Creates a new {@link PactProvider}. But i'm thinking it's not supposed to?

Thanks @blackbaud-joshlandi.

pact-web is a little different. When you create a new instance of the provider, it doesn't actually start the mock server (that's what karma-pact does for you). All it does is give you a DSL to add interactions remotely to that mock server, verify they were called etc.

What's changed in the latest karma-pact, is that you can have _multiple_ servers running at the same time. In this case, you would need to explicitly set the port property when creating the Pact.

That being said, I'm having some troubles running it locally to reproduce so I might have to fix the examples in doing so. Stay tuned.

cc: @mboudreau.

OK I have a working example (working locally): https://github.com/pact-foundation/pact-js/blob/feat/pact-node-5xx/karma/mocha/client-spec.js#L10

Just waiting for builds to pass etc. (the Karma tests did: https://travis-ci.org/pact-foundation/pact-js/jobs/286991986)

Thanks! Man, you work fast. I wish I could've got to it, but work comes first or whatever.

Also, what you said about the Pact constructor makes sense. Thanks again.

TBH I got annoyed when it didn't work for me locally, and therefore it should annoy our users even more. Plus I thought I saw an even bigger problem and there's not way I'd sleep if it were real (I think it turned out to be npm package-lock.json madness - ffs).

In any case, no dramas :)

Working examples now committed in master. Closing!

Was this page helpful?
0 / 5 - 0 ratings