@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/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonMap } from '../common/jsonTypes';
|
|
1
|
+
import type { JsonMap } from '../common/jsonTypes';
|
|
2
2
|
export declare enum SpecificationVersion {
|
|
3
3
|
SPECIFICATION_VERSION_V2 = 3,
|
|
4
4
|
SPECIFICATION_VERSION_V3 = 4,
|
|
@@ -37,9 +37,25 @@ export interface ArrayContainsMatcher extends Matcher<unknown[]> {
|
|
|
37
37
|
export interface ProviderStateInjectedValue<T> extends Matcher<T> {
|
|
38
38
|
expression: string;
|
|
39
39
|
}
|
|
40
|
+
export interface StatusCodeMatcher<T> extends Matcher<T> {
|
|
41
|
+
status: HTTPResponseStatusClass | number[];
|
|
42
|
+
}
|
|
40
43
|
export interface RulesMatcher<T> extends Matcher<T> {
|
|
41
44
|
rules: Matcher<T>[];
|
|
42
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Enum for HTTP response status classes used with the status code matcher.
|
|
48
|
+
* These values correspond to the status code ranges defined in RFC 7231.
|
|
49
|
+
*/
|
|
50
|
+
export declare enum HTTPResponseStatusClass {
|
|
51
|
+
Information = "information",
|
|
52
|
+
Success = "success",
|
|
53
|
+
Redirect = "redirect",
|
|
54
|
+
ClientError = "clientError",
|
|
55
|
+
ServerError = "serverError",
|
|
56
|
+
NonError = "nonError",
|
|
57
|
+
Error = "error"
|
|
58
|
+
}
|
|
43
59
|
/**
|
|
44
60
|
* Part of a request or response where matching rules can be applied
|
|
45
61
|
*/
|
|
@@ -76,7 +92,7 @@ export interface PactV3Options {
|
|
|
76
92
|
*/
|
|
77
93
|
provider: string;
|
|
78
94
|
/**
|
|
79
|
-
* If the mock server should handle CORS pre-flight requests. Defaults to
|
|
95
|
+
* If the mock server should handle CORS pre-flight requests. Defaults to true
|
|
80
96
|
*/
|
|
81
97
|
cors?: boolean;
|
|
82
98
|
/**
|
|
@@ -124,7 +140,7 @@ export interface V3Request {
|
|
|
124
140
|
contentType?: string;
|
|
125
141
|
}
|
|
126
142
|
export interface V3Response {
|
|
127
|
-
status: number
|
|
143
|
+
status: number | StatusCodeMatcher<number>;
|
|
128
144
|
headers?: TemplateHeaders;
|
|
129
145
|
body?: unknown;
|
|
130
146
|
contentType?: string;
|
package/src/v3/types.js
CHANGED
|
@@ -1,10 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SpecificationVersion = void 0;
|
|
3
|
+
exports.HTTPResponseStatusClass = exports.SpecificationVersion = void 0;
|
|
4
4
|
var SpecificationVersion;
|
|
5
5
|
(function (SpecificationVersion) {
|
|
6
6
|
SpecificationVersion[SpecificationVersion["SPECIFICATION_VERSION_V2"] = 3] = "SPECIFICATION_VERSION_V2";
|
|
7
7
|
SpecificationVersion[SpecificationVersion["SPECIFICATION_VERSION_V3"] = 4] = "SPECIFICATION_VERSION_V3";
|
|
8
8
|
SpecificationVersion[SpecificationVersion["SPECIFICATION_VERSION_V4"] = 5] = "SPECIFICATION_VERSION_V4";
|
|
9
9
|
})(SpecificationVersion || (exports.SpecificationVersion = SpecificationVersion = {}));
|
|
10
|
+
/**
|
|
11
|
+
* Enum for HTTP response status classes used with the status code matcher.
|
|
12
|
+
* These values correspond to the status code ranges defined in RFC 7231.
|
|
13
|
+
*/
|
|
14
|
+
var HTTPResponseStatusClass;
|
|
15
|
+
(function (HTTPResponseStatusClass) {
|
|
16
|
+
// Informational responses (100–199)
|
|
17
|
+
HTTPResponseStatusClass["Information"] = "information";
|
|
18
|
+
// Successful responses (200–299)
|
|
19
|
+
HTTPResponseStatusClass["Success"] = "success";
|
|
20
|
+
// Redirects (300–399)
|
|
21
|
+
HTTPResponseStatusClass["Redirect"] = "redirect";
|
|
22
|
+
// Client errors (400–499)
|
|
23
|
+
HTTPResponseStatusClass["ClientError"] = "clientError";
|
|
24
|
+
// Server errors (500–599)
|
|
25
|
+
HTTPResponseStatusClass["ServerError"] = "serverError";
|
|
26
|
+
// Non-error response (< 400)
|
|
27
|
+
HTTPResponseStatusClass["NonError"] = "nonError";
|
|
28
|
+
// Any error response (>= 400)
|
|
29
|
+
HTTPResponseStatusClass["Error"] = "error";
|
|
30
|
+
})(HTTPResponseStatusClass || (exports.HTTPResponseStatusClass = HTTPResponseStatusClass = {}));
|
|
10
31
|
//# sourceMappingURL=types.js.map
|
package/src/v3/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/v3/types.ts"],"names":[],"mappings":";;;AAEA,IAAY,oBAIX;AAJD,WAAY,oBAAoB;IAC9B,uGAA4B,CAAA;IAC5B,uGAA4B,CAAA;IAC5B,uGAA4B,CAAA;AAC9B,CAAC,EAJW,oBAAoB,oCAApB,oBAAoB,QAI/B"}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/v3/types.ts"],"names":[],"mappings":";;;AAEA,IAAY,oBAIX;AAJD,WAAY,oBAAoB;IAC9B,uGAA4B,CAAA;IAC5B,uGAA4B,CAAA;IAC5B,uGAA4B,CAAA;AAC9B,CAAC,EAJW,oBAAoB,oCAApB,oBAAoB,QAI/B;AAkDD;;;GAGG;AACH,IAAY,uBAeX;AAfD,WAAY,uBAAuB;IACjC,oCAAoC;IACpC,sDAA2B,CAAA;IAC3B,iCAAiC;IACjC,8CAAmB,CAAA;IACnB,sBAAsB;IACtB,gDAAqB,CAAA;IACrB,0BAA0B;IAC1B,sDAA2B,CAAA;IAC3B,0BAA0B;IAC1B,sDAA2B,CAAA;IAC3B,6BAA6B;IAC7B,gDAAqB,CAAA;IACrB,8BAA8B;IAC9B,0CAAe,CAAA;AACjB,CAAC,EAfW,uBAAuB,uCAAvB,uBAAuB,QAelC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ASTNode } from 'graphql';
|
|
3
|
-
import { PactV4Options, V4InteractionWithRequest } from '../http/types';
|
|
4
|
-
import {
|
|
1
|
+
import type { ConsumerInteraction, ConsumerPact } from '@pact-foundation/pact-core';
|
|
2
|
+
import type { ASTNode } from 'graphql';
|
|
3
|
+
import type { PactV4Options, V4InteractionWithRequest } from '../http/types';
|
|
4
|
+
import { type GraphqlRequest, type V4GraphQLInteractionWithRequest } from './types';
|
|
5
5
|
export declare class GraphQLInteractionWithRequest implements V4GraphQLInteractionWithRequest {
|
|
6
6
|
protected pact: ConsumerPact;
|
|
7
7
|
protected interaction: ConsumerInteraction;
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GraphQLInteractionWithRequest = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const ramda_1 = require("ramda");
|
|
6
|
+
const graphQL_1 = require("../../common/graphQL/graphQL");
|
|
7
|
+
const matchers_1 = require("../../v3/matchers");
|
|
8
|
+
const interactionWithRequest_1 = require("../http/interactionWithRequest");
|
|
9
|
+
const types_1 = require("./types");
|
|
10
|
+
class GraphQLInteractionWithRequest {
|
|
11
|
+
pact;
|
|
12
|
+
interaction;
|
|
13
|
+
opts;
|
|
14
|
+
cleanupFn;
|
|
15
|
+
graphQLRequest;
|
|
11
16
|
// tslint:disable:no-empty-function
|
|
12
|
-
|
|
17
|
+
constructor(pact, interaction, opts, cleanupFn, graphQLRequest) {
|
|
13
18
|
this.pact = pact;
|
|
14
19
|
this.interaction = interaction;
|
|
15
20
|
this.opts = opts;
|
|
@@ -36,22 +41,21 @@ var GraphQLInteractionWithRequest = /** @class */ (function () {
|
|
|
36
41
|
* @param query {string|ASTNode} parsed or unparsed query
|
|
37
42
|
* @return this object
|
|
38
43
|
*/
|
|
39
|
-
|
|
44
|
+
withQuery(query) {
|
|
40
45
|
return this.setQueryDetails(query, types_1.OperationType.Query);
|
|
41
|
-
}
|
|
42
|
-
|
|
46
|
+
}
|
|
47
|
+
withMutation(mutation) {
|
|
43
48
|
return this.setQueryDetails(mutation, types_1.OperationType.Mutation);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
}
|
|
50
|
+
setQueryDetails(query, type) {
|
|
51
|
+
const validatedQuery = (0, graphQL_1.validateQuery)(query, type);
|
|
47
52
|
this.interaction.withRequestBody(JSON.stringify((0, ramda_1.reject)(lodash_1.isUndefined, {
|
|
48
53
|
operationName: this.graphQLRequest.operation,
|
|
49
54
|
query: (0, matchers_1.regex)((0, graphQL_1.escapeGraphQlQuery)(validatedQuery), validatedQuery),
|
|
50
55
|
variables: this.graphQLRequest.variables,
|
|
51
56
|
})), 'application/json');
|
|
52
57
|
return new interactionWithRequest_1.InteractionWithRequest(this.pact, this.interaction, this.opts, this.cleanupFn);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
}());
|
|
58
|
+
}
|
|
59
|
+
}
|
|
56
60
|
exports.GraphQLInteractionWithRequest = GraphQLInteractionWithRequest;
|
|
57
61
|
//# sourceMappingURL=graphQLInteractionWithRequest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphQLInteractionWithRequest.js","sourceRoot":"","sources":["../../../../src/v4/graphql/graphQLInteractionWithRequest.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"graphQLInteractionWithRequest.js","sourceRoot":"","sources":["../../../../src/v4/graphql/graphQLInteractionWithRequest.ts"],"names":[],"mappings":";;;AAKA,mCAAqC;AACrC,iCAA+B;AAE/B,0DAGsC;AACtC,gDAA0C;AAC1C,2EAAwE;AAExE,mCAIiB;AAEjB,MAAa,6BAA6B;IAK5B;IACA;IACA;IACA;IACA;IANZ,mCAAmC;IACnC,YACY,IAAkB,EAClB,WAAgC,EAChC,IAAmB,EACnB,SAAqB,EACrB,cAA8B;QAJ9B,SAAI,GAAJ,IAAI,CAAc;QAClB,gBAAW,GAAX,WAAW,CAAqB;QAChC,SAAI,GAAJ,IAAI,CAAe;QACnB,cAAS,GAAT,SAAS,CAAY;QACrB,mBAAc,GAAd,cAAc,CAAgB;IACvC,CAAC;IAEJ;;;;;;;;;;;;;;;;;;;OAmBG;IACH,SAAS,CAAC,KAAuB;QAC/B,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,qBAAa,CAAC,KAAK,CAAC,CAAC;IAC1D,CAAC;IAED,YAAY,CAAC,QAA0B;QACrC,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,qBAAa,CAAC,QAAQ,CAAC,CAAC;IAChE,CAAC;IAEO,eAAe,CACrB,KAAuB,EACvB,IAAmB;QAEnB,MAAM,cAAc,GAAG,IAAA,uBAAa,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAElD,IAAI,CAAC,WAAW,CAAC,eAAe,CAC9B,IAAI,CAAC,SAAS,CACZ,IAAA,cAAM,EAAC,oBAAW,EAAE;YAClB,aAAa,EAAE,IAAI,CAAC,cAAc,CAAC,SAAS;YAC5C,KAAK,EAAE,IAAA,gBAAK,EAAC,IAAA,4BAAkB,EAAC,cAAc,CAAC,EAAE,cAAc,CAAC;YAChE,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,SAAS;SACzC,CAAC,CACH,EACD,kBAAkB,CACnB,CAAC;QAEF,OAAO,IAAI,+CAAsB,CAC/B,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,SAAS,CACf,CAAC;IACJ,CAAC;CACF;AAhED,sEAgEC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ConsumerInteraction } from '@pact-foundation/pact-core';
|
|
2
|
-
import {
|
|
3
|
-
import { V4GraphQLRequestBuilder } from './types';
|
|
1
|
+
import type { ConsumerInteraction } from '@pact-foundation/pact-core';
|
|
2
|
+
import type { TemplateHeaders, TemplateQuery } from '../../v3';
|
|
3
|
+
import type { V4GraphQLRequestBuilder } from './types';
|
|
4
4
|
export declare class GraphQLRequestBuilder implements V4GraphQLRequestBuilder {
|
|
5
5
|
protected interaction: ConsumerInteraction;
|
|
6
6
|
constructor(interaction: ConsumerInteraction);
|
|
@@ -1,42 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GraphQLRequestBuilder = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const ramda_1 = require("ramda");
|
|
5
|
+
const matchers_1 = require("../../v3/matchers");
|
|
6
|
+
class GraphQLRequestBuilder {
|
|
7
|
+
interaction;
|
|
7
8
|
// tslint:disable:no-empty-function
|
|
8
|
-
|
|
9
|
+
constructor(interaction) {
|
|
9
10
|
this.interaction = interaction;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
(0, ramda_1.forEachObjIndexed)(function (v, k) {
|
|
12
|
+
query(query) {
|
|
13
|
+
(0, ramda_1.forEachObjIndexed)((v, k) => {
|
|
14
14
|
if (Array.isArray(v)) {
|
|
15
|
-
v.forEach(
|
|
16
|
-
|
|
15
|
+
v.forEach((vv, i) => {
|
|
16
|
+
this.interaction.withQuery(k, i, (0, matchers_1.matcherValueOrString)(vv));
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
|
-
|
|
20
|
+
this.interaction.withQuery(k, 0, (0, matchers_1.matcherValueOrString)(v));
|
|
21
21
|
}
|
|
22
22
|
}, query);
|
|
23
23
|
return this;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
(0, ramda_1.forEachObjIndexed)(function (v, k) {
|
|
24
|
+
}
|
|
25
|
+
headers(headers) {
|
|
26
|
+
(0, ramda_1.forEachObjIndexed)((v, k) => {
|
|
28
27
|
if (Array.isArray(v)) {
|
|
29
|
-
v.forEach(
|
|
30
|
-
|
|
28
|
+
v.forEach((header, index) => {
|
|
29
|
+
this.interaction.withRequestHeader(`${k}`, index, (0, matchers_1.matcherValueOrString)(header));
|
|
31
30
|
});
|
|
32
31
|
}
|
|
33
32
|
else {
|
|
34
|
-
|
|
33
|
+
this.interaction.withRequestHeader(`${k}`, 0, (0, matchers_1.matcherValueOrString)(v));
|
|
35
34
|
}
|
|
36
35
|
}, headers);
|
|
37
36
|
return this;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
}());
|
|
37
|
+
}
|
|
38
|
+
}
|
|
41
39
|
exports.GraphQLRequestBuilder = GraphQLRequestBuilder;
|
|
42
40
|
//# sourceMappingURL=graphQLRequestBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphQLRequestBuilder.js","sourceRoot":"","sources":["../../../../src/v4/graphql/graphQLRequestBuilder.ts"],"names":[],"mappings":";;;AACA
|
|
1
|
+
{"version":3,"file":"graphQLRequestBuilder.js","sourceRoot":"","sources":["../../../../src/v4/graphql/graphQLRequestBuilder.ts"],"names":[],"mappings":";;;AACA,iCAA0C;AAE1C,gDAAyD;AAIzD,MAAa,qBAAqB;IAEV;IADtB,mCAAmC;IACnC,YAAsB,WAAgC;QAAhC,gBAAW,GAAX,WAAW,CAAqB;IAAG,CAAC;IAE1D,KAAK,CAAC,KAAoB;QACxB,IAAA,yBAAiB,EAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACzB,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;gBACpB,CAAe,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE;oBACjC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,IAAA,+BAAoB,EAAC,EAAE,CAAC,CAAC,CAAC;gBAC7D,CAAC,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,IAAA,+BAAoB,EAAC,CAAC,CAAC,CAAC,CAAC;YAC5D,CAAC;QACH,CAAC,EAAE,KAAK,CAAC,CAAC;QAEV,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CAAC,OAAwB;QAC9B,IAAA,yBAAiB,EAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACzB,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;gBACpB,CAA8B,CAAC,OAAO,CACrC,CAAC,MAAgC,EAAE,KAAa,EAAE,EAAE;oBAClD,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAChC,GAAG,CAAC,EAAE,EACN,KAAK,EACL,IAAA,+BAAoB,EAAC,MAAM,CAAC,CAC7B,CAAC;gBACJ,CAAC,CACF,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE,IAAA,+BAAoB,EAAC,CAAC,CAAC,CAAC,CAAC;YACzE,CAAC;QACH,CAAC,EAAE,OAAO,CAAC,CAAC;QAEZ,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AArCD,sDAqCC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ConsumerInteraction, ConsumerPact } from '@pact-foundation/pact-core';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import type { ConsumerInteraction, ConsumerPact } from '@pact-foundation/pact-core';
|
|
2
|
+
import type { GraphQLVariables } from '../../common/graphQL/graphQL';
|
|
3
|
+
import type { JsonMap } from '../../common/jsonTypes';
|
|
4
|
+
import type { Path } from '../../v3';
|
|
5
|
+
import type { PactV4Options } from '../http/types';
|
|
6
|
+
import type { V4GraphQLInteractionWithRequest, V4GraphQLRequestBuilderFunc, V4UnconfiguredGraphQLInteraction } from './types';
|
|
7
7
|
export declare class UnconfiguredGraphQLInteraction implements V4UnconfiguredGraphQLInteraction {
|
|
8
8
|
protected pact: ConsumerPact;
|
|
9
9
|
protected interaction: ConsumerInteraction;
|
package/src/v4/graphql/index.js
CHANGED
|
@@ -1,31 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UnconfiguredGraphQLInteraction = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const matchers_1 = require("../../v3/matchers");
|
|
5
|
+
const graphQLInteractionWithRequest_1 = require("./graphQLInteractionWithRequest");
|
|
6
|
+
const graphQLRequestBuilder_1 = require("./graphQLRequestBuilder");
|
|
7
|
+
class UnconfiguredGraphQLInteraction {
|
|
8
|
+
pact;
|
|
9
|
+
interaction;
|
|
10
|
+
opts;
|
|
11
|
+
cleanupFn;
|
|
12
|
+
graphQLRequest;
|
|
8
13
|
// tslint:disable:no-empty-function
|
|
9
|
-
|
|
14
|
+
constructor(pact, interaction, opts, cleanupFn) {
|
|
10
15
|
this.pact = pact;
|
|
11
16
|
this.interaction = interaction;
|
|
12
17
|
this.opts = opts;
|
|
13
18
|
this.cleanupFn = cleanupFn;
|
|
14
19
|
this.graphQLRequest = {};
|
|
15
20
|
}
|
|
16
|
-
|
|
21
|
+
withOperation(operation) {
|
|
17
22
|
this.graphQLRequest.operation = operation;
|
|
18
23
|
return this;
|
|
19
|
-
}
|
|
20
|
-
|
|
24
|
+
}
|
|
25
|
+
withVariables(variables) {
|
|
21
26
|
this.graphQLRequest.variables = variables;
|
|
22
27
|
return this;
|
|
23
|
-
}
|
|
24
|
-
|
|
28
|
+
}
|
|
29
|
+
uponReceiving(description) {
|
|
25
30
|
this.interaction.uponReceiving(description);
|
|
26
31
|
return this;
|
|
27
|
-
}
|
|
28
|
-
|
|
32
|
+
}
|
|
33
|
+
given(state, parameters) {
|
|
29
34
|
if (parameters) {
|
|
30
35
|
this.interaction.givenWithParams(state, JSON.stringify(parameters));
|
|
31
36
|
}
|
|
@@ -33,15 +38,14 @@ var UnconfiguredGraphQLInteraction = /** @class */ (function () {
|
|
|
33
38
|
this.interaction.given(state);
|
|
34
39
|
}
|
|
35
40
|
return this;
|
|
36
|
-
}
|
|
37
|
-
|
|
41
|
+
}
|
|
42
|
+
withRequest(method, path, builder) {
|
|
38
43
|
this.interaction.withRequest(method, (0, matchers_1.matcherValueOrString)(path));
|
|
39
44
|
if (builder) {
|
|
40
45
|
builder(new graphQLRequestBuilder_1.GraphQLRequestBuilder(this.interaction));
|
|
41
46
|
}
|
|
42
47
|
return new graphQLInteractionWithRequest_1.GraphQLInteractionWithRequest(this.pact, this.interaction, this.opts, this.cleanupFn, this.graphQLRequest);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
}());
|
|
48
|
+
}
|
|
49
|
+
}
|
|
46
50
|
exports.UnconfiguredGraphQLInteraction = UnconfiguredGraphQLInteraction;
|
|
47
51
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/v4/graphql/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/v4/graphql/index.ts"],"names":[],"mappings":";;;AAOA,gDAAyD;AAEzD,mFAAgF;AAChF,mEAAgE;AAQhE,MAAa,8BAA8B;IAO7B;IACA;IACA;IACA;IAPJ,cAAc,CAAiB;IAEvC,mCAAmC;IACnC,YACY,IAAkB,EAClB,WAAgC,EAChC,IAAmB,EACnB,SAAqB;QAHrB,SAAI,GAAJ,IAAI,CAAc;QAClB,gBAAW,GAAX,WAAW,CAAqB;QAChC,SAAI,GAAJ,IAAI,CAAe;QACnB,cAAS,GAAT,SAAS,CAAY;QAE/B,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;IAC3B,CAAC;IAED,aAAa,CAAC,SAAiB;QAC7B,IAAI,CAAC,cAAc,CAAC,SAAS,GAAG,SAAS,CAAC;QAE1C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,aAAa,CAAC,SAA2B;QACvC,IAAI,CAAC,cAAc,CAAC,SAAS,GAAG,SAAS,CAAC;QAE1C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,aAAa,CAAC,WAAmB;QAC/B,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;QAE5C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,KAAa,EAAE,UAAoB;QACvC,IAAI,UAAU,EAAE,CAAC;YACf,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;QACtE,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,WAAW,CACT,MAAc,EACd,IAAU,EACV,OAAqC;QAErC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,MAAM,EAAE,IAAA,+BAAoB,EAAC,IAAI,CAAC,CAAC,CAAC;QAEjE,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,CAAC,IAAI,6CAAqB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,IAAI,6DAA6B,CACtC,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,cAAc,CACpB,CAAC;IACJ,CAAC;CACF;AA7DD,wEA6DC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ASTNode } from 'graphql';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import type { ASTNode } from 'graphql';
|
|
2
|
+
import type { GraphQLVariables } from '../../common/graphQL/graphQL';
|
|
3
|
+
import type { JsonMap } from '../../common/jsonTypes';
|
|
4
|
+
import type { Path, TemplateHeaders, TemplateQuery } from '../../v3';
|
|
5
|
+
import type { V4InteractionWithRequest } from '../http/types';
|
|
6
6
|
export declare enum OperationType {
|
|
7
7
|
Mutation = "Mutation",
|
|
8
8
|
Query = "Query"
|
package/src/v4/http/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConsumerPact } from '@pact-foundation/pact-core';
|
|
2
|
-
import { PactV4Options, TestFunction } from './types';
|
|
1
|
+
import type { ConsumerPact } from '@pact-foundation/pact-core';
|
|
2
|
+
import type { PactV4Options, TestFunction } from './types';
|
|
3
3
|
export declare const readBinaryData: (file: string) => Buffer;
|
|
4
4
|
export declare const executeTest: <T>(pact: ConsumerPact, opts: PactV4Options, testFn: TestFunction<T>, cleanupFn: () => void) => Promise<T | undefined>;
|
package/src/v4/http/index.js
CHANGED
|
@@ -1,59 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
6
|
exports.executeTest = exports.readBinaryData = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
7
|
+
const fs = require("node:fs");
|
|
8
|
+
const logger_1 = __importDefault(require("../../common/logger"));
|
|
9
|
+
const display_1 = require("../../v3/display");
|
|
10
|
+
const readBinaryData = (file) => {
|
|
47
11
|
try {
|
|
48
|
-
|
|
12
|
+
const body = fs.readFileSync(file);
|
|
49
13
|
return body;
|
|
50
14
|
}
|
|
51
15
|
catch (e) {
|
|
52
|
-
|
|
16
|
+
const error = e instanceof Error ? e : new Error(String(e));
|
|
17
|
+
throw new Error(`unable to read file for binary payload : ${error.message}`);
|
|
53
18
|
}
|
|
54
19
|
};
|
|
55
20
|
exports.readBinaryData = readBinaryData;
|
|
56
|
-
|
|
21
|
+
const cleanup = (success, pact, opts, server, cleanupFn) => {
|
|
57
22
|
if (success) {
|
|
58
23
|
pact.writePactFile(opts.dir || './pacts');
|
|
59
24
|
}
|
|
@@ -61,56 +26,51 @@ var cleanup = function (success, pact, opts, server, cleanupFn) {
|
|
|
61
26
|
pact.cleanupPlugins();
|
|
62
27
|
cleanupFn();
|
|
63
28
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (error) {
|
|
98
|
-
logger_1.default.error(errorMessage);
|
|
99
|
-
throw error;
|
|
100
|
-
}
|
|
101
|
-
// Test didn't throw, so we need to ensure the test fails
|
|
102
|
-
return [2 /*return*/, Promise.reject(new Error(errorMessage))];
|
|
103
|
-
}
|
|
104
|
-
// Scenario: test threw an error, but Pact validation was OK (error in client or test)
|
|
105
|
-
if (error) {
|
|
106
|
-
cleanup(false, pact, opts, server, cleanupFn);
|
|
107
|
-
throw error;
|
|
108
|
-
}
|
|
109
|
-
// Scenario: Pact validation passed, test didn't throw - return the callback value
|
|
110
|
-
cleanup(true, pact, opts, server, cleanupFn);
|
|
111
|
-
return [2 /*return*/, val];
|
|
29
|
+
const executeTest = async (pact, opts, testFn, cleanupFn) => {
|
|
30
|
+
const scheme = opts.tls ? 'https' : 'http';
|
|
31
|
+
const host = opts.host || '127.0.0.1';
|
|
32
|
+
const cors = opts.cors ?? true;
|
|
33
|
+
const config = JSON.stringify({ corsPreflight: cors });
|
|
34
|
+
const port = pact.pactffiCreateMockServerForTransport(host, scheme, config, opts.port);
|
|
35
|
+
if (port <= 0) {
|
|
36
|
+
throw new Error(`Failed to start mock server: received error code ${port}`);
|
|
37
|
+
}
|
|
38
|
+
const server = { port, url: `${scheme}://${host}:${port}`, id: 'unknown' };
|
|
39
|
+
let val;
|
|
40
|
+
let error;
|
|
41
|
+
try {
|
|
42
|
+
val = await testFn(server);
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
error = e instanceof Error ? e : new Error(String(e));
|
|
46
|
+
}
|
|
47
|
+
const matchingResults = pact.mockServerMismatches(port);
|
|
48
|
+
const errors = (0, display_1.filterMissingFeatureFlag)(matchingResults);
|
|
49
|
+
const success = pact.mockServerMatchedSuccessfully(port);
|
|
50
|
+
// Scenario: Pact validation failed
|
|
51
|
+
if (!success && errors.length > 0) {
|
|
52
|
+
let errorMessage = 'Test failed for the following reasons:';
|
|
53
|
+
errorMessage += `\n\n ${(0, display_1.generateMockServerError)(matchingResults, '\t')}`;
|
|
54
|
+
cleanup(false, pact, opts, server, cleanupFn);
|
|
55
|
+
// If the tests throws an error, we need to rethrow the error, but print out
|
|
56
|
+
// any additional mock server errors to help the user understand what happened
|
|
57
|
+
// (The proximate cause here is often the HTTP 500 from the mock server,
|
|
58
|
+
// where the HTTP client then throws)
|
|
59
|
+
if (error) {
|
|
60
|
+
logger_1.default.error(errorMessage);
|
|
61
|
+
throw error;
|
|
112
62
|
}
|
|
113
|
-
|
|
114
|
-
|
|
63
|
+
// Test didn't throw, so we need to ensure the test fails
|
|
64
|
+
return Promise.reject(new Error(errorMessage));
|
|
65
|
+
}
|
|
66
|
+
// Scenario: test threw an error, but Pact validation was OK (error in client or test)
|
|
67
|
+
if (error) {
|
|
68
|
+
cleanup(false, pact, opts, server, cleanupFn);
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
// Scenario: Pact validation passed, test didn't throw - return the callback value
|
|
72
|
+
cleanup(true, pact, opts, server, cleanupFn);
|
|
73
|
+
return val;
|
|
74
|
+
};
|
|
115
75
|
exports.executeTest = executeTest;
|
|
116
76
|
//# sourceMappingURL=index.js.map
|
package/src/v4/http/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/v4/http/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/v4/http/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|