Skip to content

Commit

Permalink
Merge 8bb61dc into 15706cc
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Oct 9, 2018
2 parents 15706cc + 8bb61dc commit fd7fca5
Show file tree
Hide file tree
Showing 19 changed files with 186 additions and 198 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
language: node_js
node_js:
- '4'
- '5'
- '6'
- '7'
- '8'
- '9'
- '10'
os:
- linux
Expand Down
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Read [Getting started with Pact] for more information for beginners.

- [Pact JS](#pact-js)
- [Installation](#installation)
- [Versions](#versions)
- [Using Pact JS](#using-pact-js)
- [HTTP API Testing](#http-api-testing)
- [Consumer Side Testing](#consumer-side-testing)
Expand Down Expand Up @@ -77,18 +76,12 @@ Read [Getting started with Pact] for more information for beginners.

## Installation

## Versions

| Version | Stable | [Spec] Compatibility | Docs | Installation |
| ------- | ---------------- | -------------------- | ------------- | ------------------------------------------- |
| `6.x.x` | Yes | `2`, `3`\* | You are here | `npm i -S @pact-foundation/pact@latest` |
| `5.x.x` | Yes (deprecated) | `2` | See [v5] docs | `npm i -S @pact-foundation/pact@5.x.x` |
| `4.x.x` | Yes (deprecated) | Up to `2` | See [v4] docs | `npm i -S pact` |
```
npm i -S @pact-foundation/pact@latest
```

See the [Changelog] for versions and their history.

_\* v3 support is limited to the subset of functionality in the v3 [spec] required to enable language inter-operable [Message support]._

## Using Pact JS

Pact supports [synchronous request-response style HTTP interactions](#http-api-testing) and [asynchronous interactions](#asynchronous-api-testing) with JSON-formatted payloads.
Expand Down
30 changes: 30 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# build version format
version: "{build}"

# fix lineendings in Windows
init:
- git config --global core.autocrlf input

# Test against these versions of Node
environment:
matrix:
- nodejs_version: "6"
- nodejs_version: "8"
- nodejs_version: "10"

platform:
- x64

matrix:
fast_finish: true
skip_tags: true
skip_branch_with_pr: true

# Setup Node environment
install:
- ps: Install-Product node $env:nodejs_version $env:platform
- npm install

# Run custom build script instead of MSBuild
build_script:
- powershell .\scripts\build.ps1
5 changes: 3 additions & 2 deletions examples/ava/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"description": "Ava Pact example",
"main": "index.js",
"scripts": {
"test": "if [ -d 'pacts' ]; then rm -rf pacts; fi && ava"
"test": "rimraf pacts && ava"
},
"license": "MIT",
"devDependencies": {
"ava": "^0.21.0",
"axios": "^0.14.0"
"axios": "^0.14.0",
"rimraf": "^2.6.2"
}
}
5 changes: 3 additions & 2 deletions examples/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"build": "tsc",
"clean": "if [ -d 'pacts' ]; then rm -rf pacts; fi",
"clean": "rimraf pacts",
"test": "npm run clean && npm run test:consumer && npm run test:publish && npm run test:provider",
"test:consumer": "nyc --check-coverage --reporter=html --reporter=text-summary mocha consumer.spec.ts",
"test:publish": "node publish.js",
Expand Down Expand Up @@ -37,6 +37,7 @@
"@types/mocha": "^2.2.41",
"chai": "^4.1.2",
"mocha": "^5.1.1",
"nyc": "^11.6.0"
"nyc": "^11.6.0",
"rimraf": "^2.6.2"
}
}
2 changes: 1 addition & 1 deletion examples/jest/pactSetup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path')
const Pact = require('../../dist/pact').Pact

global.port = 8989
global.port = 8991
global.provider = new Pact({
port: global.port,
log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
Expand Down
7 changes: 4 additions & 3 deletions examples/messages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"build": "tsc",
"clean": "if [ -d 'pacts' ]; then rm -rf pacts; fi",
"clean": "rimraf pacts",
"test": "npm run test:consumer && npm run test:publish && npm run test:provider",
"test:consumer": "nyc --check-coverage --reporter=html --reporter=text-summary mocha consumer/*.spec.ts",
"test:provider": "nyc --check-coverage --reporter=html --reporter=text-summary mocha -t 10000 provider/*.spec.ts",
Expand All @@ -16,7 +16,8 @@
"devDependencies": {
"@types/mocha": "^2.2.41",
"chai": "^3.5.0",
"mocha": "^3.5.3",
"nyc": "^11.6.0"
"mocha": "^5.1.1",
"nyc": "^11.6.0",
"rimraf": "^2.6.2"
}
}
8 changes: 1 addition & 7 deletions examples/mocha/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Mocha example

The Mocha example is a really simple demonstration of the use of Pact in Mocha tests, as well as a demonstration of running parallel tests.

Note that the two Dog API endpoints have separate tests, but are for the same consumer/provider pair.

Each test is fully self-contained, yet the result of running both creates a union of the two test cases in the generated pact file.

This is achieved by setting `pactfileWriteMode: 'merge'`, which instructs Pact to merge any documents with the same consumer and provider pairing at the end of all test runs. Note that you need to create a separate mock server on a different port for each test.
The Mocha example is a really simple demonstration of the use of Pact in Mocha tests.
6 changes: 3 additions & 3 deletions examples/mocha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"description": "Mocha Pact example",
"main": "index.js",
"scripts": {
"test": "if [ -d 'pacts' ]; then rm -rf pacts; fi && mocha-parallel-tests"
"test": "rimraf pacts && mocha"
},
"license": "MIT",
"devDependencies": {
"axios": "^0.14.0",
"chai": "^3.5.0",
"mocha": "^3.5.3",
"mocha-parallel-tests": "^1.2.10"
"mocha": "^5.1.1",
"rimraf": "^2.6.2"
}
}
70 changes: 0 additions & 70 deletions examples/mocha/test/get-dog_1.spec.js

This file was deleted.

92 changes: 66 additions & 26 deletions examples/mocha/test/get-dogs.spec.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,87 @@
'use strict'
"use strict";

const expect = require('chai').expect
const path = require('path')
const Pact = require('../../../dist/pact').Pact
const getMeDogs = require('../index').getMeDogs
const expect = require("chai").expect;
const path = require("path");
const { Pact } = require("../../../dist/pact");
const { getMeDogs, getMeDog } = require("../index");

describe('The Dog API', () => {
let url = 'http://localhost'
const port = 8989
describe("The Dog API", () => {
let url = "http://localhost";
const port = 8992;

const provider = new Pact({
port: port,
log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
dir: path.resolve(process.cwd(), 'pacts'),
log: path.resolve(process.cwd(), "logs", "mockserver-integration.log"),
dir: path.resolve(process.cwd(), "pacts"),
spec: 2,
consumer: 'MyConsumer',
provider: 'MyProvider',
pactfileWriteMode: 'merge'
})
consumer: "MyConsumer",
provider: "MyProvider",
pactfileWriteMode: "merge"
});

const EXPECTED_BODY = [{
const EXPECTED_BODY = [
{
dog: 1
},
{
dog: 2
}
]
];

// Setup the provider
before(() => provider.setup());

before(() => provider.setup())
// Write Pact when all tests done
after(() => provider.finalize());

// verify with Pact, and reset expectations
afterEach(() => provider.verify());

describe("get /dogs", () => {
before(done => {
const interaction = {
state: "i have a list of dogs",
uponReceiving: "a request for all dogs",
withRequest: {
method: "GET",
path: "/dogs",
headers: {
Accept: "application/json"
}
},
willRespondWith: {
status: 200,
headers: {
"Content-Type": "application/json"
},
body: EXPECTED_BODY
}
};
provider.addInteraction(interaction).then(() => {
done();
});
});

after(() => provider.finalize())
it("returns the correct response", done => {
const urlAndPort = {
url: url,
port: port
};
getMeDogs(urlAndPort).then(response => {
expect(response.data).to.eql(EXPECTED_BODY);
done();
}, done);
});
});

describe('get /dogs', () => {
describe('get /dog/1', () => {
before(done => {
const interaction = {
state: 'i have a list of dogs',
uponReceiving: 'a request for all dogs',
uponReceiving: 'a request for a single dog',
withRequest: {
method: 'GET',
path: '/dogs',
path: '/dogs/1',
headers: {
'Accept': 'application/json'
}
Expand All @@ -62,14 +105,11 @@ describe('The Dog API', () => {
url: url,
port: port
}
getMeDogs(urlAndPort)
getMeDog(urlAndPort)
.then(response => {
expect(response.data).to.eql(EXPECTED_BODY)
done()
}, done)
})

// verify with Pact, and reset expectations
afterEach(() => provider.verify())
})
})
});
7 changes: 4 additions & 3 deletions examples/serverless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Example testing a serverless app with Pact",
"main": "index.js",
"scripts": {
"clean": "if [ -d 'pacts' ]; then rm -rf pacts; fi",
"clean": "rimraf pacts",
"test": "npm run test:consumer && npm run test:publish && npm run test:provider",
"test:consumer": "mocha consumer/*.spec.js",
"test:provider": "mocha -t 10000 provider/*.spec.js",
Expand All @@ -19,8 +19,9 @@
},
"devDependencies": {
"chai": "^3.5.0",
"mocha": "^3.5.3",
"serverless": "^1.26.1"
"mocha": "^5.1.1",
"serverless": "^1.26.1",
"rimraf": "^2.6.2"
},
"keywords": [
"pact",
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "MIT",
"devDependencies": {
"@types/mocha": "^2.2.41",
"mocha": "^3.5.3",
"mocha": "^5.1.1",
"nyc": "^11.9.0"
},
"dependencies": {
Expand Down

0 comments on commit fd7fca5

Please sign in to comment.