edouard-lopez / pact-consumer-example-for-typescript

pact consumer example for typescript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pact-consumer-example-for-typescript

An example of writing contract test with pact and jest-pact.

The app itself is not important, our goal is too illustrated how straightforward it is to write a contract test.

Having an integration test that check on your HTTP client. with mock (nock, msw) is really close

Tests Goal

We aim to check we are able to do a GET request on /api/customers and /api/customer/:id/orders and get the correct data shape.

Test file Description Benefits
index an integration test with a mock server (msw) - check HTTP client's plumbing
index-matcher-v2.contract a contract test using pact specs@v2 and matchers@v2 - check HTTP client's plumbing
- generate contract
index-matcher-v3.contract a contract test using pact specs@v3 and matchers@v3 - check HTTP client's plumbing
- generate contract

Install

yarn install

Usage

Run Only index.test.ts

yarn test

Run All contract tests

yarn test:contracts # both contract test files

Run Only Pact@v2 test

jest --testMatch '**/*v2.contract.test.ts'

Run Only Pact@v3 test

jest --testMatch '**/*v3.contract.test.ts'

Publish contract

requirements: [make].

To publish you need to download the Pact-CLI binary:

make install-pact-cli

Then edit the .env to fill:

PACT_BROKER_URL=https://your.broker.org/

Finally, connect to VPN and publish:

❯ make publish-contract

Repository Metadata

Follow the How to Add repo URL and main branch metadata.

About

pact consumer example for typescript

License:Apache License 2.0


Languages

Language:TypeScript 85.4%Language:Makefile 9.0%Language:JavaScript 5.6%