@pact-foundation/pact 7.3.0 → 8.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/CONTRIBUTING.md +22 -9
- package/LICENSE +1 -2
- package/README.md +253 -157
- package/common/logger.js +10 -5
- package/common/logger.js.map +1 -1
- package/common/metadata.js.map +1 -1
- package/common/net.js +3 -2
- package/common/net.js.map +1 -1
- package/common/net.spec.d.ts +1 -0
- package/common/net.spec.js +47 -0
- package/common/net.spec.js.map +1 -0
- package/common/request.js +1 -2
- package/common/request.js.map +1 -1
- package/common/request.spec.d.ts +1 -0
- package/common/request.spec.js +71 -0
- package/common/request.spec.js.map +1 -0
- package/common/utils.js +1 -2
- package/common/utils.js.map +1 -1
- package/dsl/apolloGraphql.d.ts +1 -1
- package/dsl/apolloGraphql.js +6 -3
- package/dsl/apolloGraphql.js.map +1 -1
- package/dsl/apolloGraphql.spec.d.ts +1 -0
- package/dsl/apolloGraphql.spec.js +47 -0
- package/dsl/apolloGraphql.spec.js.map +1 -0
- package/dsl/graphql.js +19 -9
- package/dsl/graphql.js.map +1 -1
- package/dsl/graphql.spec.d.ts +1 -0
- package/dsl/graphql.spec.js +141 -0
- package/dsl/graphql.spec.js.map +1 -0
- package/dsl/interaction.js +9 -7
- package/dsl/interaction.js.map +1 -1
- package/dsl/interaction.spec.d.ts +1 -0
- package/dsl/interaction.spec.js +172 -0
- package/dsl/interaction.spec.js.map +1 -0
- package/dsl/matchers.d.ts +25 -25
- package/dsl/matchers.js +57 -55
- package/dsl/matchers.js.map +1 -1
- package/dsl/matchers.spec.d.ts +1 -0
- package/dsl/matchers.spec.js +537 -0
- package/dsl/matchers.spec.js.map +1 -0
- package/dsl/message.d.ts +29 -3
- package/dsl/mockService.d.ts +6 -0
- package/dsl/mockService.js +10 -4
- package/dsl/mockService.js.map +1 -1
- package/dsl/mockService.spec.d.ts +1 -0
- package/dsl/mockService.spec.js +126 -0
- package/dsl/mockService.spec.js.map +1 -0
- package/dsl/verifier.d.ts +48 -2
- package/dsl/verifier.js +142 -3
- package/dsl/verifier.js.map +1 -1
- package/dsl/verifier.spec.d.ts +1 -0
- package/dsl/verifier.spec.js +299 -0
- package/dsl/verifier.spec.js.map +1 -0
- package/errors/configurationError.d.ts +2 -0
- package/errors/configurationError.js +24 -0
- package/errors/configurationError.js.map +1 -0
- package/errors/graphQLQueryError.d.ts +2 -0
- package/errors/graphQLQueryError.js +24 -0
- package/errors/graphQLQueryError.js.map +1 -0
- package/errors/matcherError.d.ts +2 -0
- package/errors/matcherError.js +24 -0
- package/errors/matcherError.js.map +1 -0
- package/errors/verificationError.d.ts +2 -0
- package/errors/verificationError.js +24 -0
- package/errors/verificationError.js.map +1 -0
- package/httpPact.d.ts +69 -0
- package/httpPact.js +206 -0
- package/httpPact.js.map +1 -0
- package/httpPact.spec.d.ts +1 -0
- package/httpPact.spec.js +337 -0
- package/httpPact.spec.js.map +1 -0
- package/messageConsumerPact.d.ts +3 -3
- package/messageConsumerPact.js +5 -4
- package/messageConsumerPact.js.map +1 -1
- package/messageConsumerPact.spec.d.ts +1 -0
- package/messageConsumerPact.spec.js +161 -0
- package/messageConsumerPact.spec.js.map +1 -0
- package/messageProviderPact.d.ts +0 -1
- package/messageProviderPact.js +11 -11
- package/messageProviderPact.js.map +1 -1
- package/messageProviderPact.spec.d.ts +1 -0
- package/messageProviderPact.spec.js +146 -0
- package/messageProviderPact.spec.js.map +1 -0
- package/package.json +24 -26
- package/pact-web.d.ts +2 -2
- package/pact-web.js +20 -10
- package/pact-web.js.map +1 -1
- package/pact-web.spec.d.ts +1 -0
- package/pact-web.spec.js +205 -0
- package/pact-web.spec.js.map +1 -0
- package/pact.d.ts +28 -65
- package/pact.integration.spec.d.ts +0 -0
- package/pact.integration.spec.js +292 -0
- package/pact.integration.spec.js.map +1 -0
- package/pact.js +21 -189
- package/pact.js.map +1 -1
package/pact.js
CHANGED
|
@@ -1,203 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
2
|
+
/**
|
|
3
|
+
* Pact module meta package.
|
|
4
|
+
* @module Pact
|
|
5
|
+
*/
|
|
10
6
|
function __export(m) {
|
|
11
7
|
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
12
8
|
}
|
|
13
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
// TODO: Make this the main interface into the Pact package
|
|
15
|
-
// this will be a backwards-incompatible, breaking change
|
|
16
10
|
/**
|
|
17
|
-
* Pact
|
|
18
|
-
* @
|
|
11
|
+
* Exposes {@link Pact}
|
|
12
|
+
* @memberof Pact
|
|
13
|
+
* @static
|
|
19
14
|
*/
|
|
20
|
-
|
|
21
|
-
var clc = require("cli-color");
|
|
22
|
-
var Matchers = require("./dsl/matchers");
|
|
23
|
-
var path = require("path");
|
|
24
|
-
var process = require("process");
|
|
25
|
-
var interaction_1 = require("./dsl/interaction");
|
|
26
|
-
var lodash_1 = require("lodash");
|
|
27
|
-
var net_1 = require("./common/net");
|
|
28
|
-
var logger_1 = require("./common/logger");
|
|
29
|
-
var mockService_1 = require("./dsl/mockService");
|
|
15
|
+
__export(require("./httpPact"));
|
|
30
16
|
/**
|
|
31
|
-
*
|
|
17
|
+
* Exposes {@link MessageConsumerPact}
|
|
32
18
|
* @memberof Pact
|
|
33
|
-
* @
|
|
34
|
-
* @param {PactOptions} opts
|
|
35
|
-
* @return {@link PactProvider}
|
|
19
|
+
* @static
|
|
36
20
|
*/
|
|
37
|
-
var Pact = /** @class */ (function () {
|
|
38
|
-
function Pact(config) {
|
|
39
|
-
this.opts = Pact.createOptionsWithDefaults(config);
|
|
40
|
-
if (lodash_1.isEmpty(this.opts.consumer)) {
|
|
41
|
-
throw new Error("You must specify a Consumer for this pact.");
|
|
42
|
-
}
|
|
43
|
-
if (lodash_1.isEmpty(this.opts.provider)) {
|
|
44
|
-
throw new Error("You must specify a Provider for this pact.");
|
|
45
|
-
}
|
|
46
|
-
logger_1.default.level(this.opts.logLevel);
|
|
47
|
-
pact_node_1.default.logLevel(this.opts.logLevel);
|
|
48
|
-
this.server = pact_node_1.default.createServer({
|
|
49
|
-
consumer: this.opts.consumer,
|
|
50
|
-
cors: this.opts.cors,
|
|
51
|
-
dir: this.opts.dir,
|
|
52
|
-
host: this.opts.host,
|
|
53
|
-
log: this.opts.log,
|
|
54
|
-
pactFileWriteMode: this.opts.pactfileWriteMode,
|
|
55
|
-
port: config.port,
|
|
56
|
-
provider: this.opts.provider,
|
|
57
|
-
spec: this.opts.spec,
|
|
58
|
-
ssl: this.opts.ssl,
|
|
59
|
-
sslcert: this.opts.sslcert,
|
|
60
|
-
sslkey: this.opts.sslkey,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
Pact.createOptionsWithDefaults = function (opts) {
|
|
64
|
-
return __assign({}, Pact.defaults, opts);
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Start the Mock Server.
|
|
68
|
-
* @returns {Promise}
|
|
69
|
-
*/
|
|
70
|
-
Pact.prototype.setup = function () {
|
|
71
|
-
var _this = this;
|
|
72
|
-
return this.checkPort()
|
|
73
|
-
.then(function () { return _this.startServer(); })
|
|
74
|
-
.then(function (opts) {
|
|
75
|
-
_this.setupMockService();
|
|
76
|
-
return Promise.resolve(opts);
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
/**
|
|
80
|
-
* Add an interaction to the {@link MockService}.
|
|
81
|
-
* @memberof PactProvider
|
|
82
|
-
* @instance
|
|
83
|
-
* @param {Interaction} interactionObj
|
|
84
|
-
* @returns {Promise}
|
|
85
|
-
*/
|
|
86
|
-
Pact.prototype.addInteraction = function (interactionObj) {
|
|
87
|
-
if (interactionObj instanceof interaction_1.Interaction) {
|
|
88
|
-
return this.mockService.addInteraction(interactionObj);
|
|
89
|
-
}
|
|
90
|
-
var interaction = new interaction_1.Interaction();
|
|
91
|
-
if (interactionObj.state) {
|
|
92
|
-
interaction.given(interactionObj.state);
|
|
93
|
-
}
|
|
94
|
-
interaction
|
|
95
|
-
.uponReceiving(interactionObj.uponReceiving)
|
|
96
|
-
.withRequest(interactionObj.withRequest)
|
|
97
|
-
.willRespondWith(interactionObj.willRespondWith);
|
|
98
|
-
return this.mockService.addInteraction(interaction);
|
|
99
|
-
};
|
|
100
|
-
/**
|
|
101
|
-
* Checks with the Mock Service if the expected interactions have been exercised.
|
|
102
|
-
* @memberof PactProvider
|
|
103
|
-
* @instance
|
|
104
|
-
* @returns {Promise}
|
|
105
|
-
*/
|
|
106
|
-
Pact.prototype.verify = function () {
|
|
107
|
-
var _this = this;
|
|
108
|
-
return this.mockService.verify()
|
|
109
|
-
.then(function () { return _this.mockService.removeInteractions(); })
|
|
110
|
-
.catch(function (e) {
|
|
111
|
-
// Properly format the error
|
|
112
|
-
/* tslint:disable: no-console */
|
|
113
|
-
console.error("");
|
|
114
|
-
console.error(clc.red("Pact verification failed!"));
|
|
115
|
-
console.error(clc.red(e));
|
|
116
|
-
/* tslint:enable: */
|
|
117
|
-
return _this.mockService.removeInteractions().then(function () {
|
|
118
|
-
throw new Error("Pact verification failed - expected interactions did not match actual.");
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
/**
|
|
123
|
-
* Writes the Pact and clears any interactions left behind and shutdown the
|
|
124
|
-
* mock server
|
|
125
|
-
* @memberof PactProvider
|
|
126
|
-
* @instance
|
|
127
|
-
* @returns {Promise}
|
|
128
|
-
*/
|
|
129
|
-
Pact.prototype.finalize = function () {
|
|
130
|
-
var _this = this;
|
|
131
|
-
if (this.finalized) {
|
|
132
|
-
logger_1.default.warn("finalize() has already been called, this is probably a logic error in your test setup. " +
|
|
133
|
-
"In the future this will be an error.");
|
|
134
|
-
}
|
|
135
|
-
this.finalized = true;
|
|
136
|
-
return this.mockService.writePact()
|
|
137
|
-
.then(function () { return logger_1.default.info("Pact File Written"); }, function (e) {
|
|
138
|
-
return Promise.reject(e);
|
|
139
|
-
})
|
|
140
|
-
.then(function () { return new Promise(function (resolve, reject) { return _this.server.delete().then(function () { return resolve(); }, function (e) { return reject(e); }); }); })
|
|
141
|
-
.catch(function (e) { return new Promise(function (resolve, reject) {
|
|
142
|
-
return _this.server.delete().finally(function () { return reject(e); });
|
|
143
|
-
}); });
|
|
144
|
-
};
|
|
145
|
-
/**
|
|
146
|
-
* Writes the pact file out to file. Should be called when all tests have been performed for a
|
|
147
|
-
* given Consumer <-> Provider pair. It will write out the Pact to the
|
|
148
|
-
* configured file.
|
|
149
|
-
* @memberof PactProvider
|
|
150
|
-
* @instance
|
|
151
|
-
* @returns {Promise}
|
|
152
|
-
*/
|
|
153
|
-
Pact.prototype.writePact = function () {
|
|
154
|
-
return this.mockService.writePact();
|
|
155
|
-
};
|
|
156
|
-
/**
|
|
157
|
-
* Clear up any interactions in the Provider Mock Server.
|
|
158
|
-
* @memberof PactProvider
|
|
159
|
-
* @instance
|
|
160
|
-
* @returns {Promise}
|
|
161
|
-
*/
|
|
162
|
-
Pact.prototype.removeInteractions = function () {
|
|
163
|
-
return this.mockService.removeInteractions();
|
|
164
|
-
};
|
|
165
|
-
Pact.prototype.checkPort = function () {
|
|
166
|
-
if (this.server && this.server.options.port) {
|
|
167
|
-
return net_1.isPortAvailable(this.server.options.port, this.opts.host);
|
|
168
|
-
}
|
|
169
|
-
return Promise.resolve();
|
|
170
|
-
};
|
|
171
|
-
Pact.prototype.setupMockService = function () {
|
|
172
|
-
logger_1.default.info("Setting up Pact with Consumer \"" + this.opts.consumer + "\" and Provider \"" + this.opts.provider + "\"\n using mock service on Port: \"" + this.opts.port + "\"");
|
|
173
|
-
this.mockService = new mockService_1.MockService(undefined, undefined, this.opts.port, this.opts.host, this.opts.ssl, this.opts.pactfileWriteMode);
|
|
174
|
-
};
|
|
175
|
-
Pact.prototype.startServer = function () {
|
|
176
|
-
var _this = this;
|
|
177
|
-
return new Promise(function (resolve, reject) {
|
|
178
|
-
return _this.server.start()
|
|
179
|
-
.then(function () {
|
|
180
|
-
_this.opts.port = _this.server.options.port || _this.opts.port;
|
|
181
|
-
resolve(_this.opts);
|
|
182
|
-
}, function (e) { return reject(e); });
|
|
183
|
-
});
|
|
184
|
-
};
|
|
185
|
-
Pact.defaults = {
|
|
186
|
-
consumer: "",
|
|
187
|
-
cors: false,
|
|
188
|
-
dir: path.resolve(process.cwd(), "pacts"),
|
|
189
|
-
host: "127.0.0.1",
|
|
190
|
-
log: path.resolve(process.cwd(), "logs", "pact.log"),
|
|
191
|
-
logLevel: "info",
|
|
192
|
-
pactfileWriteMode: "overwrite",
|
|
193
|
-
provider: "",
|
|
194
|
-
spec: 2,
|
|
195
|
-
ssl: false,
|
|
196
|
-
};
|
|
197
|
-
return Pact;
|
|
198
|
-
}());
|
|
199
|
-
exports.Pact = Pact;
|
|
200
21
|
__export(require("./messageConsumerPact"));
|
|
22
|
+
/**
|
|
23
|
+
* Exposes {@link MessageProviderPact}
|
|
24
|
+
* @memberof Pact
|
|
25
|
+
* @static
|
|
26
|
+
*/
|
|
201
27
|
__export(require("./messageProviderPact"));
|
|
202
28
|
/**
|
|
203
29
|
* Exposes {@link Verifier}
|
|
@@ -211,6 +37,11 @@ __export(require("./dsl/verifier"));
|
|
|
211
37
|
* @static
|
|
212
38
|
*/
|
|
213
39
|
__export(require("./dsl/graphql"));
|
|
40
|
+
/**
|
|
41
|
+
* Exposes {@link ApolloGraphQL}
|
|
42
|
+
* @memberof Pact
|
|
43
|
+
* @static
|
|
44
|
+
*/
|
|
214
45
|
__export(require("./dsl/apolloGraphql"));
|
|
215
46
|
/**
|
|
216
47
|
* Exposes {@link Matchers}
|
|
@@ -219,6 +50,7 @@ __export(require("./dsl/apolloGraphql"));
|
|
|
219
50
|
* @memberof Pact
|
|
220
51
|
* @static
|
|
221
52
|
*/
|
|
53
|
+
var Matchers = require("./dsl/matchers");
|
|
222
54
|
exports.Matchers = Matchers;
|
|
223
55
|
/**
|
|
224
56
|
* Exposes {@link Interaction}
|
package/pact.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pact.js","sourceRoot":"","sources":["../src/pact.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pact.js","sourceRoot":"","sources":["../src/pact.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAEH;;;;GAIG;AACH,gCAA0B;AAE1B;;;;GAIG;AACH,2CAAqC;AAErC;;;;GAIG;AACH,2CAAqC;AASrC;;;;GAIG;AACH,oCAA8B;AAE9B;;;;GAIG;AACH,mCAA6B;AAC7B;;;;GAIG;AACH,yCAAmC;AAEnC;;;;;;GAMG;AACH,yCAA0C;AAC5B,QAAA,QAAQ,GAAG,QAAQ,CAAA;AAEjC;;;;GAIG;AACH,uCAAiC;AAEjC;;;;GAIG;AACH,uCAAiC"}
|