Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

This is a sample project to demonstrate consumer driven contract testing using the PACT framework and TypeScript.

License

NotificationsYou must be signed in to change notification settings

amalsgit/typescript_pact_contract_test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a sample project to demonstrate consumer driven contract testing using the PACT framework and TypeScript.

This repo consists of aprovider service and aconsumer service. The interactions between these 2 services will be tested used PACT.

Theprovider service which is responsible for CRUD-ing & maintaining a movie database and theconsumer service makes use of the APIs exposed by theprovider to do further operations.

Project Structure

├── README.md├── consumer                                    # consumer service│   ├── jest.config.js                          # Jest test configurations│   ├── logs                                    # Logs generated by pact for debugging issues│   │   └── pact.log│   ├── package.json│   ├── src│   │   ├── actions.ts                          # Contains application business logic│   └── └── pacts            └── movies.contract.test.ts         # Contains the consumer contract tests├── contracts│   └── movie_consumer-movie_producer.json      # Generated PACT contract└── provider                                    # provider service    ├── jest.config.js                          # Jest test configurations    ├── package.json    ├── pacts    │   └── movies.contract.test.ts             # Contains the provider contract tests    ├── src    │   ├── actions.ts                          # Contains application business logic    │   ├── app.ts                              # Contains the API endpoints    │   ├── data                                # Sqlite Datastore of the service    │   ├── entity                              # TypeORM entities    └── └── server.ts                           # Server initializer

Installation

This project is written with Node version v12.18.4

Install node

https://nodejs.org/en/

Install yarn

https://classic.yarnpkg.com/en/docs/install#mac-stable

Provider SetUp

Go to the provider directory

cd provider/

Run yarn to get all the required libraries

yarn

To run the provider server run

yarn start

This brings up the application athttp://localhost:3001 You can hithttp://localhost:3001/movies to return a list of movies in the system

Consumer SetUp

Go to the consumer directory

cd consumer/

Run yarn to get all the required libraries

yarn

PACT Broker Setup

The tests require a PACT broker to be running. To start the broker run the below command from the root project directory

docker-compose up

This brings up the broker application as well a PostgreSQL database to store the contracts and verification results.

The broker app can be accessed athttp://localhost:9292/

Running Consumer Contract Tests

Go to the consumer directory

cd consumer/

Run

yarn test

The above command runs the contract tests and generates the PACT contract file under thecontracts directory

Running Provider Contract Tests

Go to the provider directory

cd provider/

Before running the provider test, you need to bring up the provider server. You can do that by running

yarn start

Once the application is up run the tests using

yarn test

The above command picks up the PACT contract file from thecontracts directory which was generated by the consumer contract tests and run the tests against the provider.

pact-cli

The docker pact-cli can be used to perform multiple functions like running the verifications, accessing the broker and also to verify whether the application can be deployed safely.

A sample command to runcan-i-deploy

docker run --rm pactfoundation/pact-cli broker can-i-deploy --pacticipant "Movie Consumer" --latest --broker-base-url http://host.docker.internal:9292

References

https://hub.docker.com/r/pactfoundation/pact-clihttps://hub.docker.com/r/pactfoundation/pact-brokerhttps://github.com/pact-foundation/pact-js

About

This is a sample project to demonstrate consumer driven contract testing using the PACT framework and TypeScript.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp