Skip to content

Commit

Permalink
feat(pactFileWriteMode): add pactFileWriteMode to server. Fixes #50
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Dec 10, 2017
1 parent 0d6816d commit 0f8658b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ pact.verifyPacts({
pactBrokerUsername: <String>, // Username for Pact Broker basic authentication. Optional.
pactBrokerPassword: <String>, // Password for Pact Broker basic authentication. Optional
publishVerificationResult: <Boolean> // Publish verification result to Broker. Optional
customProviderHeaders: <Array> // Header(s) to add to provider state set up and pact verification requests. eg 'Authorization: Basic cGFjdDpwYWN0'.
customProviderHeaders: <Array> // Header(s) to add to provider state set up and pact verification
requests. eg 'Authorization: Basic cGFjdDpwYWN0'.
providerVersion: <Boolean> // Provider version, required to publish verification result to Broker. Optional otherwise.
timeout: <Number> // The duration in ms we should wait to confirm verification process was successful. Defaults to 30000, Optional.
pactFileWriteMode: <String> // Control how the pact file is created. One of 'overwrite', 'update' or 'merge'. Defaults to 'overwrite'.
});
```

Expand Down
1 change: 1 addition & 0 deletions bin/pact-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cli
.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)
.option("-d, --pact-dir [directory]", "Directory to which the pacts will be written. Default is cwd.")
.option("-i, --pact-version [n]", "The Pact specification version to use when writing the Pact files. Default is 1.", cli.INT)
.option("-w, --pact-file-write-mode [m]", "Controls how pact files are written to disk. One of 'overwrite', 'update', 'merge'")
.option("--consumer [consumerName]", "Specify consumer name for written Pact files.")
.option("--provider [providerName]", "Specify provider name for written Pact files.")
.action((args: any, options: any) => pact.createServer(options).start());
Expand Down
6 changes: 6 additions & 0 deletions src/server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ describe("Server Spec", () => {
sslkey: path.resolve(__dirname, "../test/ssl/server.key")
})).to.throw(Error);
});

it("should fail if incorrect pactFileWriteMode provided", () => {
expect(() => serverFactory({
pactFileWriteMode: "notarealoption",
})).to.throw(Error);
});
});

context("when valid options are set", () => {
Expand Down
6 changes: 6 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class Server extends events.EventEmitter {
options.cors = options.cors || false;
options.dir = options.dir ? path.resolve(options.dir) : process.cwd(); // Use directory relative to cwd
options.host = options.host || "localhost";
options.pactFileWriteMode = options.pactFileWriteMode || "overwrite";

// port checking
if (options.port) {
Expand Down Expand Up @@ -119,6 +120,9 @@ export class Server extends events.EventEmitter {
checkTypes.assert.string(options.provider);
}

// pactFileWriteMode check
checkTypes.assert.includes(["overwrite", "update", "merge"], options.pactFileWriteMode);

return new Server(options);
}

Expand All @@ -135,6 +139,7 @@ export class Server extends events.EventEmitter {
"cors": "--cors",
"dir": "--pact_dir",
"spec": "--pact_specification_version",
"pactFileWriteMode": "--pact-file-write-mode",
"consumer": "--consumer",
"provider": "--provider"
};
Expand Down Expand Up @@ -286,4 +291,5 @@ export interface ServerOptions extends SpawnArguments {
spec?: number;
consumer?: string;
provider?: string;
pactFileWriteMode?: "overwrite" | "update" | "merge";
}

0 comments on commit 0f8658b

Please sign in to comment.