Hi, I am looking at integrating pact / contract te...
# pact-js
c
Hi, I am looking at integrating pact / contract testing into a new project. Where are the examples/documentation on how to integrate provider tests with jest + supertest, or if that's not possible koa? I need to see the whole flow - i.e. 1.
beforeEach
creating the supertest instance or standing up the test server on a random ephemeral port 2. the actual provider test in a describe/it block 3.
afterEach
tearing down the supertest instance or standing down the test server
m
You don’t use supertest with Pact, because that’s a separate testing tool
howtoexamples
s
m
howtolearn
s
Here are a number of useful hands-on labs that teach all of the key concepts: https://docs.pactflow.io/docs/workshops and https://docs.pact.io/implementation_guides/workshops
m
see the learning tutorials and examples above
c
I've looked briefly through through that material. It leads to this: https://github.com/pactflow/example-provider/tree/master/src/product It uses a static port and won't work when we have concurrent tests. Also, I need to see/show that it works with Koa, not Express. I'm really just after an example I can poke, tear apart, follow to build a spike with.
m
I think you’re misunderstanding how pact works. There is a consumer side of the test, and a provider side. The consumer side doesn’t have Koa (or shouldn’t) and can be run in parallel. The tests are analogous to supertest, but you use the Pact consumer DSL instead (pointing at the pact mock server, not a real thing). This generates a pact file, which is essentially a set of tests for the provider. On the provider side, you start the API (Express, Koa etc.) and then you tell Pact to verify it. Pact uses the contract generated by the consumer, to replay against the (locally) running API
I think you should be able to extrapolate the above provider example to koa quite easily
c
I get the distinction between consumer side, the provider side and the role of a broker. I am specifically asking for a provider side example against Koa, but it appears one doesn't exist and the example you have with express uses a fixed test server port (which would preclude, e.g. running multiple tests concurrently against the provider).
m
gotcha
I don’t think that concurrency concern is a problem, because the Pact verifier doesn’t run those tests concurrently
Surely your koa server can expose a fixed port for the test?
I don’t think that concurrency concern is a problem, because the Pact verifier doesn’t run those tests concurrently
to elaborate, consider a scenario that is in conflict with another scenario. State 1: There are products State 2: There are no products Running those two examples concurrently is likely to break a scenario attached to one of them
c
Is it assumed and a constraint on the provider side that you only ever have a single verifier running all contracts from all consumers against it sequentially?
👍 1
I know that lack of concurrency (anything that slows down unit tests) will be a reason for push-back, even if the new suite replaces brittle and even slower integration tests.
m
That’s a little presumptuous, without actually seeing how fast/slow they are
They usually aren’t very slow
Is it assumed and a constraint on the provider side that you only ever have a single verifier running all contracts from all consumers against it sequentially?
you could run the verification process multiple times (and in parallel), by having each verification only verify a subset of consumers or branches (or whatever selectors you choose)