Hi there. I have some pretty basic questions. I re...
# pact-js
j
Hi there. I have some pretty basic questions. I read through the docs and watched the videos and was able to write my first pact test for the consumer, put that test in CI and use the publishing steps to get it on pact broker Now I see it on pact broker but it's unverified So, I started setting it up on my provider and it's a bit confusing Is the goal on the provider side to create a test that also adds a file in its own pact directory? And this is basically the same as a regular api test except it's named .pact and has pact language in it? Or is the goal that the provider verifies the pact file in the broker and doesn't create it's own pact json? Like when I run my CI in the provider and it looks for a pact file (which it doesn't find currently so it fails), is it looking for a pact file in itself to publish or is it looking for a pact file generated by the consumer? Is can-i-deploy necessary in the MVP or can i not worry about it just yet? I'd like to just prove this out.
m
Or is the goal that the provider verifies the pact file in the broker and doesn’t create it’s own pact json in a pact folder with interaction data?
verification takes a pact file, and the Pact stands in for the consumer and executes test against the locally running provider. If it passes, the results are sent back to the broker (in a CI setup, you wouldn’t normally publish from local - but fine for your tests)
can-i-deploy isn’t necessary for MVP
The guide for starting out and getting to “nirvana” is here: https://docs.pact.io/pact_nirvana
👀 1
j
ok, thanks. So it seems like i was on the right track. My MVP was just literally this:
Copy code
const { Verifier } = require('@pact-foundation/pact')
const path = require('path')

let port
let opts

describe('Provider Tests', () => {
  beforeAll(() => {
    port = 4000
    opts = {
      provider: 'services',
      consumer: 'company',
      providerBaseUrl: `<http://localhost>:${port}`,
      dir: path.resolve(process.cwd(), 'pacts')
    }
  })

  it('tests the createCustomTask mutation', async () => {
 
    await new Verifier(opts).verifyProvider()
  })
})
And it seems like I should at least get past the 'file not found error' i'm seeing in CI before I worry about making the provider pact more complicated
and troubleshoot from the stance of this is that the provider probably just doesn't see the broker because likely some variable or setting that's incorrect
m
Those options don’t look like they’re valid for the provider side.
☝️ 1
There is a (more complicated) end-to-end example here: https://github.com/pactflow/example-provider/
👀 1
see also howtoexamples for many more
s
m
The options on the provider side are: https://docs.pact.io/implementation_guides/javascript/docs/provider#verification-options (but if you use VS code or a modern IDE you should get auto completion there)
☝️ 1
j
Thanks. This is not super easy for me, I'm not a developer. And the person who set it up before me only created one working pact but it's in ruby.
🙏 1
y
I would really advise working alongside a developer especially when first implementing pact, it will save you alot of time.
pactUrls
is the option you should provide with a link to the consumer pact file you wish to verify (assuming it in on the same machine or you have copied the file to it)
j
I have pactBroker so I think in that case pactUrl is just the pactBrokerUrl. The file is up on pact broker so I think all I need to do is figure out how to start the provider service correctly. Devs have their own work so it's always hit or miss whether I can get any pairing or help.