Skip to content

Commit 5f2c851

Browse files
committed
chore(docs): add section on pact-web usage
1 parent 07a6c2d commit 5f2c851

1 file changed

Lines changed: 59 additions & 20 deletions

File tree

README.md

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,29 @@ how to get going.
2424

2525
**NOTE: This project supersedes [Pact Consumer JS DSL](https://github.com/DiUS/pact-consumer-js-dsl).**
2626

27-
<!-- TOC depthFrom:1 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 -->
27+
<!-- TOC -->
2828

2929
- [Pact JS](#pact-js)
30-
- [Installation](#installation)
31-
- [Using Pact JS](#using-pact-js)
32-
- [Using Mocha?](#using-mocha)
33-
- [Consumer Side Testing](#consumer-side-testing)
34-
- [API](#api)
35-
- [Example](#example)
36-
- [Provider API Testing](#provider-api-testing)
37-
- [Publishing Pacts to a Broker](#publishing-pacts-to-a-broker)
38-
- [Flexible Matching](#flexible-matching)
39-
- [Match by regular expression](#match-by-regular-expression)
40-
- [Match based on type](#match-based-on-type)
41-
- [Match based on arrays](#match-based-on-arrays)
42-
- [Examples](#examples)
43-
- [Troubleshooting](#troubleshooting)
44-
- [Timeout](#timeout)
45-
- [Note on Jest](#note-on-jest)
46-
- [Contributing](#contributing)
47-
- [Contact](#contact)
30+
- [Installation](#installation)
31+
- [Using Pact JS](#using-pact-js)
32+
- [Using Mocha?](#using-mocha)
33+
- [Consumer Side Testing](#consumer-side-testing)
34+
- [API](#api)
35+
- [Example](#example)
36+
- [Provider API Testing](#provider-api-testing)
37+
- [Publishing Pacts to a Broker](#publishing-pacts-to-a-broker)
38+
- [Flexible Matching](#flexible-matching)
39+
- [Match by regular expression](#match-by-regular-expression)
40+
- [Match based on type](#match-based-on-type)
41+
- [Match based on arrays](#match-based-on-arrays)
42+
- [Examples](#examples)
43+
- [Using Pact in non-Node environments](#using-pact-in-non-node-environments)
44+
- [Using Pact with Karma](#using-pact-with-karma)
45+
- [Troubleshooting](#troubleshooting)
46+
- [Timeout](#timeout)
47+
- [Note on Jest](#note-on-jest)
48+
- [Contributing](#contributing)
49+
- [Contact](#contact)
4850

4951
<!-- /TOC -->
5052

@@ -222,7 +224,7 @@ let opts = {
222224
pactBroker: <String>, // URL to fetch the provider states for the given provider API. Optional.
223225
pactBrokerUsername: <String>, // Username for Pact Broker basic authentication. Optional
224226
pactBrokerPassword: <String>, // Password for Pact Broker basic authentication. Optional
225-
consumerVersion: <String> // A string containing a semver-style version e.g. 1.0.0. Required.
227+
consumerVersion: <String> // A string containing a semver-style version e.g. 1.0.0. Required.
226228
};
227229

228230
pact.publishPacts(opts)).then(function () {
@@ -369,6 +371,43 @@ provider.addInteraction({
369371

370372
[![asciicast](https://asciinema.org/a/105793.png)](https://asciinema.org/a/105793)
371373

374+
## Using Pact in non-Node environments
375+
376+
Pact requires a Node runtime to be able to start and stop Mock servers, write logs and other things.
377+
378+
However, when used within browser or non-Node based environments - such as with Karma or ng-test
379+
- this is not possible.
380+
381+
To address this challenge, we have released a separate 'web' based module for this purpose - `pact-web`.
382+
Whilst it still provides a testing DSL, it cannot start and stop mock servers as per the `pact`
383+
package, so you will need to coordinate this yourself prior to and after executing any tests.
384+
385+
To get started, install `pact-web` and [Pact Node](https://github.com/pact-foundation/pact-node):
386+
387+
npm install --save-dev pact-web pact-node
388+
389+
If you're not using Karma, you can start and stop the mock server using [Pact Node](https://github.com/pact-foundation/pact-node) or something like [Grunt Pact](https://github.com/pact-foundation/grunt-pact).
390+
391+
### Using Pact with Karma
392+
393+
We have create a [plugin](https://github.com/pact-foundation/karma-pact) for Karma,
394+
which will automatically start and stop any Mock Server for your Pact tests.
395+
396+
Modify your `karma.conf.js` file as per below to get started:
397+
398+
```js
399+
// Load pact framework - this will start/stop mock server automatically
400+
frameworks: ['pact'],
401+
402+
// load pact web
403+
files: [
404+
'node_modules/pact-web/pact-web.js',
405+
...
406+
]
407+
```
408+
409+
Check out the [Examples](/pact-foundation/pact-js#examples) for how to use the Karma interface.
410+
372411
## Troubleshooting
373412

374413
If you are having issues, a good place to start is setting `logLevel: 'DEBUG'`

0 commit comments

Comments
 (0)