An example test framework using PactJS to validate contract testing between consumer and provider. The application that we are testing is a simple movies API which returns a list of movies. Please feel free to fork the repo to help with your contract testing learning.
Install dependencies:
npm i
Run the movies API:
npm run start:provider
On another terminal, run:
npm run start:graphql:server
We are using Pactflow as the Pact broker. To use Pactflow , register for their free developer plan and export your Pactflow Broker URL and API token:
export PACT_BROKER_URL=<PACT_BROKER_URL here>
export PACT_API_TOKEN=<API_TOKEN here>
Run the web consumer tests:
npm run test:web:consumer
Publish the contract to your pact broker:
npm run publish:pact
Run the provider tests:
npm run test:provider
Run the GraphQL consumer tests:
npm run test:graphql:consumer
To run the tests as part of a CI pipeline using GitHub actions, store the PACT_BROKER_URL and PACT_API_TOKEN as secrets to your forked repo.