Skip to content

Commit 2a6e2f5

Browse files
committed
feat(pactFileWriteMode): add pactFileWriteMode to server. Fixes #50
1 parent 0d6816d commit 2a6e2f5

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

README.md

+89-1
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ pact.verifyPacts({
8989
pactBrokerUsername: <String>, // Username for Pact Broker basic authentication. Optional.
9090
pactBrokerPassword: <String>, // Password for Pact Broker basic authentication. Optional
9191
publishVerificationResult: <Boolean> // Publish verification result to Broker. Optional
92-
customProviderHeaders: <Array> // Header(s) to add to provider state set up and pact verification requests. eg 'Authorization: Basic cGFjdDpwYWN0'.
92+
customProviderHeaders: <Array> // Header(s) to add to provider state set up and pact verification
93+
requests. eg 'Authorization: Basic cGFjdDpwYWN0'.
9394
providerVersion: <Boolean> // Provider version, required to publish verification result to Broker. Optional otherwise.
9495
timeout: <Number> // The duration in ms we should wait to confirm verification process was successful. Defaults to 30000, Optional.
96+
pactFileWriteMode: <String> // Control how the pact file is created. One of 'overwrite', 'update' or 'merge'. Defaults to 'overwrite'.
9597
});
9698
```
9799

@@ -184,6 +186,92 @@ server.on('stop', function() { console.log('stopped'); });
184186
server.on('delete', function() { console.log('deleted'); });
185187
```
186188

189+
<<<<<<< Updated upstream
190+
=======
191+
### Provider Verification
192+
193+
Read more about [Verify Pacts](https://github.com/realestate-com-au/pact/wiki/Verifying-pacts).
194+
195+
```js
196+
var pact = require('@pact-foundation/pact-node');
197+
198+
pact.verifyPacts({
199+
...
200+
});
201+
```
202+
203+
**Options**:
204+
205+
|Parameter | Required? | Type | Description |
206+
|----------|------------|-------------|-------------|
207+
| `providerBaseUrl` | true | string | Running API provider host endpoint. |
208+
| `pactBrokerUrl` | false | string | URL to fetch the pacts if pactUrls not supplied|
209+
| `provider` | false | string | Name of the provider if fetching from a Broker|
210+
| `tags` | false | array | Array of tags, used to filter pacts from the Broker|
211+
| `pactUrls` | false | array | Array of local Pact file paths or HTTP-based URLs (e.g. from a broker). Required if not using a Broker. |
212+
| `providerStatesSetupUrl` | false | string | URL to send PUT requests to setup a given provider state|
213+
| `pactBrokerUsername` | false | string | Username for Pact Broker basic authentication|
214+
| `pactBrokerPassword` | false | string | Password for Pact Broker basic authentication |
215+
| `publishVerificationResult` | false | boolean | Publish verification result to Broker |
216+
| `customProviderHeaders` | false | array | Header(s) to add to provider state set up and pact verification `requests`. eg 'Authorization: Basic cGFjdDpwYWN0'.
217+
| `providerVersion` | false | boolean | Provider version, required to publish verification result to Broker. Optional otherwise.
218+
| `timeout` | false | number | The duration in ms we should wait to confirm verification process was successful. Defaults to 30000.
219+
220+
221+
### Pact Broker publishing
222+
223+
```js
224+
var pact = require('@pact-foundation/pact-node');
225+
var opts = {
226+
...
227+
};
228+
229+
pact.publishPacts(opts).then(function () {
230+
// do something
231+
});
232+
```
233+
234+
**Options**:
235+
236+
|Parameter | Required? | Type | Description |
237+
|-----------------------|------------|-------------|-------------|
238+
| `pactFilesOrDirs` | false | array | Array of local Pact files or directories containing them. Required. |
239+
| `pactBroker` | false | string | URL to fetch the provider states for the given provider API. Optional. |
240+
| `pactBrokerUsername` | false | string | Username for Pact Broker basic authentication. Optional |
241+
| `pactBrokerPassword` | false | string | Password for Pact Broker basic authentication. Optional, |
242+
| `tags` | false | array | An array of Strings to tag the Pacts being published. Optional |
243+
| `consumerVersion` | false | string | A string containing a semver-style version e.g. 1.0.0. Required. |
244+
245+
246+
### Stub Servers
247+
248+
Stub servers create runnable APIs from existing pact files.
249+
250+
The interface is comparable to the Mock Server API.
251+
252+
#### Create Stub Server
253+
254+
```js
255+
var pact = require('@pact-foundation/pact-node');
256+
var server = pact.createStub({
257+
...
258+
});
259+
```
260+
**Options**:
261+
262+
|Parameter | Required? | Type | Description |
263+
|-----------|------------|-------------|-------------|
264+
| pactUrls | true | array | List of local Pact files to create the stub service from|
265+
| port | false | number | Port number that the server runs on, defaults to random available port|
266+
| host | false | string | Host on which to bind the server on, defaults to 'localhost'. Supports '0.0.0.0' to bind on all IPv4 addresses on the local machine.|
267+
| log | false | string | File to log output on relative to current working directory, defaults to none|
268+
| ssl | false | boolean | Create a self-signed SSL cert to run the server over HTTPS , defaults to 'false'|
269+
| sslcert | false | string | Path to a custom self-signed SSL cert file, 'ssl' option must be set to true to use this option. Defaults false | to none|
270+
| sslkey | false | string | Path a custom key and self-signed SSL cert key file, 'ssl' option must be set to true to use this option false. Defaults to none|
271+
| cors | false | boolean | Allow CORS OPTION requests to be accepted, defaults to 'false'|
272+
273+
274+
>>>>>>> Stashed changes
187275
## Contributing
188276

189277
To develop this project, simply install the dependencies and run `npm run watch` to for continual development, linting and testing when a source file changes.

bin/pact-cli.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ cli
2121
.option("-o, --cors [boolean]", "Support browser security in tests by responding to OPTIONS requests and adding CORS headers to mocked responses. Default is false.", cli.BOOL)
2222
.option("-d, --pact-dir [directory]", "Directory to which the pacts will be written. Default is cwd.")
2323
.option("-i, --pact-version [n]", "The Pact specification version to use when writing the Pact files. Default is 1.", cli.INT)
24+
.option("-w, --pact-file-write-mode [m]", "Controls how pact files are written to disk. One of 'overwrite', 'update', 'merge'")
2425
.option("--consumer [consumerName]", "Specify consumer name for written Pact files.")
2526
.option("--provider [providerName]", "Specify provider name for written Pact files.")
2627
.action((args: any, options: any) => pact.createServer(options).start());

src/server.ts

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class Server extends events.EventEmitter {
3131
options.cors = options.cors || false;
3232
options.dir = options.dir ? path.resolve(options.dir) : process.cwd(); // Use directory relative to cwd
3333
options.host = options.host || "localhost";
34+
options.pactFileWriteMode = options.pactFileWriteMode || "overwrite";
3435

3536
// port checking
3637
if (options.port) {
@@ -135,6 +136,7 @@ export class Server extends events.EventEmitter {
135136
"cors": "--cors",
136137
"dir": "--pact_dir",
137138
"spec": "--pact_specification_version",
139+
"pactFileWriteMode": "--pact-file-write-mode",
138140
"consumer": "--consumer",
139141
"provider": "--provider"
140142
};
@@ -286,4 +288,5 @@ export interface ServerOptions extends SpawnArguments {
286288
spec?: number;
287289
consumer?: string;
288290
provider?: string;
291+
pactFileWriteMode?: "overwrite" | "update" | "merge";
289292
}

0 commit comments

Comments
 (0)