Skip to content

Commit 2b9053c

Browse files
committed
feat(mock-service): pass arguments to CLI not API
- Passes arguments through CLI instead of API. - Deprecates consumer/provider in MockService.ts - Passes consumer/provider through the underlying mock server CLI. Fixes #105
1 parent 9ca25de commit 2b9053c

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
]
7979
},
8080
"dependencies": {
81-
"@pact-foundation/pact-node": "^6.4.1",
81+
"@pact-foundation/pact-node": "^6.5.0",
8282
"cli-color": "^1.1.0",
8383
"lodash": "^4.17.4",
8484
"lodash.isfunction": "3.0.8",

src/dsl/mockService.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { logger } from "../common/logger";
99
import { Request } from "../common/request";
1010
import { Interaction } from "./interaction";
1111

12-
export type PactfileWriteMode = "overwrite" | "update" | "none";
12+
export type PactfileWriteMode = "overwrite" | "update" | "merge";
1313

1414
export interface Pacticipant {
1515
name: string;
@@ -32,21 +32,19 @@ export class MockService {
3232
* @param {number} port - the mock service port, defaults to 1234
3333
* @param {string} host - the mock service host, defaults to 127.0.0.1
3434
* @param {boolean} ssl - which protocol to use, defaults to false (HTTP)
35-
* @param {string} pactfileWriteMode - 'overwrite' | 'update' | 'none', defaults to 'overwrite'
35+
* @param {string} pactfileWriteMode - 'overwrite' | 'update' | 'merge', defaults to 'overwrite'
3636
*/
3737
constructor(
38+
// Deprecated as at https://github.com/pact-foundation/pact-js/issues/105
3839
private consumer?: string,
3940
private provider?: string,
41+
42+
// Valid
4043
private port = 1234,
4144
private host = "127.0.0.1",
4245
private ssl = false,
4346
private pactfileWriteMode: PactfileWriteMode = "overwrite") {
4447

45-
if (isEmpty(consumer) || isEmpty(provider)) {
46-
logger.warn("Warning: Consumer\Provider details not provided, ensure " +
47-
"that the mock service has been started with this information");
48-
}
49-
5048
this.request = new Request();
5149
this.baseUrl = `${ssl ? "https" : "http"}://${host}:${port}`;
5250
this.pactDetails = {

src/pact-web.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,12 @@ export class PactWeb {
3737

3838
this.opts = { ...defaults, ...config } as PactOptionsComplete;
3939

40-
if (isEmpty(this.opts.consumer) || isEmpty(this.opts.provider)) {
41-
logger.info(`Setting up Pact using mock service on port: "${this.opts.port}"`);
42-
} else {
43-
logger.info(`Setting up Pact with Consumer "${this.opts.consumer}" and Provider
44-
"${this.opts.provider}" using mock service on port: "${this.opts.port}"`);
40+
if (!isEmpty(this.opts.consumer) || !isEmpty(this.opts.provider)) {
41+
logger.warn(`Passing in consumer/provider to PactWeb is deprecated,
42+
and will be removed in the next major version`);
4543
}
4644

47-
logger.info(`Setting up Pact with Consumer "${this.opts.consumer}" and Provider "${this.opts.provider}"
48-
using mock service on Port: "${this.opts.port}"`);
45+
logger.info(`Setting up Pact using mock service on port: "${this.opts.port}"`);
4946

5047
this.mockService = new MockService(this.opts.consumer, this.opts.provider, this.opts.port, this.opts.host,
5148
this.opts.ssl, this.opts.pactfileWriteMode);

src/pact.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,14 @@ export class Pact {
5656
}
5757

5858
this.server = serviceFactory.createServer({
59+
consumer: this.opts.consumer,
5960
cors: this.opts.cors,
6061
dir: this.opts.dir,
6162
host: this.opts.host,
6263
log: this.opts.log,
64+
pactfileWriteMode: this.opts.pactfileWriteMode,
6365
port: this.opts.port,
66+
provider: this.opts.provider,
6467
spec: this.opts.spec,
6568
ssl: this.opts.ssl,
6669
sslcert: this.opts.sslcert,
@@ -71,7 +74,7 @@ export class Pact {
7174
logger.info(`Setting up Pact with Consumer "${this.opts.consumer}" and Provider "${this.opts.provider}"
7275
using mock service on Port: "${this.opts.port}"`);
7376

74-
this.mockService = new MockService(this.opts.consumer, this.opts.provider, this.opts.port, this.opts.host,
77+
this.mockService = new MockService(undefined, undefined, this.opts.port, this.opts.host,
7578
this.opts.ssl, this.opts.pactfileWriteMode);
7679
}
7780

0 commit comments

Comments
 (0)