I'm trying to run a test for the provider but I ke...
# pact-js
a
I'm trying to run a test for the provider but I keep getting this error
Copy code
1) Pact verification:
     TypeError [ERR_INVALID_URL]: Invalid URL
      at new NodeError (node:internal/errors:372:5)
      at URL.onParseError (node:internal/url:553:9)
      at new URL (node:internal/url:629:5)
      at Verifier.isLocalVerification (node_modules\@pact-foundation\pact\src\dsl\verifier.js:302:17)
      at Verifier.setConfig (node_modules\@pact-foundation\pact\src\dsl\verifier.js:295:23)
      at Verifier.verifyProvider (node_modules\@pact-foundation\pact\src\dsl\verifier.js:86:18)
      at Context.<anonymous> (test\provider.spec.js:27:25)     
      at processImmediate (node:internal/timers:466:21
Line 27 is the return line below
Copy code
return new Verifier(opts).verifyProvider().then(() => {
      console.log("Pacts verified and published");
  });
m
so the error seems to be pretty clear to me. What options have you given the verifier?
a
Copy code
let opts = {
      pactBroker: "<http://hijazi.pactflow.io>",
      provider: "Node API (Provider)",
      consumerVersionTags: ["main"],
      publishVerificationResult: true, //generally you'd do something like `<http://process.env.CI|process.env.CI> === 'true'`
      providerVersion: "version 1.0",  //recommended to be the git sha
      providerVersionTag: "1.0",
      stateHandlers: {
          //If you have defined any states in your consumer tests, the Verifier can put the provider into the 
          //right state prior to sending the request.
      },
      beforeEach: () => {
          console.log('I run before everything else')
        },
      
        afterEach: () => {
          console.log('I run after everything else has finished')
        }
  
  };
m
You need to pass the
providerBaseUrl
argument
i.e. the thing you are testing
a
As another option?
m
it’s an attribute of
opts
a
right, let me try, thanks
👍 1
m
it should be a URL pointing to your locally running HTTP provider
a
This is my output
Copy code
Error: Must provide the pactUrls argument if no pactBrokerUrl provided
pactBroker is provided though
m
read the error message carefully
pactBroker
is not
pactBrokerUrl
🔫 1
😵 1
There are TS types if you’re using an IDE which should help
a
Also I realised, if I put
return
the pact doesn't pass, and even when it does pass, it's not calling my API This is my verifier method without
return
Copy code
new Verifier(opts).verifyProvider()
.then(output => {
        console.log("Pacts verified and published");
        console.log(output);
})
m
what do you mean by “return”? I think you might be saying
return new Verifier(opts)…
. If so, you must do that, otherwise you’re not properly handling the promise. If you don’t know what that means, I highly suggest you pair with a developer
and even when it does pass, it’s not calling my API
So to help you understand what might be going wrong, i’d suggest following the debugging guide in the readme and coming back here with the information you’ve found