pact-foundation / pact-js

JS version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
https://pact.io
Other
1.63k stars 346 forks source link

Issue publishing pact to broker #31

Closed shavo007 closed 7 years ago

shavo007 commented 7 years ago

Hi,

I have a sample project that I recently upgraded to 2.2.0.

https://github.com/shavo007/pact-demo/tree/dev-lees-js-consumer-upgrade/jsConsumer

If i run gulp pact the error in the logs is:

[10:45:45] Finished 'createPacts' after 8.63 s
[10:45:45] Starting 'publishPacts'...
[2017-03-13T23:45:45.139Z] ERROR: pact-node@4.8.0/90149
    Could not retrieve all Pact contracts:
      - Invalid Pact contract "pacts/js_consumer-provider1.json":
    Error: Cannot find module 'pacts/js_consumer-provider1.json'
    --
    Error: Could not retrieve all Pact contracts:
      - Invalid Pact contract "pacts/js_consumer-provider1.json":
    Error: Cannot find module 'pacts/js_consumer-provider1.json'
        at /Users/shanelee/java-projects/pact-demo/jsConsumer/node_modules/@pact-foundation/pact-node/src/publisher.js:63:16

I see the pact exists at jsConsumer/pacts/js_consumer-provider1.json

The opts defined in gulpfile are:

var opts = {
    pactUrls: ['pacts'],               // Array of local Pact files or directories containing them. Required.
    pactBroker: 'http://localhost',
    consumerVersion: '1.0'            // URL to fetch the provider states for the given provider API. Optional.
};

ENV:

Node: v7.5.0
"pact": "^2.2.0"

Any clue?

Thanks. Shane.

mefellows commented 7 years ago

Ah, the pactUrls requires the path to be absolute in the latest version. I'll update the docs accordingly, but for now patching your publish task like this should fix your problem:

var path = require('path');
pactUrls: [path.resolve(process.cwd(), 'pacts')],
shavo007 commented 7 years ago

that worked perfectly. thanks.

out of interest, @mefellows why is it absolute now instead of relative?

shavo007 commented 7 years ago

i will leave this issue opened for now until the doc has been updated.

mefellows commented 7 years ago

Thanks @shavo007, I'll follow up on that, short answer is I'm not sure.

shavo007 commented 7 years ago

No worries mate

mefellows commented 7 years ago

Looks like it was an unintended consequence (albeit if you provided it with a directory it needed to be absolute anyway), I'll raise an enhancement request. It seems fairly low priority though.

shavo007 commented 7 years ago

👍

jonathanconway commented 7 years ago

Can there not just be some sensible defaults around this kind of stuff? Like make pactUrls optional and just default it to /pacts under your project root?

mefellows commented 7 years ago

Probably, we'll happily accept a PR if you're willing :)

jonathanconway commented 7 years ago

Thanks for the opportunity! Very keen to. Hopefully soon!