Hello Pact familly, I used Pact in the past, but I...
# pact-js
t
Hello Pact familly, I used Pact in the past, but I wanted to improve my configuration. Unfortunately, I don't know how to do the following, or if that's even possible: I have two test suites, one for unit tests (that don't use pacts), and another specifically for pacts. Is that a better practice to include my Pact tests directly into my unit tests suite (I'm wondering about watch mode too)? Also, I'm doing this because all my pact tests for a single provider-consumer pair are in the same file. This is because if I have multiple files, they override the generated Pact file, and I end up with only the expected message of the test I ran last. I'm using a
MessageConsumerPact
:
Copy code
pact = new MessageConsumerPact({
      consumer: '<consumer-name>',
      dir: path.resolve(process.cwd(), 'pacts'),
      pactfileWriteMode: 'merge',
      provider: '<provider-name>',
      logLevel: 'info',
    });
Would appreciate some help 🙏
m
With the latest version of Pact, you should be able to (more easily) split tests across files
Assuming you’re on the 9.x.x line, you could use this tip to split tests across files: https://github.com/pact-foundation/pact-js/tree/9.x.x#splitting-tests-across-multiple-files
The key trick is properly clearing out the pact files before the entire suite of tests run. But even locally it’s not that important, if you only publish pacts from CI
I have two test suites, one for unit tests (that don’t use pacts), and another specifically for pacts.
I tend to keep them separate. One of the benefits is that you can use code coverage tools to get some idea of what code paths are tested with Pact
t
Thanks a lot of the answers @Matt (pactflow.io / pact-js / pact-go) 🙏 If I keep the test suites separate I don't mind having Pact tests in the same file. Does that mean you have some overlap between your unit and pact test suites? Or some cases are not covered by unit tests but tested by Pact tests?
m
Does that mean you have some overlap between your unit and pact test suites? Or some cases are not covered by unit tests but tested by Pact tests?
Yes that can happen. I wouldn’t be too concerned about it, but I think the visibility you get by separating things out helps. I’d expect unit tests to overlap with Pact tests pretty significantly, as Pact tests (generalization) tend to be slighly higher up the testing stack than unit tests, albeit you want that “unit test” mentality.
t
Understood, thanks a lot 🙏
🙌 1