- Written in Typescript
- Utilises Pact in a Jest Wrapper jest-pact
- Uses Swagger to define API
- Uses Swagger-cli to validate Swagger specification
- Uses Pact.io to perform consumer driven contract tests
- Uses Swagger-mock-validator to validate generated pact contracts
- Publishes validated pact contracts to pact-broker (hosted on AWS EC2)
- Pact mock service docker base
- Pact mock service docker base examples
- circleci config
- use pmpact to generate postman collections for pact contracts
- Example pact tests
- AWS v4 Signed API Gateway Provider
- Soap API provider
- File upload API provider
- JSON API provider
- Pact mock service docker base
- Pact mock service docker base examples
- Postman integration
- Generate postman collections from pact contracts
- Inject URL into postman collection from
PACT_PROVIDER_URL
- Run postman scripts with newman
- Run postman scripts with jest
- example can-i-deploy
- CircleCI builds here - https://circleci.com/gh/YOU54F/pact-consumer-example-typescript
- Pact Broker here - https://you54f.co.uk - running on AWS Lambda (see https://github.com/YOU54F/pact_broker-serverless for details of setup)
- clone repository
- Run
yarn install
- Run
yarn run pact-test
- Run
yarn run swagger-validate-spec
- Run
yarn run swagger-validate-pact
- Run
yarn run pact-publish
- Run
cd docker && docker-compose up
- PACT_BROKER_BASE_URL
- PACT_BROKER_TOKEN
- run
./postman/postman-pact.sh
to generate postman collections inpact/postman/collections
- run
./postman/postman-replace-urls.sh
to generate env configs for postman inpact/postman/env
where the urls are replaced with$PACT_PROVIDER_URL
- run
./postman/postman-newman.sh
to run the postman collection against your$PACT_PROVIDER_URL
- run newman tests with jest, via
npx jest -c jest.newman.js
Note:- There are no tests in the saved postman collections, so it will run the requests, but will not validate the responses are as per the pacts.
TODO
- Currently this will use
$PACT_PROVIDER_URL
for all generated postman collections, add the ability to specify a provider name, and update the url accordingly.
cd docker/pact-stub-service
Build the base pact image, change the name you54f
to your own dockerhub username
The Base image resides at base.Dockerfile
which will load the pact ruby standalone, plus a healthcheck endpoint /healthcheck
on the containers for use in AWS and other Cloud providers.
make pact_build
docker build -t pact-base -f base.Dockerfile .
make pact_tag
docker tag pact-base you54f/pact-base
make pact_push
docker push you54f/pact-base
You can then copy your pact files generated with yarn run test
into the docker/pact-stub-service/pacts
folder that the Dockerfile
will use.
copy_pacts
rm -rf pacts && cp -r ../../pact/pacts .
Look at the Dockerfile
FROM you54f/pact-base
ARG PACT_FILE
COPY ${PACT_FILE} /pact.json
See the docker/docker-compose.yml
file for how to load your pacts into the docker container.
version: "3.1"
services:
pact-stub-server-json:
build:
context: pact-stub-service
args:
PACT_FILE: pacts/test-consumer-json-provider.json
ports:
- "8080:8080"
You can run it with cd docker && docker-compose up