https://github.com/you54f/deno-pact
Pact 🔗 Contract Testing for Deno 🦕, Powered by Rust 🦀
https://github.com/you54f/deno-pact
cdc cdct contract-testing deno deno-grpc ffi grpc interop pact rust testing ts typescript
Last synced: 10 months ago
JSON representation
Pact 🔗 Contract Testing for Deno 🦕, Powered by Rust 🦀
- Host: GitHub
- URL: https://github.com/you54f/deno-pact
- Owner: YOU54F
- License: mit
- Created: 2022-12-07T02:16:39.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-22T23:02:53.000Z (over 2 years ago)
- Last Synced: 2025-04-18T08:34:47.072Z (11 months ago)
- Topics: cdc, cdct, contract-testing, deno, deno-grpc, ffi, grpc, interop, pact, rust, testing, ts, typescript
- Language: TypeScript
- Homepage: https://deno.land/x/pact
- Size: 2.13 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Deno Pact



Try out Deno-Pact in your browser, via our [interactive tutorial](https://killercoda.com/deno-pact/course/tutorials/deno-pact)
## Pre-Reqs
You need to
[Download](https://github.com/pact-foundation/pact-reference/releases?q=%22Pact+FFI+Library%22&expanded=true)
the
[Pact FFI](https://github.com/pact-foundation/pact-reference/tree/master/rust/pact_ffi#pact-ffi)
Library for your platform
| OS | Architecture | Supported |
| ------- | ------------ | --------- |
| OSX | x86_64 | ✅ |
| OSX | arm | ✅ |
| Linux | x86_64 | ✅ |
| Linux | arm | ✅ |
| Windows | x86_64 | ✅ |
```sh
deno run -A --unstable https://deno.land/x/pact/src/downloadFfi.ts --run
```
- Checks if it exists in `${HOME}/.pact/ffi/`
- Downloads the necessary library for your architecture
- Executes the library to ensure it works
You can also do this in code
```ts
import { downloadFfiForPlatform } from "https://deno.land/x/pact/src/mod.ts";
await downloadFfiForPlatform();
```
## How to get started
- `touch helloPactDeno.ts`
```ts
import { DenoPact, Pact } from "https://deno.land/x/pact/src/mod.ts";
const denoPact = new DenoPact();
console.log(denoPact.getPactFfiVersion());
```
- `deno run -A --unstable helloPactDeno.ts`
### Egg Users
You can install via nest.land - Check the [package](https://nest.land/package/pact) for the latest version
```sh
import { DenoPact, Pact } from "https://x.nest.land/pact@0.0.6/src/mod.ts"
```
## Examples
There is a handy helper script to run the examples
Try `./run help` for available commands or take a look at the [run](./run)
script
### gRPC Area Calculator
- The Proto File -
[area_calculator.proto](./src/usage/areaCalculator/area_calculator.proto)
- The Server -
[areaCalculatorServer.ts](./src/usage/areaCalculator/areaCalculatorServer.ts)
- The Client -
[areaCalculator/areaCalculatorClient.ts](./src/usage/areaCalculator/areaCalculatorClient.ts)
- The Client Pact test
[areaCalculatorClientTest.ts](./src/usage/areaCalculatorClientTest.ts)
- The Server Pact verification
[areaCalculatorProviderTest.ts](./src/usage/areaCalculatorProviderTest.ts)
### gRPC Greeter
- The Proto File - [greeter.proto](./src/usage/greeter/greeter.proto)
- The Server - [greeterServer.ts](./src/usage/greeter/greeterServer.ts)
- The Client - [greeterClient.ts](./src/usage/greeter/greeterClient.ts)
- The Client Pact test [greeterClientTest.ts](./src/usage/greeterClientTest.ts)
### HTTP service - Swagger Mock Validator
- The Service -
[swaggerMockValidatorService.ts](./src/usage/swaggerMockValidator/swaggerMockValidatorService.ts)
- The Service Unit Test -
[swaggerMockValidatorService.test.ts](./src/usage/swaggerMockValidator/swaggerMockValidatorService.test.ts)
- The Server -
[swaggerMockValidatorServer.ts](./src/usage/swaggerMockValidator/swaggerMockValidatorServer.ts)
- The Server Integration Test -
[swaggerMockValidatorServer.test.ts](./src/usage/swaggerMockValidator/swaggerMockValidatorServer.test.ts)
- The Client Pact test
[swaggerMockValidatorServer.consumer.pact.ts](./src/usage/swaggerMockValidator/swaggerMockValidatorServer.consumer.pact.ts)
- The Server Pact verification
[swaggerMockValidatorServer.provider.pact.ts](./src/usage/swaggerMockValidator/swaggerMockValidatorServer.provider.pact.ts)
### Pact Verifications
- Pact verification task, tests multiple transport protocols
[verifier.test.ts](./src/usage/verifier.test.ts)
### Docker
You can spin up various services with Docker to help you play around with the
pact files generated, and the examples
- Pact Broker via Deno [pactBroker.ts](./docker/pactBroker.ts)
- Pact Broker via Docker-Compose
[docker-compose.yml](./docker/docker-compose.yml)