:blob-wave: I'm putting the finishing touches on m...
# pact-js
g
blob wave I'm putting the finishing touches on my team's first contract tests between sort of a frontend server (consumer, js) and a backend monolith (provider, java). both sides are complex enough that ideally I could organize the tests that make up the contract into separate files. there's an example for doing this in java providers, but there's no examples for doing this in js. based on searching through the slack archives, there were some examples at https://github.com/pact-foundation/pact-js/blob/master/README.md#splitting-tests-across-multiple-files. currently, I have 2 test files that are each creating their own pact with the provider, which as I understand it won't work (it's also.. not working). is there an accepted or preferred way to divvy up js test files for better organization for the consumer side of a pact? (I can provide examples of what I do have)
m
There's nothing too fancy required here. You need to give the provider the same name (otherwise you'll get multiple different pact files). 1. Clear out the pact files before test runs 2. You can reuse (if you like) the Pact (or Pact V3, V4) instance across those files 3. Be sure not to specify a port so you don't get port conflicts and can run in parallel if needed
g
hmmm, ok we appear to be doing that. although looking at this more closely when I went to copy paste it into here, it seems like we are specifically trying to use V2? I didn't write these originally so I'm not sure. (this is copied in each test file)
Copy code
const provider = new PactV3({
  consumer: PACT_CONSUMER,
  provider: PACT_MONOLITH_PROVIDER,
  log: path.resolve(process.cwd(), 'logs', 'pact.log'),
  logLevel: 'warn',
  dir: '__build__/pact/pacts',
  spec: SpecificationVersion.SPECIFICATION_VERSION_V2,
  host: '127.0.0.1',
});
but if this isn't the problem maybe it's a pact-jvm question for the provider
m
What problem are you seeing?
g
Originally it was (I think) having too many pact tests defined on the java/provider side so I was seeing a 2x2 matrix of results. After trying to fix that on the provider side I was still seeing one of the consumer tests fail in a way that I thought meant I needed to combine something on that side too. But since apparently you can define multiple consumer tests, I went back to the provider and realized I hadn't fully implemented the example - specifically I hadn't added my 2nd controller as an argument in
target.setControllers()
. Which definitely explained why the consumer test for that controller was receiving a 404 in response.
👍 1
This was all late Friday (for me) so I was going to follow back up this morning anyways - it was unrelated to the pact-js side but it was really helpful to double check that the js consumer side doesn't need to do the same type of massaging to have multiple test files
👍 1