https://github.com/kwishna/pact-contract-testing-nodejs
API contract testing using Pact
https://github.com/kwishna/pact-contract-testing-nodejs
api-testing contract-testing expressjs pact rest-api webservices
Last synced: about 2 months ago
JSON representation
API contract testing using Pact
- Host: GitHub
- URL: https://github.com/kwishna/pact-contract-testing-nodejs
- Owner: kwishna
- Created: 2024-06-22T22:21:15.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-16T15:25:23.000Z (almost 2 years ago)
- Last Synced: 2025-05-20T07:32:06.291Z (about 1 year ago)
- Topics: api-testing, contract-testing, expressjs, pact, rest-api, webservices
- Language: JavaScript
- Homepage:
- Size: 43.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
Command line explaination :-
```bash
npm install
```
This command starts the Pact Broker in a Docker container, accessible at http://localhost:9292.
```bash
docker-compose up -d
```
```plaintext
ecommerce/
├── product-service/
│ ├── productService.js
│ ├── products.json
│ └── test/
│ └── providerPactTest.js
├── order-service/
│ ├── orderService.js
│ ├── consumerClient.js
│ ├── orders.json
│ └── test/
│ └── consumerPactTest.js
└── pacts/
```
This command starts the order service on port 8080.
```bash
node order-service/orderService.js
```
This command starts the product service on port 8081.
```bash
node product-service/productService.js
```
This command runs the consumer tests, generating Pact files based on the interactions.
```bash
mocha order-service/test/consumerPactTest.js
```
This command publishes the generated Pact files to the Pact Broker. [If using broker server]
```bash
node publishPacts.js
```
This command fetches the Pact files from the Pact Broker and verifies them against the running Product Service.
```bash
mocha product-service/test/providerPactTest.js
```
```json
"scripts": {
"start-product": "node product-service/productService.js",
"start-order": "node order-service/orderService.js",
"test-consumer": "mocha order-service/test/consumerPactTest.js",
"test-provider": "mocha product-service/test/providerPactTest.js",
"publish-pacts": "node publishPacts.js"
}
```
```bash
npm run start-product # Start the Product Service
npm run start-order # Start the Order Service
npm run test-consumer # Run Consumer Pact Tests
npm run publish-pacts # [Optional] Publish Pacts to Broker only if Broker server is running
npm run test-provider # Run Provider Verification Tests
```