This is an example of a Node consumer using Pact to create a consumer driven contract, and sharing it via Pactflow.
It is using a public tenant on Pactflow, which you can access here using the credentials
O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1. The latest version of the Example Consumer/Example Provider pact is published here.
The project uses a Makefile to simulate a very simple build pipeline with two stages - test and deploy.
- Run tests (including the pact tests that generate the contract)
- Publish pacts, tagging the consumer version with the name of the current branch
- Check if we are safe to deploy to prod (ie. has the pact content been successfully verified)
- Deploy (only from master)
- Deploy app (just pretend for the purposes of this example!)
- Record the deployment in the Pact Broker
See the Pactflow CI/CD Workshop.
Running the application
Open a separate terminal for the consumer.
Before starting the consumer, create a
.env file in the root of the project and set the URL to point to your running provider:
npm run start
- Tools listed at: https://docs.pactflow.io/docs/workshops/ci-cd/set-up-ci/prerequisites/
- A pactflow.io account with an valid API token
To be able to run some of the commands locally, you will need to export the following environment variables into your shell:
PACT_BROKER_TOKEN: a valid API token for Pactflow
PACT_BROKER_BASE_URL: a fully qualified domain name with protocol to your pact broker e.g. https://testdemo.pactflow.io
Pact use case
make test- run the pact test locally
make fake_ci- run the CI process locally