All Projects → YOU54F → jest-pact-typescript

YOU54F / jest-pact-typescript

Licence: MIT License
A PACT consumer example written in TypeScript with Jest

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects
Dockerfile
14818 projects
Makefile
30231 projects
go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to jest-pact-typescript

chuck
Lightweight proxy for REST API mocking and run integration test on mobile devices
Stars: ✭ 17 (-22.73%)
Mutual labels:  mock-server
mock-algolia
A mock server for the Algolia search engine allowing integration testing without the need to hit Algolia's actual servers
Stars: ✭ 18 (-18.18%)
Mutual labels:  mock-server
pactum
REST API Testing Tool for all levels in a Test Pyramid
Stars: ✭ 190 (+763.64%)
Mutual labels:  mock-server
kb-proxy
kb-proxy 是一个可本地部署的、提供代理功能、接口测试管理、支持在线Mock、Host环境管理的在线工具平台。
Stars: ✭ 52 (+136.36%)
Mutual labels:  mock-server
mock-json-server
A mock web server using a JSON file with live-reload support.
Stars: ✭ 31 (+40.91%)
Mutual labels:  mock-server
open-api-mocker
A mock server based in OpenAPI Specification
Stars: ✭ 58 (+163.64%)
Mutual labels:  mock-server
Endpoint2mock
Android library which simplifies mocking of Retrofit endpoints
Stars: ✭ 16 (-27.27%)
Mutual labels:  mock-server
mocky
Mocky is a simple API mocking solution written in PHP.
Stars: ✭ 29 (+31.82%)
Mutual labels:  mock-server
json-server
Create a dummy REST API from a json file with zero coding in seconds
Stars: ✭ 34 (+54.55%)
Mutual labels:  mock-server
any-mock
A configurable mock server,help you mock APIs.
Stars: ✭ 25 (+13.64%)
Mutual labels:  mock-server
karate
Test Automation Made Simple
Stars: ✭ 6,384 (+28918.18%)
Mutual labels:  mock-server
manta-style
🚀 The futuristic API Mock Server for Frontend
Stars: ✭ 41 (+86.36%)
Mutual labels:  mock-server
Mockaco
🐵 HTTP mock server, useful to stub services and simulate dynamic API responses, leveraging ASP.NET Core features, built-in fake data generation and pure C# scripting
Stars: ✭ 213 (+868.18%)
Mutual labels:  mock-server
main
Mocks Server monorepo
Stars: ✭ 109 (+395.45%)
Mutual labels:  mock-server
mockify
Easy, configurable API mocking you can change on-the-fly
Stars: ✭ 83 (+277.27%)
Mutual labels:  mock-server
wiremock
A tool for mocking HTTP services
Stars: ✭ 5,239 (+23713.64%)
Mutual labels:  mock-server
rusqbin
A server that stashes your requests for later retrieval so you can do end-to-end testing of code that makes HTTP calls. Available as a binary, a Docker image, and a library.
Stars: ✭ 25 (+13.64%)
Mutual labels:  mock-server
servirtium-java
Service Virtualized HTTP - to help service test automation stay fast and consistent
Stars: ✭ 16 (-27.27%)
Mutual labels:  mock-server
gmocker
Create a blazing fast mock server with just a JSON file
Stars: ✭ 49 (+122.73%)
Mutual labels:  mock-server
pytest-mock-server
Mock server plugin for pytest
Stars: ✭ 19 (-13.64%)
Mutual labels:  mock-server

Pact Consumer Workflow Example in Typescript with Jest

CircleCI

Showcases the following

  • 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)
  • Tags validated contracts with branch name
  • 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

Where can I see it

Installation

  • clone repository
  • Run yarn install

Run pact tests

  • Run yarn run pact-test

Validate Swagger spec

  • Run yarn run swagger-validate-spec

Validate Pact contract against Swagger spec

  • Run yarn run swagger-validate-pact

Publish pacts

  • Run pact-publish

Tag pacts

  • Run pact-tag

Start the mock server

  • Run docker-compose up

Set the following env vars for pact publishing

  • PACT_BROKER_BASE_URL
  • PACT_BROKER_TOKEN

Create postman collections from pacts

  • run ./postman/postman-pact.sh to generate postman collections in pact/postman/collections
  • run ./postman/postman-replace-urls.sh to generate env configs for postman in pact/postman/env where the urls are replaced with $PACT_PROVIDER_URL
  • run ./postman/postman-newman.sj 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.

Build your own Pact Stub Service for your pacts in Docker

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

Credits

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].