A simple Node project implementing Pact to integration tests.
- Express
- Typescript
- Jest
- Pact
Pact is a code-first tool for testing HTTP and message integrations using contract tests. Contract tests assert that inter-application messages conform to a shared understanding that is documented in a contract. Without contract testing, the only way to ensure that applications will work correctly together is by using expensive and brittle integration tests.
Do you set your house on fire to test your smoke alarm? No, you test the contract it holds with your ears by using the testing button. Pact provides that testing button for your code, allowing you to safely confirm that your applications will work together without having to deploy the world first.
- Clone the project on your machine.
git clone https://github.com/iannsantos/pact-node
- Go to directories
account-api
andclient-api
and executeyarn install
(ornpm install
) to install necessary packages. - Go to directory
infrastructure
withdocker-compose.yml
for up Postgres and Pact Broker containers.
docker-compose up
- To start with tests, go to
client-api
directory and executeyarn test ; yarn pact:publish
to generate Pact Contract and publish it on Pact Broker. To view this result, go tohttp://localhost
, you should see something like this:
Also you'll see the Pact contract JSON file on client-api/pacts
.
- And to validate the generated contract, go to
account-api
, executeyarn dev:server
(let it run) and executeyarn test
, this will run verifier Pact contract and publish the result on Pact Broker. To see, go again tohttp://localhost
and you should see something like this:
- How to Pact works: https://docs.pact.io/how-pact-works#slide-1
- Pact Documentation: https://docs.pact.io/
- Pact Flow: https://pactflow.io/
- Pact Broker: https://github.com/pact-foundation/pact_broker
- POC with Java: https://github.com/vinirib/zup-pact-workshop