@pact-foundation/pact 16.3.1 → 16.5.0
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 +23 -0
- package/CONTRIBUTING.md +2 -2
- package/README.md +22 -12
- package/package.json +26 -47
- package/scripts/ci/build-and-test.sh +0 -3
- package/scripts/install-plugins.js +104 -0
- package/src/common/graphQL/configurationError.js +2 -22
- package/src/common/graphQL/configurationError.js.map +1 -1
- package/src/common/graphQL/graphQL.d.ts +2 -2
- package/src/common/graphQL/graphQL.js +11 -14
- package/src/common/graphQL/graphQL.js.map +1 -1
- package/src/common/graphQL/graphQLQueryError.js +2 -22
- package/src/common/graphQL/graphQLQueryError.js.map +1 -1
- package/src/common/logger.js +9 -9
- package/src/common/logger.js.map +1 -1
- package/src/common/matchingRules.d.ts +7 -1
- package/src/common/matchingRules.js +42 -22
- package/src/common/matchingRules.js.map +1 -1
- package/src/common/net.js +36 -42
- package/src/common/net.js.map +1 -1
- package/src/common/net.spec.js +39 -87
- package/src/common/net.spec.js.map +1 -1
- package/src/common/request.js +33 -82
- package/src/common/request.js.map +1 -1
- package/src/common/request.spec.js +29 -73
- package/src/common/request.spec.js.map +1 -1
- package/src/common/spec.js +3 -4
- package/src/common/spec.js.map +1 -1
- package/src/dsl/apolloGraphql.js +7 -25
- package/src/dsl/apolloGraphql.js.map +1 -1
- package/src/dsl/apolloGraphql.spec.js +21 -58
- package/src/dsl/apolloGraphql.spec.js.map +1 -1
- package/src/dsl/graphql.d.ts +2 -2
- package/src/dsl/graphql.js +29 -48
- package/src/dsl/graphql.js.map +1 -1
- package/src/dsl/graphql.spec.js +92 -117
- package/src/dsl/graphql.spec.js.map +1 -1
- package/src/dsl/interaction.d.ts +2 -2
- package/src/dsl/interaction.js +41 -48
- package/src/dsl/interaction.js.map +1 -1
- package/src/dsl/interaction.spec.js +109 -132
- package/src/dsl/interaction.spec.js.map +1 -1
- package/src/dsl/matchers.d.ts +2 -3
- package/src/dsl/matchers.js +19 -31
- package/src/dsl/matchers.js.map +1 -1
- package/src/dsl/matchers.spec.js +279 -289
- package/src/dsl/matchers.spec.js.map +1 -1
- package/src/dsl/message.d.ts +3 -3
- package/src/dsl/options.d.ts +3 -3
- package/src/dsl/verifier/proxy/hooks.d.ts +2 -2
- package/src/dsl/verifier/proxy/hooks.js +42 -112
- package/src/dsl/verifier/proxy/hooks.js.map +1 -1
- package/src/dsl/verifier/proxy/hooks.spec.js +86 -199
- package/src/dsl/verifier/proxy/hooks.spec.js.map +1 -1
- package/src/dsl/verifier/proxy/messages.d.ts +2 -2
- package/src/dsl/verifier/proxy/messages.js +88 -106
- package/src/dsl/verifier/proxy/messages.js.map +1 -1
- package/src/dsl/verifier/proxy/parseBody.d.ts +1 -1
- package/src/dsl/verifier/proxy/parseBody.js +3 -3
- package/src/dsl/verifier/proxy/parseBody.js.map +1 -1
- package/src/dsl/verifier/proxy/parseBody.spec.js +35 -113
- package/src/dsl/verifier/proxy/parseBody.spec.js.map +1 -1
- package/src/dsl/verifier/proxy/proxy.d.ts +2 -2
- package/src/dsl/verifier/proxy/proxy.js +22 -26
- package/src/dsl/verifier/proxy/proxy.js.map +1 -1
- package/src/dsl/verifier/proxy/proxy.spec.js +11 -53
- package/src/dsl/verifier/proxy/proxy.spec.js.map +1 -1
- package/src/dsl/verifier/proxy/proxyRequest.d.ts +3 -3
- package/src/dsl/verifier/proxy/proxyRequest.js +7 -7
- package/src/dsl/verifier/proxy/proxyRequest.js.map +1 -1
- package/src/dsl/verifier/proxy/proxyRequest.spec.js +54 -104
- package/src/dsl/verifier/proxy/proxyRequest.spec.js.map +1 -1
- package/src/dsl/verifier/proxy/stateHandler/setupStates.d.ts +3 -3
- package/src/dsl/verifier/proxy/stateHandler/setupStates.js +14 -18
- package/src/dsl/verifier/proxy/stateHandler/setupStates.js.map +1 -1
- package/src/dsl/verifier/proxy/stateHandler/setupStates.spec.js +76 -193
- package/src/dsl/verifier/proxy/stateHandler/setupStates.spec.js.map +1 -1
- package/src/dsl/verifier/proxy/stateHandler/stateHandler.d.ts +2 -2
- package/src/dsl/verifier/proxy/stateHandler/stateHandler.js +23 -72
- package/src/dsl/verifier/proxy/stateHandler/stateHandler.js.map +1 -1
- package/src/dsl/verifier/proxy/stateHandler/stateHandler.spec.js +37 -122
- package/src/dsl/verifier/proxy/stateHandler/stateHandler.spec.js.map +1 -1
- package/src/dsl/verifier/proxy/tracer.d.ts +1 -1
- package/src/dsl/verifier/proxy/tracer.js +42 -35
- package/src/dsl/verifier/proxy/tracer.js.map +1 -1
- package/src/dsl/verifier/proxy/types.d.ts +5 -5
- package/src/dsl/verifier/types.d.ts +3 -3
- package/src/dsl/verifier/verifier.d.ts +5 -1
- package/src/dsl/verifier/verifier.js +53 -60
- package/src/dsl/verifier/verifier.js.map +1 -1
- package/src/dsl/verifier/verifier.spec.js +84 -151
- package/src/dsl/verifier/verifier.spec.js.map +1 -1
- package/src/errors/configurationError.js +2 -22
- package/src/errors/configurationError.js.map +1 -1
- package/src/errors/graphQLQueryError.js +2 -22
- package/src/errors/graphQLQueryError.js.map +1 -1
- package/src/errors/matcherError.js +2 -22
- package/src/errors/matcherError.js.map +1 -1
- package/src/errors/verificationError.js +2 -22
- package/src/errors/verificationError.js.map +1 -1
- package/src/httpPact/ffi.d.ts +2 -2
- package/src/httpPact/ffi.js +28 -29
- package/src/httpPact/ffi.js.map +1 -1
- package/src/httpPact/ffi.spec.js +40 -83
- package/src/httpPact/ffi.spec.js.map +1 -1
- package/src/httpPact/index.d.ts +3 -3
- package/src/httpPact/index.js +92 -149
- package/src/httpPact/index.js.map +1 -1
- package/src/httpPact/index.spec.js +102 -195
- package/src/httpPact/index.spec.js.map +1 -1
- package/src/httpPact/tracing.js +20 -28
- package/src/httpPact/tracing.js.map +1 -1
- package/src/index.d.ts +25 -25
- package/src/index.js +29 -29
- package/src/index.js.map +1 -1
- package/src/messageConsumerPact.d.ts +5 -5
- package/src/messageConsumerPact.js +59 -53
- package/src/messageConsumerPact.js.map +1 -1
- package/src/messageConsumerPact.spec.js +55 -97
- package/src/messageConsumerPact.spec.js.map +1 -1
- package/src/messageProviderPact.d.ts +3 -3
- package/src/messageProviderPact.js +68 -85
- package/src/messageProviderPact.js.map +1 -1
- package/src/messageProviderPact.spec.js +96 -123
- package/src/messageProviderPact.spec.js.map +1 -1
- package/src/pact.integration.spec.js +242 -351
- package/src/pact.integration.spec.js.map +1 -1
- package/src/v3/display.d.ts +1 -1
- package/src/v3/display.js +44 -58
- package/src/v3/display.js.map +1 -1
- package/src/v3/ffi.js +20 -16
- package/src/v3/ffi.js.map +1 -1
- package/src/v3/ffi.spec.js +7 -42
- package/src/v3/ffi.spec.js.map +1 -1
- package/src/v3/graphql/graphQL.d.ts +4 -4
- package/src/v3/graphql/graphQL.js +50 -75
- package/src/v3/graphql/graphQL.js.map +1 -1
- package/src/v3/graphql/index.d.ts +1 -1
- package/src/v3/graphql/index.js +1 -1
- package/src/v3/graphql/index.js.map +1 -1
- package/src/v3/index.d.ts +4 -12
- package/src/v3/index.js +4 -12
- package/src/v3/index.js.map +1 -1
- package/src/v3/matchers.d.ts +15 -3
- package/src/v3/matchers.js +131 -148
- package/src/v3/matchers.js.map +1 -1
- package/src/v3/matchers.spec.js +281 -232
- package/src/v3/matchers.spec.js.map +1 -1
- package/src/v3/pact.d.ts +2 -2
- package/src/v3/pact.js +108 -151
- package/src/v3/pact.js.map +1 -1
- package/src/v3/pact.spec.js +94 -0
- package/src/v3/pact.spec.js.map +1 -0
- package/src/v3/types.d.ts +19 -3
- package/src/v3/types.js +22 -1
- package/src/v3/types.js.map +1 -1
- package/src/v4/graphql/graphQLInteractionWithRequest.d.ts +4 -4
- package/src/v4/graphql/graphQLInteractionWithRequest.js +21 -17
- package/src/v4/graphql/graphQLInteractionWithRequest.js.map +1 -1
- package/src/v4/graphql/graphQLRequestBuilder.d.ts +3 -3
- package/src/v4/graphql/graphQLRequestBuilder.js +18 -20
- package/src/v4/graphql/graphQLRequestBuilder.js.map +1 -1
- package/src/v4/graphql/index.d.ts +6 -6
- package/src/v4/graphql/index.js +21 -17
- package/src/v4/graphql/index.js.map +1 -1
- package/src/v4/graphql/types.d.ts +5 -5
- package/src/v4/http/index.d.ts +2 -2
- package/src/v4/http/index.js +53 -93
- package/src/v4/http/index.js.map +1 -1
- package/src/v4/http/index.spec.d.ts +1 -0
- package/src/v4/http/index.spec.js +73 -0
- package/src/v4/http/index.spec.js.map +1 -0
- package/src/v4/http/interactionWithCompleteRequest.d.ts +4 -7
- package/src/v4/http/interactionWithCompleteRequest.js +6 -10
- package/src/v4/http/interactionWithCompleteRequest.js.map +1 -1
- package/src/v4/http/interactionWithPlugin.d.ts +3 -3
- package/src/v4/http/interactionWithPlugin.js +14 -11
- package/src/v4/http/interactionWithPlugin.js.map +1 -1
- package/src/v4/http/interactionWithPluginRequest.d.ts +4 -3
- package/src/v4/http/interactionWithPluginRequest.js +17 -9
- package/src/v4/http/interactionWithPluginRequest.js.map +1 -1
- package/src/v4/http/interactionWithPluginResponse.d.ts +2 -2
- package/src/v4/http/interactionWithPluginResponse.js +10 -48
- package/src/v4/http/interactionWithPluginResponse.js.map +1 -1
- package/src/v4/http/interactionWithRequest.d.ts +4 -3
- package/src/v4/http/interactionWithRequest.js +17 -9
- package/src/v4/http/interactionWithRequest.js.map +1 -1
- package/src/v4/http/interactionWithRequest.spec.d.ts +1 -0
- package/src/v4/http/interactionWithRequest.spec.js +82 -0
- package/src/v4/http/interactionWithRequest.spec.js.map +1 -0
- package/src/v4/http/interactionWithResponse.d.ts +2 -2
- package/src/v4/http/interactionWithResponse.js +10 -48
- package/src/v4/http/interactionWithResponse.js.map +1 -1
- package/src/v4/http/requestBuilder.d.ts +4 -3
- package/src/v4/http/requestBuilder.js +36 -34
- package/src/v4/http/requestBuilder.js.map +1 -1
- package/src/v4/http/requestBuilder.spec.d.ts +1 -0
- package/src/v4/http/requestBuilder.spec.js +42 -0
- package/src/v4/http/requestBuilder.spec.js.map +1 -0
- package/src/v4/http/requestWithPluginBuilder.d.ts +3 -2
- package/src/v4/http/requestWithPluginBuilder.js +30 -46
- package/src/v4/http/requestWithPluginBuilder.js.map +1 -1
- package/src/v4/http/requestWithPluginBuilder.spec.d.ts +1 -0
- package/src/v4/http/requestWithPluginBuilder.spec.js +34 -0
- package/src/v4/http/requestWithPluginBuilder.spec.js.map +1 -0
- package/src/v4/http/responseBuilder.d.ts +4 -3
- package/src/v4/http/responseBuilder.js +28 -25
- package/src/v4/http/responseBuilder.js.map +1 -1
- package/src/v4/http/responseBuilder.spec.d.ts +1 -0
- package/src/v4/http/responseBuilder.spec.js +42 -0
- package/src/v4/http/responseBuilder.spec.js.map +1 -0
- package/src/v4/http/responseWithPluginBuilder.d.ts +1 -1
- package/src/v4/http/responseWithPluginBuilder.js +5 -25
- package/src/v4/http/responseWithPluginBuilder.js.map +1 -1
- package/src/v4/http/responseWithPluginBuilder.spec.d.ts +1 -0
- package/src/v4/http/responseWithPluginBuilder.spec.js +34 -0
- package/src/v4/http/responseWithPluginBuilder.spec.js.map +1 -0
- package/src/v4/http/types.d.ts +13 -4
- package/src/v4/http/unconfiguredInteraction.d.ts +6 -5
- package/src/v4/http/unconfiguredInteraction.js +31 -26
- package/src/v4/http/unconfiguredInteraction.js.map +1 -1
- package/src/v4/index.d.ts +6 -5
- package/src/v4/index.js +32 -35
- package/src/v4/index.js.map +1 -1
- package/src/v4/message/asynchronousMessage.d.ts +7 -6
- package/src/v4/message/asynchronousMessage.js +157 -190
- package/src/v4/message/asynchronousMessage.js.map +1 -1
- package/src/v4/message/index.d.ts +7 -6
- package/src/v4/message/index.js +188 -217
- package/src/v4/message/index.js.map +1 -1
- package/src/v4/message/types.d.ts +5 -3
- package/src/v4/types.d.ts +3 -3
- package/src/xml/index.d.ts +4 -0
- package/src/xml/index.js +21 -0
- package/src/xml/index.js.map +1 -0
- package/src/{v3/xml → xml}/xmlBuilder.d.ts +1 -3
- package/src/{v3/xml → xml}/xmlBuilder.js +7 -9
- package/src/xml/xmlBuilder.js.map +1 -0
- package/src/{v3/xml → xml}/xmlElement.d.ts +2 -2
- package/src/xml/xmlElement.js +73 -0
- package/src/xml/xmlElement.js.map +1 -0
- package/src/xml/xmlElement.spec.d.ts +1 -0
- package/src/xml/xmlElement.spec.js +107 -0
- package/src/xml/xmlElement.spec.js.map +1 -0
- package/src/xml/xmlNode.js +7 -0
- package/src/xml/xmlNode.js.map +1 -0
- package/src/{v3/xml → xml}/xmlText.d.ts +1 -1
- package/src/xml/xmlText.js +15 -0
- package/src/xml/xmlText.js.map +1 -0
- package/scripts/install-plugins +0 -106
- package/src/v3/xml/xmlBuilder.js.map +0 -1
- package/src/v3/xml/xmlElement.js +0 -90
- package/src/v3/xml/xmlElement.js.map +0 -1
- package/src/v3/xml/xmlElement.spec.js +0 -113
- package/src/v3/xml/xmlElement.spec.js.map +0 -1
- package/src/v3/xml/xmlNode.js +0 -10
- package/src/v3/xml/xmlNode.js.map +0 -1
- package/src/v3/xml/xmlText.js +0 -31
- package/src/v3/xml/xmlText.js.map +0 -1
- /package/src/v3/{xml/xmlElement.spec.d.ts → pact.spec.d.ts} +0 -0
- /package/src/{v3/xml → xml}/xmlNode.d.ts +0 -0
package/src/v3/graphql/index.js
CHANGED
|
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./graphQL"), exports);
|
|
18
17
|
__exportStar(require("../../common/graphQL/configurationError"), exports);
|
|
19
18
|
__exportStar(require("../../common/graphQL/graphQLQueryError"), exports);
|
|
20
19
|
__exportStar(require("../../common/graphQL/types"), exports);
|
|
20
|
+
__exportStar(require("./graphQL"), exports);
|
|
21
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/v3/graphql/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/v3/graphql/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0EAAwD;AACxD,yEAAuD;AACvD,6DAA2C;AAC3C,4CAA0B"}
|
package/src/v3/index.d.ts
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export * from './
|
|
1
|
+
export * from '../xml';
|
|
2
|
+
export * from './graphql';
|
|
3
3
|
/**
|
|
4
4
|
* Exposes {@link MatchersV3}
|
|
5
5
|
* @memberof Pact
|
|
6
6
|
* @static
|
|
7
7
|
*/
|
|
8
8
|
export * as MatchersV3 from './matchers';
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* @memberof Pact
|
|
12
|
-
* @static
|
|
13
|
-
*/
|
|
14
|
-
export * from './xml/xmlBuilder';
|
|
15
|
-
export * from './xml/xmlElement';
|
|
16
|
-
export * from './xml/xmlNode';
|
|
17
|
-
export * from './xml/xmlText';
|
|
18
|
-
export * from './graphql';
|
|
9
|
+
export * from './pact';
|
|
10
|
+
export * from './types';
|
package/src/v3/index.js
CHANGED
|
@@ -37,22 +37,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
37
37
|
})();
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.MatchersV3 = void 0;
|
|
40
|
-
__exportStar(require("
|
|
41
|
-
__exportStar(require("./
|
|
40
|
+
__exportStar(require("../xml"), exports);
|
|
41
|
+
__exportStar(require("./graphql"), exports);
|
|
42
42
|
/**
|
|
43
43
|
* Exposes {@link MatchersV3}
|
|
44
44
|
* @memberof Pact
|
|
45
45
|
* @static
|
|
46
46
|
*/
|
|
47
47
|
exports.MatchersV3 = __importStar(require("./matchers"));
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
* @memberof Pact
|
|
51
|
-
* @static
|
|
52
|
-
*/
|
|
53
|
-
__exportStar(require("./xml/xmlBuilder"), exports);
|
|
54
|
-
__exportStar(require("./xml/xmlElement"), exports);
|
|
55
|
-
__exportStar(require("./xml/xmlNode"), exports);
|
|
56
|
-
__exportStar(require("./xml/xmlText"), exports);
|
|
57
|
-
__exportStar(require("./graphql"), exports);
|
|
48
|
+
__exportStar(require("./pact"), exports);
|
|
49
|
+
__exportStar(require("./types"), exports);
|
|
58
50
|
//# sourceMappingURL=index.js.map
|
package/src/v3/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,4CAA0B;AAE1B;;;;GAIG;AACH,yDAAyC;AACzC,yCAAuB;AACvB,0CAAwB"}
|
package/src/v3/matchers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { AnyJson } from '../common/jsonTypes';
|
|
2
|
+
import type { ArrayContainsMatcher, DateTimeMatcher, HTTPResponseStatusClass, Matcher, MaxLikeMatcher, MinLikeMatcher, ProviderStateInjectedValue, RulesMatcher, StatusCodeMatcher, V3RegexMatcher } from './types';
|
|
3
3
|
export * from './types';
|
|
4
4
|
export declare function isMatcher(x: unknown): x is Matcher<unknown>;
|
|
5
5
|
/**
|
|
@@ -33,6 +33,14 @@ export declare const eachKeyMatches: (example: Record<string, unknown>, matchers
|
|
|
33
33
|
* @param matchers Matchers to apply to each value
|
|
34
34
|
*/
|
|
35
35
|
export declare const eachValueMatches: <T>(example: Record<string, T>, matchers: Matcher<T> | Matcher<T>[]) => RulesMatcher<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Matches HTTP status codes either by a class (e.g. 2XX) or a list of specific codes.
|
|
38
|
+
*
|
|
39
|
+
* @param example Example status code to use in consumer tests
|
|
40
|
+
* @param status Allowed status codes - either an HTTPResponseStatusClass (e.g. Success for 2XX)
|
|
41
|
+
* or an array of specific status codes (e.g. [200, 201])
|
|
42
|
+
*/
|
|
43
|
+
export declare const matchStatus: (example: number, status: HTTPResponseStatusClass | number[]) => StatusCodeMatcher<number>;
|
|
36
44
|
/**
|
|
37
45
|
* Array where each element must match the given template
|
|
38
46
|
* @param template Template to base the comparison on
|
|
@@ -170,9 +178,13 @@ export declare function fromProviderState<V>(expression: string, exampleValue: V
|
|
|
170
178
|
*/
|
|
171
179
|
export declare function uuid(example?: string): V3RegexMatcher;
|
|
172
180
|
export declare const matcherValueOrString: (obj: unknown) => string;
|
|
181
|
+
/**
|
|
182
|
+
* Type guard to check if a value is a StatusCodeMatcher.
|
|
183
|
+
*/
|
|
184
|
+
export declare const isStatusCodeMatcher: (status: number | StatusCodeMatcher<number>) => status is StatusCodeMatcher<number>;
|
|
173
185
|
/**
|
|
174
186
|
* Recurse the object removing any underlying matching guff, returning the raw
|
|
175
187
|
* example content.
|
|
176
188
|
*/
|
|
177
|
-
export declare function reify(input: unknown):
|
|
189
|
+
export declare function reify<T extends AnyJson = AnyJson>(input: unknown): T;
|
|
178
190
|
export { reify as extractPayload };
|
package/src/v3/matchers.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
3
|
if (k2 === undefined) k2 = k;
|
|
15
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -24,20 +13,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
24
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
15
|
};
|
|
27
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
28
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
29
|
-
if (ar || !(i in from)) {
|
|
30
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
31
|
-
ar[i] = from[i];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
35
|
-
};
|
|
36
16
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
18
|
};
|
|
39
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.matcherValueOrString = exports.equal = exports.contentType = exports.decimal = exports.integer = exports.boolean = exports.constrainedArrayLike = exports.atMostLike = exports.atLeastLike = exports.atLeastOneLike = exports.eachLike = exports.eachValueMatches = exports.eachKeyMatches = exports.eachKeyLike = exports.like = void 0;
|
|
20
|
+
exports.isStatusCodeMatcher = exports.matcherValueOrString = exports.equal = exports.contentType = exports.decimal = exports.integer = exports.boolean = exports.constrainedArrayLike = exports.atMostLike = exports.atLeastLike = exports.atLeastOneLike = exports.eachLike = exports.matchStatus = exports.eachValueMatches = exports.eachKeyMatches = exports.eachKeyLike = exports.like = void 0;
|
|
41
21
|
exports.isMatcher = isMatcher;
|
|
42
22
|
exports.number = number;
|
|
43
23
|
exports.string = string;
|
|
@@ -55,8 +35,8 @@ exports.fromProviderState = fromProviderState;
|
|
|
55
35
|
exports.uuid = uuid;
|
|
56
36
|
exports.reify = reify;
|
|
57
37
|
exports.extractPayload = reify;
|
|
58
|
-
|
|
59
|
-
|
|
38
|
+
const ramda_1 = require("ramda");
|
|
39
|
+
const randexp_1 = __importDefault(require("randexp"));
|
|
60
40
|
__exportStar(require("./types"), exports);
|
|
61
41
|
function isMatcher(x) {
|
|
62
42
|
return (x != null &&
|
|
@@ -67,10 +47,10 @@ function isMatcher(x) {
|
|
|
67
47
|
* Value must match the given template
|
|
68
48
|
* @param template Template to base the comparison on
|
|
69
49
|
*/
|
|
70
|
-
|
|
50
|
+
const like = (template) => ({
|
|
71
51
|
'pact:matcher:type': 'type',
|
|
72
52
|
value: template,
|
|
73
|
-
});
|
|
53
|
+
});
|
|
74
54
|
exports.like = like;
|
|
75
55
|
/**
|
|
76
56
|
* Object where the key itself is ignored, but the value template must match.
|
|
@@ -79,15 +59,12 @@ exports.like = like;
|
|
|
79
59
|
* @param keyTemplate Example key to use
|
|
80
60
|
* @param template Example value template to base the comparison on
|
|
81
61
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
_a),
|
|
89
|
-
});
|
|
90
|
-
};
|
|
62
|
+
const eachKeyLike = (keyTemplate, template) => ({
|
|
63
|
+
'pact:matcher:type': 'values',
|
|
64
|
+
value: {
|
|
65
|
+
[keyTemplate]: template,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
91
68
|
exports.eachKeyLike = eachKeyLike;
|
|
92
69
|
/**
|
|
93
70
|
* Object where the _keys_ must match the supplied matchers.
|
|
@@ -97,14 +74,11 @@ exports.eachKeyLike = eachKeyLike;
|
|
|
97
74
|
* @param example Example object with key/values e.g. `{ foo: 'bar', baz: 'qux'}`
|
|
98
75
|
* @param matchers Matchers to apply to each key
|
|
99
76
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
value: example,
|
|
106
|
-
});
|
|
107
|
-
};
|
|
77
|
+
const eachKeyMatches = (example, matchers = (0, exports.like)('key')) => ({
|
|
78
|
+
'pact:matcher:type': 'eachKey',
|
|
79
|
+
rules: Array.isArray(matchers) ? matchers : [matchers],
|
|
80
|
+
value: example,
|
|
81
|
+
});
|
|
108
82
|
exports.eachKeyMatches = eachKeyMatches;
|
|
109
83
|
/**
|
|
110
84
|
* Object where the _values_ must match the supplied matchers.
|
|
@@ -114,7 +88,7 @@ exports.eachKeyMatches = eachKeyMatches;
|
|
|
114
88
|
* @param example Example object with key/values e.g. `{ foo: 'bar', baz: 'qux'}`
|
|
115
89
|
* @param matchers Matchers to apply to each value
|
|
116
90
|
*/
|
|
117
|
-
|
|
91
|
+
const eachValueMatches = (example, matchers) => ({
|
|
118
92
|
'pact:matcher:type': 'eachValue',
|
|
119
93
|
rules: Array.isArray(matchers) ? matchers : [matchers],
|
|
120
94
|
value: example,
|
|
@@ -122,20 +96,32 @@ var eachValueMatches = function (example, matchers) { return ({
|
|
|
122
96
|
// value: {
|
|
123
97
|
// [keyTemplate]: template,
|
|
124
98
|
// },
|
|
125
|
-
});
|
|
99
|
+
});
|
|
126
100
|
exports.eachValueMatches = eachValueMatches;
|
|
101
|
+
/**
|
|
102
|
+
* Matches HTTP status codes either by a class (e.g. 2XX) or a list of specific codes.
|
|
103
|
+
*
|
|
104
|
+
* @param example Example status code to use in consumer tests
|
|
105
|
+
* @param status Allowed status codes - either an HTTPResponseStatusClass (e.g. Success for 2XX)
|
|
106
|
+
* or an array of specific status codes (e.g. [200, 201])
|
|
107
|
+
*/
|
|
108
|
+
const matchStatus = (example, status) => ({
|
|
109
|
+
'pact:matcher:type': 'statusCode',
|
|
110
|
+
status,
|
|
111
|
+
value: example,
|
|
112
|
+
});
|
|
113
|
+
exports.matchStatus = matchStatus;
|
|
127
114
|
/**
|
|
128
115
|
* Array where each element must match the given template
|
|
129
116
|
* @param template Template to base the comparison on
|
|
130
117
|
* @param min Minimum number of elements required in the array
|
|
131
118
|
*/
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
var elements = min;
|
|
119
|
+
const eachLike = (template, min = 1) => {
|
|
120
|
+
const elements = min;
|
|
135
121
|
return {
|
|
136
|
-
min
|
|
122
|
+
min,
|
|
137
123
|
'pact:matcher:type': 'type',
|
|
138
|
-
value: (0, ramda_1.times)(
|
|
124
|
+
value: (0, ramda_1.times)(() => template, elements),
|
|
139
125
|
};
|
|
140
126
|
};
|
|
141
127
|
exports.eachLike = eachLike;
|
|
@@ -144,14 +130,11 @@ exports.eachLike = eachLike;
|
|
|
144
130
|
* @param template Template to base the comparison on
|
|
145
131
|
* @param count Number of examples to generate, defaults to one
|
|
146
132
|
*/
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
value: (0, ramda_1.times)(function () { return template; }, count),
|
|
153
|
-
});
|
|
154
|
-
};
|
|
133
|
+
const atLeastOneLike = (template, count = 1) => ({
|
|
134
|
+
min: 1,
|
|
135
|
+
'pact:matcher:type': 'type',
|
|
136
|
+
value: (0, ramda_1.times)(() => template, count),
|
|
137
|
+
});
|
|
155
138
|
exports.atLeastOneLike = atLeastOneLike;
|
|
156
139
|
/**
|
|
157
140
|
* An array that has to have at least the required number of elements and each element must match the given template
|
|
@@ -159,16 +142,16 @@ exports.atLeastOneLike = atLeastOneLike;
|
|
|
159
142
|
* @param min Minimum number of elements required in the array
|
|
160
143
|
* @param count Number of examples to generate, defaults to min
|
|
161
144
|
*/
|
|
162
|
-
|
|
163
|
-
|
|
145
|
+
const atLeastLike = (template, min, count) => {
|
|
146
|
+
const elements = count || min;
|
|
164
147
|
if (count && count < min) {
|
|
165
|
-
throw new Error(
|
|
166
|
-
|
|
148
|
+
throw new Error(`atLeastLike has a minimum of ${min} but ${count} elements were requested.` +
|
|
149
|
+
` Make sure the count is greater than or equal to the min.`);
|
|
167
150
|
}
|
|
168
151
|
return {
|
|
169
|
-
min
|
|
152
|
+
min,
|
|
170
153
|
'pact:matcher:type': 'type',
|
|
171
|
-
value: (0, ramda_1.times)(
|
|
154
|
+
value: (0, ramda_1.times)(() => template, elements),
|
|
172
155
|
};
|
|
173
156
|
};
|
|
174
157
|
exports.atLeastLike = atLeastLike;
|
|
@@ -178,16 +161,16 @@ exports.atLeastLike = atLeastLike;
|
|
|
178
161
|
* @param max Maximum number of elements required in the array
|
|
179
162
|
* @param count Number of examples to generate, defaults to one
|
|
180
163
|
*/
|
|
181
|
-
|
|
182
|
-
|
|
164
|
+
const atMostLike = (template, max, count) => {
|
|
165
|
+
const elements = count || 1;
|
|
183
166
|
if (count && count > max) {
|
|
184
|
-
throw new Error(
|
|
185
|
-
|
|
167
|
+
throw new Error(`atMostLike has a maximum of ${max} but ${count} elements where requested.` +
|
|
168
|
+
` Make sure the count is less than or equal to the max.`);
|
|
186
169
|
}
|
|
187
170
|
return {
|
|
188
|
-
max
|
|
171
|
+
max,
|
|
189
172
|
'pact:matcher:type': 'type',
|
|
190
|
-
value: (0, ramda_1.times)(
|
|
173
|
+
value: (0, ramda_1.times)(() => template, elements),
|
|
191
174
|
};
|
|
192
175
|
};
|
|
193
176
|
exports.atMostLike = atMostLike;
|
|
@@ -198,23 +181,23 @@ exports.atMostLike = atMostLike;
|
|
|
198
181
|
* @param max Maximum number of elements required in the array
|
|
199
182
|
* @param count Number of examples to generate, defaults to one
|
|
200
183
|
*/
|
|
201
|
-
|
|
202
|
-
|
|
184
|
+
const constrainedArrayLike = (template, min, max, count) => {
|
|
185
|
+
const elements = count || min;
|
|
203
186
|
if (count) {
|
|
204
187
|
if (count < min) {
|
|
205
|
-
throw new Error(
|
|
206
|
-
|
|
188
|
+
throw new Error(`constrainedArrayLike has a minimum of ${min} but ${count} elements where requested.` +
|
|
189
|
+
` Make sure the count is greater than or equal to the min.`);
|
|
207
190
|
}
|
|
208
191
|
else if (count > max) {
|
|
209
|
-
throw new Error(
|
|
210
|
-
|
|
192
|
+
throw new Error(`constrainedArrayLike has a maximum of ${max} but ${count} elements where requested.` +
|
|
193
|
+
` Make sure the count is less than or equal to the max.`);
|
|
211
194
|
}
|
|
212
195
|
}
|
|
213
196
|
return {
|
|
214
|
-
min
|
|
215
|
-
max
|
|
197
|
+
min,
|
|
198
|
+
max,
|
|
216
199
|
'pact:matcher:type': 'type',
|
|
217
|
-
value: (0, ramda_1.times)(
|
|
200
|
+
value: (0, ramda_1.times)(() => template, elements),
|
|
218
201
|
};
|
|
219
202
|
};
|
|
220
203
|
exports.constrainedArrayLike = constrainedArrayLike;
|
|
@@ -222,19 +205,16 @@ exports.constrainedArrayLike = constrainedArrayLike;
|
|
|
222
205
|
* Value must be a boolean
|
|
223
206
|
* @param b Boolean example value. Defaults to true if unsupplied
|
|
224
207
|
*/
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
value: b,
|
|
230
|
-
});
|
|
231
|
-
};
|
|
208
|
+
const boolean = (b = true) => ({
|
|
209
|
+
'pact:matcher:type': 'type',
|
|
210
|
+
value: b,
|
|
211
|
+
});
|
|
232
212
|
exports.boolean = boolean;
|
|
233
213
|
/**
|
|
234
214
|
* Value must be an integer (must be a number and have no decimal places)
|
|
235
215
|
* @param int Example value. If omitted a random value will be generated.
|
|
236
216
|
*/
|
|
237
|
-
|
|
217
|
+
const integer = (int) => {
|
|
238
218
|
if (Number.isInteger(int)) {
|
|
239
219
|
return {
|
|
240
220
|
'pact:matcher:type': 'integer',
|
|
@@ -242,7 +222,7 @@ var integer = function (int) {
|
|
|
242
222
|
};
|
|
243
223
|
}
|
|
244
224
|
if (int) {
|
|
245
|
-
throw new Error(
|
|
225
|
+
throw new Error(`The integer matcher was passed '${int}' which is not an integer.`);
|
|
246
226
|
}
|
|
247
227
|
return {
|
|
248
228
|
'pact:generator:type': 'RandomInt',
|
|
@@ -255,7 +235,7 @@ exports.integer = integer;
|
|
|
255
235
|
* Value must be a decimal number (must be a number and have decimal places)
|
|
256
236
|
* @param num Example value. If omitted a random value will be generated.
|
|
257
237
|
*/
|
|
258
|
-
|
|
238
|
+
const decimal = (num) => {
|
|
259
239
|
if (Number.isFinite(num)) {
|
|
260
240
|
return {
|
|
261
241
|
'pact:matcher:type': 'decimal',
|
|
@@ -263,7 +243,7 @@ var decimal = function (num) {
|
|
|
263
243
|
};
|
|
264
244
|
}
|
|
265
245
|
if (num) {
|
|
266
|
-
throw new Error(
|
|
246
|
+
throw new Error(`The decimal matcher was passed '${num}' which is not a number.`);
|
|
267
247
|
}
|
|
268
248
|
return {
|
|
269
249
|
'pact:generator:type': 'RandomDecimal',
|
|
@@ -284,7 +264,7 @@ function number(num) {
|
|
|
284
264
|
};
|
|
285
265
|
}
|
|
286
266
|
if (num) {
|
|
287
|
-
throw new Error(
|
|
267
|
+
throw new Error(`The number matcher was passed '${num}' which is not a number.`);
|
|
288
268
|
}
|
|
289
269
|
return {
|
|
290
270
|
'pact:generator:type': 'RandomInt',
|
|
@@ -296,8 +276,7 @@ function number(num) {
|
|
|
296
276
|
* Value must be a string
|
|
297
277
|
* @param str Example value
|
|
298
278
|
*/
|
|
299
|
-
function string(str) {
|
|
300
|
-
if (str === void 0) { str = 'some string'; }
|
|
279
|
+
function string(str = 'some string') {
|
|
301
280
|
return {
|
|
302
281
|
'pact:matcher:type': 'type',
|
|
303
282
|
value: str,
|
|
@@ -327,19 +306,19 @@ function regex(pattern, str) {
|
|
|
327
306
|
* Used for matching binary content or specific content types in multipart requests.
|
|
328
307
|
* @param contentTypeValue The content type to match (e.g., 'image/jpeg', 'text/plain')
|
|
329
308
|
*/
|
|
330
|
-
|
|
309
|
+
const contentType = (contentTypeValue) => ({
|
|
331
310
|
'pact:matcher:type': 'contentType',
|
|
332
311
|
value: contentTypeValue,
|
|
333
|
-
});
|
|
312
|
+
});
|
|
334
313
|
exports.contentType = contentType;
|
|
335
314
|
/**
|
|
336
315
|
* Value that must be equal to the example. This is mainly used to reset the matching rules which cascade.
|
|
337
316
|
* @param value Example value
|
|
338
317
|
*/
|
|
339
|
-
|
|
318
|
+
const equal = (value) => ({
|
|
340
319
|
'pact:matcher:type': 'equality',
|
|
341
|
-
value
|
|
342
|
-
});
|
|
320
|
+
value,
|
|
321
|
+
});
|
|
343
322
|
exports.equal = equal;
|
|
344
323
|
/**
|
|
345
324
|
* String value that must match the provided datetime format string.
|
|
@@ -348,12 +327,12 @@ exports.equal = equal;
|
|
|
348
327
|
*/
|
|
349
328
|
function datetime(format, example) {
|
|
350
329
|
if (!example) {
|
|
351
|
-
throw new Error(
|
|
330
|
+
throw new Error(`you must provide an example datetime`);
|
|
352
331
|
}
|
|
353
|
-
return (0, ramda_1.pickBy)(
|
|
332
|
+
return (0, ramda_1.pickBy)((v) => !(0, ramda_1.isNil)(v), {
|
|
354
333
|
'pact:generator:type': example ? undefined : 'DateTime',
|
|
355
334
|
'pact:matcher:type': 'timestamp',
|
|
356
|
-
format
|
|
335
|
+
format,
|
|
357
336
|
value: example,
|
|
358
337
|
});
|
|
359
338
|
}
|
|
@@ -364,7 +343,7 @@ function datetime(format, example) {
|
|
|
364
343
|
*/
|
|
365
344
|
function timestamp(format, example) {
|
|
366
345
|
if (!example) {
|
|
367
|
-
throw new Error(
|
|
346
|
+
throw new Error(`you must provide an example timestamp`);
|
|
368
347
|
}
|
|
369
348
|
return datetime(format, example);
|
|
370
349
|
}
|
|
@@ -375,12 +354,12 @@ function timestamp(format, example) {
|
|
|
375
354
|
*/
|
|
376
355
|
function time(format, example) {
|
|
377
356
|
if (!example) {
|
|
378
|
-
throw new Error(
|
|
357
|
+
throw new Error(`you must provide an example time`);
|
|
379
358
|
}
|
|
380
|
-
return (0, ramda_1.pickBy)(
|
|
359
|
+
return (0, ramda_1.pickBy)((v) => !(0, ramda_1.isNil)(v), {
|
|
381
360
|
'pact:generator:type': example ? undefined : 'Time',
|
|
382
361
|
'pact:matcher:type': 'time',
|
|
383
|
-
format
|
|
362
|
+
format,
|
|
384
363
|
value: example,
|
|
385
364
|
});
|
|
386
365
|
}
|
|
@@ -391,10 +370,10 @@ function time(format, example) {
|
|
|
391
370
|
*/
|
|
392
371
|
function date(format, example) {
|
|
393
372
|
if (!example) {
|
|
394
|
-
throw new Error(
|
|
373
|
+
throw new Error(`you must provide an example date`);
|
|
395
374
|
}
|
|
396
|
-
return (0, ramda_1.pickBy)(
|
|
397
|
-
format
|
|
375
|
+
return (0, ramda_1.pickBy)((v) => !(0, ramda_1.isNil)(v), {
|
|
376
|
+
format,
|
|
398
377
|
'pact:generator:type': example ? undefined : 'Date',
|
|
399
378
|
'pact:matcher:type': 'date',
|
|
400
379
|
value: example,
|
|
@@ -407,7 +386,7 @@ function date(format, example) {
|
|
|
407
386
|
function includes(value) {
|
|
408
387
|
return {
|
|
409
388
|
'pact:matcher:type': 'include',
|
|
410
|
-
value
|
|
389
|
+
value,
|
|
411
390
|
};
|
|
412
391
|
}
|
|
413
392
|
/**
|
|
@@ -429,42 +408,44 @@ function stringFromRegex(r) {
|
|
|
429
408
|
* @param pathFragments list of path fragments, can be regular expressions
|
|
430
409
|
*/
|
|
431
410
|
function url2(basePath, pathFragments) {
|
|
432
|
-
|
|
433
|
-
'.*('
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
411
|
+
const regexpr = [
|
|
412
|
+
'.*(',
|
|
413
|
+
...pathFragments.map((p) => {
|
|
414
|
+
if (p instanceof RegExp) {
|
|
415
|
+
return `\\/${p.source}`;
|
|
416
|
+
}
|
|
417
|
+
if (p instanceof Object && p['pact:matcher:type'] === 'regex') {
|
|
418
|
+
return `\\/${p.regex}`;
|
|
419
|
+
}
|
|
420
|
+
return `\\/${p.toString()}`;
|
|
421
|
+
}),
|
|
422
|
+
].join('');
|
|
423
|
+
const example = [
|
|
424
|
+
basePath || 'http://localhost:8080',
|
|
425
|
+
...pathFragments.map((p) => {
|
|
426
|
+
if (p instanceof RegExp) {
|
|
427
|
+
return `/${stringFromRegex(p)}`;
|
|
428
|
+
}
|
|
429
|
+
if (p instanceof Object && p['pact:matcher:type'] === 'regex') {
|
|
430
|
+
return `/${p.value}`;
|
|
431
|
+
}
|
|
432
|
+
return `/${p.toString()}`;
|
|
433
|
+
}),
|
|
434
|
+
].join('');
|
|
454
435
|
// Temporary fix for inconsistencies between matchers and generators. Matchers use "value" attribute for
|
|
455
436
|
// example values, while generators use "example"
|
|
456
437
|
if (basePath == null) {
|
|
457
438
|
return {
|
|
458
439
|
'pact:matcher:type': 'regex',
|
|
459
440
|
'pact:generator:type': 'MockServerURL',
|
|
460
|
-
regex:
|
|
441
|
+
regex: `${regexpr})$`,
|
|
461
442
|
value: example,
|
|
462
|
-
example
|
|
443
|
+
example,
|
|
463
444
|
};
|
|
464
445
|
}
|
|
465
446
|
return {
|
|
466
447
|
'pact:matcher:type': 'regex',
|
|
467
|
-
regex:
|
|
448
|
+
regex: `${regexpr})$`,
|
|
468
449
|
value: example,
|
|
469
450
|
};
|
|
470
451
|
}
|
|
@@ -479,14 +460,10 @@ function url(pathFragments) {
|
|
|
479
460
|
* Matches the items in an array against a number of variants. Matching is successful if each variant
|
|
480
461
|
* occurs once in the array. Variants may be objects containing matching rules.
|
|
481
462
|
*/
|
|
482
|
-
function arrayContaining() {
|
|
483
|
-
var variants = [];
|
|
484
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
485
|
-
variants[_i] = arguments[_i];
|
|
486
|
-
}
|
|
463
|
+
function arrayContaining(...variants) {
|
|
487
464
|
return {
|
|
488
465
|
'pact:matcher:type': 'arrayContains',
|
|
489
|
-
variants
|
|
466
|
+
variants,
|
|
490
467
|
};
|
|
491
468
|
}
|
|
492
469
|
/**
|
|
@@ -498,7 +475,7 @@ function fromProviderState(expression, exampleValue) {
|
|
|
498
475
|
return {
|
|
499
476
|
'pact:matcher:type': 'type',
|
|
500
477
|
'pact:generator:type': 'ProviderState',
|
|
501
|
-
expression
|
|
478
|
+
expression,
|
|
502
479
|
value: exampleValue,
|
|
503
480
|
};
|
|
504
481
|
}
|
|
@@ -506,11 +483,11 @@ function fromProviderState(expression, exampleValue) {
|
|
|
506
483
|
* Match a universally unique identifier (UUID). Random values will be used for examples if no example is given.
|
|
507
484
|
*/
|
|
508
485
|
function uuid(example) {
|
|
509
|
-
|
|
486
|
+
const regexStr = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}';
|
|
510
487
|
if (example) {
|
|
511
|
-
|
|
488
|
+
const regexpr = new RegExp(`^${regexStr}$`);
|
|
512
489
|
if (!example.match(regexpr)) {
|
|
513
|
-
throw new Error(
|
|
490
|
+
throw new Error(`regex: Example value '${example}' does not match the UUID regular expression '${regexStr}'`);
|
|
514
491
|
}
|
|
515
492
|
return {
|
|
516
493
|
'pact:matcher:type': 'regex',
|
|
@@ -525,12 +502,17 @@ function uuid(example) {
|
|
|
525
502
|
value: 'e2490de5-5bd3-43d5-b7c4-526e33f71304',
|
|
526
503
|
};
|
|
527
504
|
}
|
|
528
|
-
|
|
505
|
+
const matcherValueOrString = (obj) => {
|
|
529
506
|
if (typeof obj === 'string')
|
|
530
507
|
return obj;
|
|
531
508
|
return JSON.stringify(obj);
|
|
532
509
|
};
|
|
533
510
|
exports.matcherValueOrString = matcherValueOrString;
|
|
511
|
+
/**
|
|
512
|
+
* Type guard to check if a value is a StatusCodeMatcher.
|
|
513
|
+
*/
|
|
514
|
+
const isStatusCodeMatcher = (status) => isMatcher(status) && status['pact:matcher:type'] === 'statusCode';
|
|
515
|
+
exports.isStatusCodeMatcher = isStatusCodeMatcher;
|
|
534
516
|
/**
|
|
535
517
|
* Recurse the object removing any underlying matching guff, returning the raw
|
|
536
518
|
* example content.
|
|
@@ -546,9 +528,10 @@ function reify(input) {
|
|
|
546
528
|
if (input === null) {
|
|
547
529
|
return input;
|
|
548
530
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
531
|
+
const objectInput = input;
|
|
532
|
+
return Object.keys(objectInput).reduce((acc, propName) => {
|
|
533
|
+
acc[propName] = reify(objectInput[propName]);
|
|
534
|
+
return acc;
|
|
552
535
|
}, {});
|
|
553
536
|
}
|
|
554
537
|
if (typeof input === 'number' ||
|
|
@@ -556,6 +539,6 @@ function reify(input) {
|
|
|
556
539
|
typeof input === 'boolean') {
|
|
557
540
|
return input;
|
|
558
541
|
}
|
|
559
|
-
throw new Error(
|
|
542
|
+
throw new Error(`Unable to strip matcher from a '${typeof input}', as it is not valid in a Pact description`);
|
|
560
543
|
}
|
|
561
544
|
//# sourceMappingURL=matchers.js.map
|