Skip to content

Commit e99df17

Browse files
committed
feat: add docs and nock example
1 parent 9381ac4 commit e99df17

File tree

6 files changed

+44
-14
lines changed

6 files changed

+44
-14
lines changed

Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,10 @@ travis_encrypt_pact_broker_token:
130130

131131
.env:
132132
touch .env
133+
134+
output:
135+
mkdir -p ./pacts
136+
touch ./pacts/tmp
137+
138+
clean: output
139+
rm pacts/*

README.md

+36-10
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,44 @@
88

99
This is an example of a Node consumer using Pact to create a consumer driven contract, and sharing it via [Pactflow](https://pactflow.io).
1010

11-
It is using a public tenant on Pactflow, which you can access [here](https://test.pact.dius.com.au) using the credentials `dXfltyFMgNOFZAxr8io9wJ37iUpY42M`/`O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1`. The latest version of the Example Consumer/Example Provider pact is published [here](https://test.pact.dius.com.au/pacts/provider/pactflow-example-provider/consumer/pactflow-example-consumer/latest).
11+
It implements a "Product" website, to demonstrate the new bi-directional contract capability of Pactflow (previously referred to as Provider driven contracts, or collaborative contracts). See the [Provider](https://github.com/pactflow/example-collaborative-contracts-provider) counterpart.
1212

13-
The project uses a Makefile to simulate a very simple build pipeline with two stages - test and deploy.
1413

15-
* Test
16-
* Run tests (including the pact tests that generate the contract)
17-
* Publish pacts, tagging the consumer version with the name of the current branch
18-
* Check if we are safe to deploy to prod (ie. has the pact content been successfully verified)
19-
* Deploy (only from master)
20-
* Deploy app (just pretend for the purposes of this example!)
21-
* Tag the deployed consumer version as 'prod'
14+
It is using a public tenant on Pactflow, which you can access [here](https://test.pact.dius.com.au) using the credentials `dXfltyFMgNOFZAxr8io9wJ37iUpY42M`/`O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1`. The latest version of the Example Consumer/Example Provider pact is published [here](https://test.pact.dius.com.au/pacts/provider/pactflow-example-collaborative-contracts-provider/consumer/pactflow-example-consumer/latest).
2215

16+
In the following diagram, you can see how the consumer testing process works - it's the same as the current Pact process! (We do show an alternative using Nock's record/replay functionality)
17+
18+
When we call "can-i-deploy" the cross-contract validation process kicks off on Pactflow, to ensure any consumer consumes a valid subset of the OAS for the provider.
19+
20+
![Consumer Test](docs/consumer-scope.png "Consumer Test")
21+
22+
When you run the CI pipeline (see below for doing this), the pipeline should perform the following activities (simplified):
23+
24+
![Consumer Pipeline](docs/consumer-pipeline.png "Consumer Pipeline")
25+
26+
## Pre-requisites
27+
28+
**Software**:
29+
30+
* Tools listed at: https://docs.pactflow.io/docs/workshops/ci-cd/set-up-ci/prerequisites/
31+
* A pactflow.io account with an valid [API token](https://docs.pactflow.io/docs/getting-started/#configuring-your-api-token)
32+
33+
### Environment variables
34+
35+
To be able to run some of the commands locally, you will need to export the following environment variables into your shell:
36+
37+
* `PACT_BROKER_TOKEN`: a valid [API token](https://docs.pactflow.io/docs/getting-started/#configuring-your-api-token) for Pactflow
38+
* `PACT_BROKER_BASE_URL`: a fully qualified domain name with protocol to your pact broker e.g. https://testdemo.pactflow.io
39+
* `PACT_PROVIDER=collaborative-contracts-provider`: this changes the default provider
2340
## Usage
2441

25-
See the [Pactflow CI/CD Workshop](https://github.com/pactflow/ci-cd-workshop).
42+
### Pact use case
43+
44+
* `make test` - run the pact test locally
45+
* `make fake_ci` - run the CI process locally
46+
47+
### Nock (record/replay example)
48+
49+
* `make clean` - ensure previous pacts are cleared
50+
* `make test_nock` - run the nock test locally
51+
* `make fake_ci_nock` - run the nock version of the CI process locally

docs/consumer-pipeline.png

122 KB
Loading

docs/consumer-scope.png

238 KB
Loading

src/api.nock.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const nockBack = require("nock").back;
55
nockBack.fixtures = "fixtures";
66

77
describe("API Nock Tests", () => {
8-
test("nock recordings", (done) => {
8+
test("nock replay tests", (done) => {
99
// reuse the nock fixture
1010
nockBack(
1111
"nock.json",

src/api.record.spec.js

-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { API } from "./api";
22
import * as fs from "fs";
3-
import * as path from "path";
43

5-
//
64
const nockBack = require("nock").back;
75
nockBack.setMode("record");
86
nockBack.fixtures = "fixtures"
97

10-
118
describe("API Nock Tests", () => {
129
test("nock recordings", () => {
1310
// recording of the fixture

0 commit comments

Comments
 (0)