Skip to content

Commit

Permalink
Merge branch 'master' into 5.x.x
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Aug 19, 2018
2 parents df0ab0a + 78aac94 commit 46bb23a
Show file tree
Hide file tree
Showing 13 changed files with 845 additions and 603 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ env:
matrix:
- CXX=g++-4.8
global:
# NPM KEY
- secure: NikiOMeibEpwVk4mLdXxCDm4jknLWZQQACSwHPlotB0u9JRzlyIoJhm47uzlPnKMtCylV0DMXQo32qbuv2xTIbB0cuZqcTzJaE2pQPHpnsVOrUnOlzRF0bSyRZGY/22ELQxWgK2Jc94lWBiniHbZzLeRh/iSAShj/lmUgVRXgUg1bxjdPNDOb3A+QNMMTl8NIp9FajsOp1l+2RXOZaJZwZChMnB+jLIMk4C56onV+rTn4EvxM/6mY0tOD+fO78Qz72riAcP8CSm/POlwTd/LcKdjtV+A6udPmuetZEy+4SWRF82WsWvU9RTytkr4kgct/uD7Y1oBVS9FMMBndS0YV6GSRnz4nwSUfAGJC93cijcrBzMRJxJ8+lYDMNPmED352RfIo68Lnrp73fXii2KMbyrSDFZUxaP4BMJu2LgUTBbk1+mxcEZMwByR2ZGEZMI7XXft1t2rMLWbWd9Ppo1XlT4XsJ6sLQHdU8/XDq4Zz7s4TVUnhNSpHqRUHQlpUxsvncUo7JgLoB9VzUIA8hK6Vs6/zKvCLgTew330vjDFTQCl473OlsfuFBpqHLBc57kfWbaugvan5OW1RXUpydoptX5tmIIIfWe8XbyKKCBK+fS9LO7qQaYlsPDyjQqJ+IXBRd239odNia/ke6F9Pkvcdt2Z/NEqDtuN9azKy+LHGT8
# travis encrypt NPM_KEY=<key>
- secure: "dadftjIY7w+KRucMDOqflXYTvWI1WYvtLtvGnbJuoFrgviax5zhwI7rSi6PTvW7mqV05FtqfVVb8Mgkwp1GNhv9byzuPCKnX6zN/tnl3mC++ivMA3BI7KhNp6VinzVeHWN+9BSYAQs1RQbslIK6IJ3oQJ9azp1MnxMQ1s0w5hqo0ojPWRJsm/IN57/pSiR4U0yyvONdwVg7Q8RQmyMZtovA2QzrR3ij6IxBwiJ7RQXsWIYkPL1SzaIqNNhMOdXK3m1iCESmtNc1BG9oEoaZc0ZzowT/O5VVPWe+bUfdSaAHjkTauaMCU2OAk6J89yd7pSCT5fe1YYYPgTIZiPkG0wQH8k7dKqqeaxBo+tN7uCfkYlTMNZmjv+qVBafoP8wBV97g3UugDqqIXaFknTUDnSNaigcJjFRWhCHBtltR+hzF6pCl3H1o1dDnmJWrgEb01qJ0lZonmaK/anZGNpUWE6qndOKBwnd0XiR1LnvzL/7tdflNb4DPy+lWdDEj4HWZR3lFA009m651qHBN+117ousZFXJ1866JywkAM2GrEWD4umzKknXDhulMG/Q32DS01BgW1pMenzQkH5WE+O0T3W/8BPw0Ev//bqZIg0gDckppUexHZ+pMhAFMaJfCzYVhrA0fhwLb+1EW7VDEcQIc0QHGXOb3Vclja7qB4yDuAJxk="
script: ./scripts/build.sh
after_success:
- npm run coverage
Expand Down
69 changes: 48 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[![Coverage Status](https://coveralls.io/repos/github/pact-foundation/pact-js/badge.svg?branch=master)](https://coveralls.io/github/pact-foundation/pact-js?branch=master)
[![Code Climate](https://codeclimate.com/github/pact-foundation/pact-js/badges/gpa.svg)](https://codeclimate.com/github/pact-foundation/pact-js)
[![Issue Count](https://codeclimate.com/github/pact-foundation/pact-js/badges/issue_count.svg)](https://codeclimate.com/github/pact-foundation/pact-js)
[![Dependency Status](https://gemnasium.com/badges/github.com/pact-foundation/pact-js.svg)](https://gemnasium.com/github.com/pact-foundation/pact-js)
[![npm](https://img.shields.io/github/license/pact-foundation/pact-js.svg?maxAge=2592000)](https://github.com/pact-foundation/pact-js/blob/master/LICENSE)
[![slack](http://slack.pact.io/badge.svg)](http://slack.pact.io)

Expand All @@ -28,8 +27,7 @@ how to get going.

- [Pact JS](#pact-js)
- [Installation](#installation)
- [Latest (5.x.x)](#latest-5xx)
- [Stable (4.x.x)](#stable-4xx)
- [Versions](#versions)
- [Using Pact JS](#using-pact-js)
- [Message and Asynchronous Support](#message-and-asynchronous-support)
- [Consumer Side Testing](#consumer-side-testing)
Expand Down Expand Up @@ -59,32 +57,31 @@ how to get going.
- [Re-run specific verification failures](#re-run-specific-verification-failures)
- [Timeout](#timeout)
- [Note on Jest](#note-on-jest)
- [Debugging](#debugging)
- [Contributing](#contributing)
- [Contact](#contact)

<!-- /TOC -->

## Installation

### Latest (5.x.x)
## Versions

```
npm install --save-dev @pact-foundation/pact
```

_NOTE_: the `5.x.x` release contains several breaking changes from the previous version and will be maintained in parallel with the previous stable version. See the [`4.x.x`](https://github.com/pact-foundation/pact-js/tree/4.x.x) documentation for more details.
| Version | Stable | [Spec] Compatibility | Docs | Installation |
| ----------| ---------------- | -------------------- | ------------------- | --------------------------------------------|
| `6.x.x` | No (beta) | `2`, `3`* | See [v6] docs | `npm i -S @pact-foundation/pact@prerelease` |
| `5.x.x` | Yes | `2` | You are here | `npm i -S @pact-foundation/pact@5.x.x` |
| `4.x.x` | Yes (deprecated) | Up to `2` | See [v4] docs | `npm i -S pact` |

### Stable (4.x.x)
See the [Changelog] for versions and their history.

```
npm install --save-dev pact
```

See [`4.x.x` documentation](https://github.com/pact-foundation/pact-js/tree/4.x.x) for usage details.
_* v3 support is limited to the subset of functionality in the [Pact Specification v3] required to enable language inter-operable [Message support]._

## Using Pact JS

### Message and Asynchronous Support

Interested in trying pact on Message Queues, Lambdas, WebSockets and more? Check out our [experimental support](https://github.com/pact-foundation/pact-js/tree/feat/message-pact) and provide [feedback](https://github.com/pact-foundation/pact-js/issues/166) on the API before it is rolled into the main library.
Interested in trying pact on Message Queues, Lambdas, WebSockets and more? Check out our [experimental support](https://github.com/pact-foundation/pact-js/tree/6.x.x) in the `6.x.x` release and provide [feedback](https://github.com/pact-foundation/pact-js/issues/166) on the API before it is rolled into the main library.

### Consumer Side Testing

Expand All @@ -97,6 +94,7 @@ const { Pact } = require('pact')
The `Pact` class provides the following high-level APIs, they are listed in the order in which they typically get called in the lifecycle of testing a consumer:

#### API

|API |Options |Returns|Description |
|-----------------------|------------|------------------------------------------------------|---|
|`new Pact(options)` |See constructor options below |`Object` |Creates a Mock Server test double of your Provider API. If you need multiple Providers for a scenario, you can create as many as these as you need. |
Expand Down Expand Up @@ -124,6 +122,7 @@ The `Pact` class provides the following high-level APIs, they are listed in the
| `pactfileWriteMode` | no | string | Control how the Pact files are written. Choices: 'overwrite' 'update' or 'none'. Defaults to 'overwrite'|

#### Example

The first step is to create a test for your API Consumer. The example below uses [Mocha](https://mochajs.org), and demonstrates the basic approach:

1. Create the Pact object
Expand All @@ -136,6 +135,10 @@ The first step is to create a test for your API Consumer. The example below uses
Check out the `examples` folder for examples with Karma Jasmine, Mocha and Jest. The example below is taken from the [integration spec](https://github.com/pact-foundation/pact-js/blob/master/src/pact.integration.spec.ts).

```javascript
/**
* The following example is for Pact version 5
*/

const path = require('path')
const chai = require('chai')
const { Pact } = require('@pact-foundation/pact')
Expand Down Expand Up @@ -215,8 +218,9 @@ describe('Pact', () => {
// (6) write the pact file for this consumer-provider pair,
// and shutdown the associated mock server.
// You should do this only _once_ per Provider you are testing.
after(() => {
after((done) => {
provider.finalize()
.then(() => done())
})
})
})
Expand Down Expand Up @@ -652,7 +656,7 @@ You have a number of options to achieve this feat:
See this [example](https://github.com/tarciosaraiva/pact-melbjs/blob/master/helper.js) and this [issue](https://github.com/pact-foundation/pact-js/issues/11) for more.
1. Set `pactfileWriteMode` to `update` in the `Pact()` constructor
1. Set `pactfileWriteMode` to `merge` in the `Pact()` constructor
This will allow you to have multiple independent tests for a given Consumer-Provider pair, without it clobbering previous interactions, thereby allowing you to incrementally build up or modify your pact files.
Expand Down Expand Up @@ -695,6 +699,7 @@ to review your unit testing timeout to ensure it has sufficient time to start th
See [here](http://stackoverflow.com/questions/42496401/all-pact-js-tests-are-failing-with-same-errors/42518752) for more details.
### Note on Jest
Jest uses JSDOM under the hood which may cause issues with libraries making HTTP request.
You'll need to add the following snippet to your `package.json` to ensure it uses
Expand All @@ -712,7 +717,7 @@ Also, [from Jest 20](https://facebook.github.io/jest/blog/2017/05/06/jest-20-del
/**
* @jest-environment node
*/
```
```
Jest also runs tests in parallel by default, which can be problematic with Pact which is stateful. See [parallel tests](#parallel-tests) to see how to make it run in parallel, or run Jest with the `--runInBand` [option](https://facebook.github.io/jest/docs/en/cli.html#runinband) to run them sequentially.
Expand All @@ -737,6 +742,7 @@ Try starting the mock service manually and seeing if it comes up. When submittin
```
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
Expand All @@ -751,11 +757,32 @@ The vision is to have a compatible `Pact` implementation in all the commonly use
Join us in Slack
<a href="http://slack.pact.io"><img src="http://slack.pact.io/badge.svg"></a>
<a href="http://slack.pact.io">
<img src="http://slack.pact.io/badge.svg">
</a>
or
* Slack: [slack.pact.io](http://slack.pact.io)
* Twitter: [@pact_up](https://twitter.com/pact_up)
* Stack Overflow: https://stackoverflow.com/questions/tagged/pact
* Google users group: https://groups.google.com/forum/#!forum/pact-support
[Getting started with Pact]: http://dius.com.au/2016/02/03/microservices-pact/
[v4]: https://github.com/pact-foundation/pact-js/tree/4.x.x
[v5]: https://github.com/pact-foundation/pact-js/tree/5.x.x
[v6]: https://github.com/pact-foundation/pact-js/tree/6.x.x
[Spec]: https://github.com/pact-foundation/pact-specification
[Pact Wiki]: https://github.com/pact-foundation/pact-ruby/wiki
[Getting started with Pact]: http://dius.com.au/2016/02/03/microservices-pact/
[Pact website]: http://docs.pact.io/
[Slack channel]: http://slack.pact.io
[@pact_up]: https://twitter.com/pact_up
[Pact Specification v2]: https://github.com/pact-foundation/pact-specification/tree/version-2
[Pact Specification v3]: https://github.com/pact-foundation/pact-specification/tree/version-3
[CLI tools]: https://github.com/pact-foundation/pact-ruby-standalone/releases
[Installation]: #installation
[Message support]: https://github.com/pact-foundation/pact-specification/tree/version-3#introduces-messages-for-services-that-communicate-via-event-streams-and-message-queues
[Changelog]: https://github.com/pact-foundation/pact-js/blob/master/CHANGELOG.md
[Pact Broker]: https://github.com/pact-foundation/pact_broker
[hosted broker]: pact.dius.com.au
[can-i-deploy tool]: https://github.com/pact-foundation/pact_broker/wiki/Provider-verification-results
9 changes: 9 additions & 0 deletions examples/e2e/consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ const suggestion = mate => {
})
}

// Creates a mate for suggestions
const createMateForDates = (mate) => {
return request
.post(`${API_HOST}/animals`)
.send(mate)
.set('Content-Type', 'application/json; charset=utf-8')
}

// Suggestions API
server.get('/suggestions/:animalId', (req, res) => {
if (!req.params.animalId) {
Expand All @@ -77,6 +85,7 @@ server.get('/suggestions/:animalId', (req, res) => {
module.exports = {
server,
availableAnimals,
createMateForDates,
suggestion,
getAnimalById
}
Loading

0 comments on commit 46bb23a

Please sign in to comment.