Skip to content

Commit

Permalink
Merge 43cc1fc into 15706cc
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Oct 8, 2018
2 parents 15706cc + 43cc1fc commit 6b332e2
Show file tree
Hide file tree
Showing 17 changed files with 156 additions and 188 deletions.
34 changes: 34 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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: "4"
- nodejs_version: "5"
- nodejs_version: "6"
- nodejs_version: "7"
- nodejs_version: "8"
- nodejs_version: "9"
- 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.

81 changes: 40 additions & 41 deletions examples/mocha/test/get-dogs.spec.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,74 @@
'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").Pact;
const getMeDogs = require("../index").getMeDogs;

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
}
]
];

before(() => provider.setup())
before(() => provider.setup());

after(() => provider.finalize())
after(() => provider.finalize());

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

done();
});
});

it('returns the correct response', done => {
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)
})
};
getMeDogs(urlAndPort).then(response => {
expect(response.data).to.eql(EXPECTED_BODY);
done();
}, done);
});

// verify with Pact, and reset expectations
afterEach(() => provider.verify())
})
})
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
Loading

0 comments on commit 6b332e2

Please sign in to comment.