Skip to content

Commit b1a3927

Browse files
authored
Merge pull request #66 from pact-foundation/feat/50-pactFileWriteMode
feat(pactFileWriteMode): add pactFileWriteMode to server. Fixes #50
2 parents 0d6816d + 0f8658b commit b1a3927

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

README.md

+3-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

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.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ describe("Server Spec", () => {
5454
sslkey: path.resolve(__dirname, "../test/ssl/server.key")
5555
})).to.throw(Error);
5656
});
57+
58+
it("should fail if incorrect pactFileWriteMode provided", () => {
59+
expect(() => serverFactory({
60+
pactFileWriteMode: "notarealoption",
61+
})).to.throw(Error);
62+
});
5763
});
5864

5965
context("when valid options are set", () => {

src/server.ts

+6
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) {
@@ -119,6 +120,9 @@ export class Server extends events.EventEmitter {
119120
checkTypes.assert.string(options.provider);
120121
}
121122

123+
// pactFileWriteMode check
124+
checkTypes.assert.includes(["overwrite", "update", "merge"], options.pactFileWriteMode);
125+
122126
return new Server(options);
123127
}
124128

@@ -135,6 +139,7 @@ export class Server extends events.EventEmitter {
135139
"cors": "--cors",
136140
"dir": "--pact_dir",
137141
"spec": "--pact_specification_version",
142+
"pactFileWriteMode": "--pact-file-write-mode",
138143
"consumer": "--consumer",
139144
"provider": "--provider"
140145
};
@@ -286,4 +291,5 @@ export interface ServerOptions extends SpawnArguments {
286291
spec?: number;
287292
consumer?: string;
288293
provider?: string;
294+
pactFileWriteMode?: "overwrite" | "update" | "merge";
289295
}

0 commit comments

Comments
 (0)