@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.
Files changed (261) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/CONTRIBUTING.md +2 -2
  3. package/README.md +22 -12
  4. package/package.json +26 -47
  5. package/scripts/ci/build-and-test.sh +0 -3
  6. package/scripts/install-plugins.js +104 -0
  7. package/src/common/graphQL/configurationError.js +2 -22
  8. package/src/common/graphQL/configurationError.js.map +1 -1
  9. package/src/common/graphQL/graphQL.d.ts +2 -2
  10. package/src/common/graphQL/graphQL.js +11 -14
  11. package/src/common/graphQL/graphQL.js.map +1 -1
  12. package/src/common/graphQL/graphQLQueryError.js +2 -22
  13. package/src/common/graphQL/graphQLQueryError.js.map +1 -1
  14. package/src/common/logger.js +9 -9
  15. package/src/common/logger.js.map +1 -1
  16. package/src/common/matchingRules.d.ts +7 -1
  17. package/src/common/matchingRules.js +42 -22
  18. package/src/common/matchingRules.js.map +1 -1
  19. package/src/common/net.js +36 -42
  20. package/src/common/net.js.map +1 -1
  21. package/src/common/net.spec.js +39 -87
  22. package/src/common/net.spec.js.map +1 -1
  23. package/src/common/request.js +33 -82
  24. package/src/common/request.js.map +1 -1
  25. package/src/common/request.spec.js +29 -73
  26. package/src/common/request.spec.js.map +1 -1
  27. package/src/common/spec.js +3 -4
  28. package/src/common/spec.js.map +1 -1
  29. package/src/dsl/apolloGraphql.js +7 -25
  30. package/src/dsl/apolloGraphql.js.map +1 -1
  31. package/src/dsl/apolloGraphql.spec.js +21 -58
  32. package/src/dsl/apolloGraphql.spec.js.map +1 -1
  33. package/src/dsl/graphql.d.ts +2 -2
  34. package/src/dsl/graphql.js +29 -48
  35. package/src/dsl/graphql.js.map +1 -1
  36. package/src/dsl/graphql.spec.js +92 -117
  37. package/src/dsl/graphql.spec.js.map +1 -1
  38. package/src/dsl/interaction.d.ts +2 -2
  39. package/src/dsl/interaction.js +41 -48
  40. package/src/dsl/interaction.js.map +1 -1
  41. package/src/dsl/interaction.spec.js +109 -132
  42. package/src/dsl/interaction.spec.js.map +1 -1
  43. package/src/dsl/matchers.d.ts +2 -3
  44. package/src/dsl/matchers.js +19 -31
  45. package/src/dsl/matchers.js.map +1 -1
  46. package/src/dsl/matchers.spec.js +279 -289
  47. package/src/dsl/matchers.spec.js.map +1 -1
  48. package/src/dsl/message.d.ts +3 -3
  49. package/src/dsl/options.d.ts +3 -3
  50. package/src/dsl/verifier/proxy/hooks.d.ts +2 -2
  51. package/src/dsl/verifier/proxy/hooks.js +42 -112
  52. package/src/dsl/verifier/proxy/hooks.js.map +1 -1
  53. package/src/dsl/verifier/proxy/hooks.spec.js +86 -199
  54. package/src/dsl/verifier/proxy/hooks.spec.js.map +1 -1
  55. package/src/dsl/verifier/proxy/messages.d.ts +2 -2
  56. package/src/dsl/verifier/proxy/messages.js +88 -106
  57. package/src/dsl/verifier/proxy/messages.js.map +1 -1
  58. package/src/dsl/verifier/proxy/parseBody.d.ts +1 -1
  59. package/src/dsl/verifier/proxy/parseBody.js +3 -3
  60. package/src/dsl/verifier/proxy/parseBody.js.map +1 -1
  61. package/src/dsl/verifier/proxy/parseBody.spec.js +35 -113
  62. package/src/dsl/verifier/proxy/parseBody.spec.js.map +1 -1
  63. package/src/dsl/verifier/proxy/proxy.d.ts +2 -2
  64. package/src/dsl/verifier/proxy/proxy.js +22 -26
  65. package/src/dsl/verifier/proxy/proxy.js.map +1 -1
  66. package/src/dsl/verifier/proxy/proxy.spec.js +11 -53
  67. package/src/dsl/verifier/proxy/proxy.spec.js.map +1 -1
  68. package/src/dsl/verifier/proxy/proxyRequest.d.ts +3 -3
  69. package/src/dsl/verifier/proxy/proxyRequest.js +7 -7
  70. package/src/dsl/verifier/proxy/proxyRequest.js.map +1 -1
  71. package/src/dsl/verifier/proxy/proxyRequest.spec.js +54 -104
  72. package/src/dsl/verifier/proxy/proxyRequest.spec.js.map +1 -1
  73. package/src/dsl/verifier/proxy/stateHandler/setupStates.d.ts +3 -3
  74. package/src/dsl/verifier/proxy/stateHandler/setupStates.js +14 -18
  75. package/src/dsl/verifier/proxy/stateHandler/setupStates.js.map +1 -1
  76. package/src/dsl/verifier/proxy/stateHandler/setupStates.spec.js +76 -193
  77. package/src/dsl/verifier/proxy/stateHandler/setupStates.spec.js.map +1 -1
  78. package/src/dsl/verifier/proxy/stateHandler/stateHandler.d.ts +2 -2
  79. package/src/dsl/verifier/proxy/stateHandler/stateHandler.js +23 -72
  80. package/src/dsl/verifier/proxy/stateHandler/stateHandler.js.map +1 -1
  81. package/src/dsl/verifier/proxy/stateHandler/stateHandler.spec.js +37 -122
  82. package/src/dsl/verifier/proxy/stateHandler/stateHandler.spec.js.map +1 -1
  83. package/src/dsl/verifier/proxy/tracer.d.ts +1 -1
  84. package/src/dsl/verifier/proxy/tracer.js +42 -35
  85. package/src/dsl/verifier/proxy/tracer.js.map +1 -1
  86. package/src/dsl/verifier/proxy/types.d.ts +5 -5
  87. package/src/dsl/verifier/types.d.ts +3 -3
  88. package/src/dsl/verifier/verifier.d.ts +5 -1
  89. package/src/dsl/verifier/verifier.js +53 -60
  90. package/src/dsl/verifier/verifier.js.map +1 -1
  91. package/src/dsl/verifier/verifier.spec.js +84 -151
  92. package/src/dsl/verifier/verifier.spec.js.map +1 -1
  93. package/src/errors/configurationError.js +2 -22
  94. package/src/errors/configurationError.js.map +1 -1
  95. package/src/errors/graphQLQueryError.js +2 -22
  96. package/src/errors/graphQLQueryError.js.map +1 -1
  97. package/src/errors/matcherError.js +2 -22
  98. package/src/errors/matcherError.js.map +1 -1
  99. package/src/errors/verificationError.js +2 -22
  100. package/src/errors/verificationError.js.map +1 -1
  101. package/src/httpPact/ffi.d.ts +2 -2
  102. package/src/httpPact/ffi.js +28 -29
  103. package/src/httpPact/ffi.js.map +1 -1
  104. package/src/httpPact/ffi.spec.js +40 -83
  105. package/src/httpPact/ffi.spec.js.map +1 -1
  106. package/src/httpPact/index.d.ts +3 -3
  107. package/src/httpPact/index.js +92 -149
  108. package/src/httpPact/index.js.map +1 -1
  109. package/src/httpPact/index.spec.js +102 -195
  110. package/src/httpPact/index.spec.js.map +1 -1
  111. package/src/httpPact/tracing.js +20 -28
  112. package/src/httpPact/tracing.js.map +1 -1
  113. package/src/index.d.ts +25 -25
  114. package/src/index.js +29 -29
  115. package/src/index.js.map +1 -1
  116. package/src/messageConsumerPact.d.ts +5 -5
  117. package/src/messageConsumerPact.js +59 -53
  118. package/src/messageConsumerPact.js.map +1 -1
  119. package/src/messageConsumerPact.spec.js +55 -97
  120. package/src/messageConsumerPact.spec.js.map +1 -1
  121. package/src/messageProviderPact.d.ts +3 -3
  122. package/src/messageProviderPact.js +68 -85
  123. package/src/messageProviderPact.js.map +1 -1
  124. package/src/messageProviderPact.spec.js +96 -123
  125. package/src/messageProviderPact.spec.js.map +1 -1
  126. package/src/pact.integration.spec.js +242 -351
  127. package/src/pact.integration.spec.js.map +1 -1
  128. package/src/v3/display.d.ts +1 -1
  129. package/src/v3/display.js +44 -58
  130. package/src/v3/display.js.map +1 -1
  131. package/src/v3/ffi.js +20 -16
  132. package/src/v3/ffi.js.map +1 -1
  133. package/src/v3/ffi.spec.js +7 -42
  134. package/src/v3/ffi.spec.js.map +1 -1
  135. package/src/v3/graphql/graphQL.d.ts +4 -4
  136. package/src/v3/graphql/graphQL.js +50 -75
  137. package/src/v3/graphql/graphQL.js.map +1 -1
  138. package/src/v3/graphql/index.d.ts +1 -1
  139. package/src/v3/graphql/index.js +1 -1
  140. package/src/v3/graphql/index.js.map +1 -1
  141. package/src/v3/index.d.ts +4 -12
  142. package/src/v3/index.js +4 -12
  143. package/src/v3/index.js.map +1 -1
  144. package/src/v3/matchers.d.ts +15 -3
  145. package/src/v3/matchers.js +131 -148
  146. package/src/v3/matchers.js.map +1 -1
  147. package/src/v3/matchers.spec.js +281 -232
  148. package/src/v3/matchers.spec.js.map +1 -1
  149. package/src/v3/pact.d.ts +2 -2
  150. package/src/v3/pact.js +108 -151
  151. package/src/v3/pact.js.map +1 -1
  152. package/src/v3/pact.spec.js +94 -0
  153. package/src/v3/pact.spec.js.map +1 -0
  154. package/src/v3/types.d.ts +19 -3
  155. package/src/v3/types.js +22 -1
  156. package/src/v3/types.js.map +1 -1
  157. package/src/v4/graphql/graphQLInteractionWithRequest.d.ts +4 -4
  158. package/src/v4/graphql/graphQLInteractionWithRequest.js +21 -17
  159. package/src/v4/graphql/graphQLInteractionWithRequest.js.map +1 -1
  160. package/src/v4/graphql/graphQLRequestBuilder.d.ts +3 -3
  161. package/src/v4/graphql/graphQLRequestBuilder.js +18 -20
  162. package/src/v4/graphql/graphQLRequestBuilder.js.map +1 -1
  163. package/src/v4/graphql/index.d.ts +6 -6
  164. package/src/v4/graphql/index.js +21 -17
  165. package/src/v4/graphql/index.js.map +1 -1
  166. package/src/v4/graphql/types.d.ts +5 -5
  167. package/src/v4/http/index.d.ts +2 -2
  168. package/src/v4/http/index.js +53 -93
  169. package/src/v4/http/index.js.map +1 -1
  170. package/src/v4/http/index.spec.d.ts +1 -0
  171. package/src/v4/http/index.spec.js +73 -0
  172. package/src/v4/http/index.spec.js.map +1 -0
  173. package/src/v4/http/interactionWithCompleteRequest.d.ts +4 -7
  174. package/src/v4/http/interactionWithCompleteRequest.js +6 -10
  175. package/src/v4/http/interactionWithCompleteRequest.js.map +1 -1
  176. package/src/v4/http/interactionWithPlugin.d.ts +3 -3
  177. package/src/v4/http/interactionWithPlugin.js +14 -11
  178. package/src/v4/http/interactionWithPlugin.js.map +1 -1
  179. package/src/v4/http/interactionWithPluginRequest.d.ts +4 -3
  180. package/src/v4/http/interactionWithPluginRequest.js +17 -9
  181. package/src/v4/http/interactionWithPluginRequest.js.map +1 -1
  182. package/src/v4/http/interactionWithPluginResponse.d.ts +2 -2
  183. package/src/v4/http/interactionWithPluginResponse.js +10 -48
  184. package/src/v4/http/interactionWithPluginResponse.js.map +1 -1
  185. package/src/v4/http/interactionWithRequest.d.ts +4 -3
  186. package/src/v4/http/interactionWithRequest.js +17 -9
  187. package/src/v4/http/interactionWithRequest.js.map +1 -1
  188. package/src/v4/http/interactionWithRequest.spec.d.ts +1 -0
  189. package/src/v4/http/interactionWithRequest.spec.js +82 -0
  190. package/src/v4/http/interactionWithRequest.spec.js.map +1 -0
  191. package/src/v4/http/interactionWithResponse.d.ts +2 -2
  192. package/src/v4/http/interactionWithResponse.js +10 -48
  193. package/src/v4/http/interactionWithResponse.js.map +1 -1
  194. package/src/v4/http/requestBuilder.d.ts +4 -3
  195. package/src/v4/http/requestBuilder.js +36 -34
  196. package/src/v4/http/requestBuilder.js.map +1 -1
  197. package/src/v4/http/requestBuilder.spec.d.ts +1 -0
  198. package/src/v4/http/requestBuilder.spec.js +42 -0
  199. package/src/v4/http/requestBuilder.spec.js.map +1 -0
  200. package/src/v4/http/requestWithPluginBuilder.d.ts +3 -2
  201. package/src/v4/http/requestWithPluginBuilder.js +30 -46
  202. package/src/v4/http/requestWithPluginBuilder.js.map +1 -1
  203. package/src/v4/http/requestWithPluginBuilder.spec.d.ts +1 -0
  204. package/src/v4/http/requestWithPluginBuilder.spec.js +34 -0
  205. package/src/v4/http/requestWithPluginBuilder.spec.js.map +1 -0
  206. package/src/v4/http/responseBuilder.d.ts +4 -3
  207. package/src/v4/http/responseBuilder.js +28 -25
  208. package/src/v4/http/responseBuilder.js.map +1 -1
  209. package/src/v4/http/responseBuilder.spec.d.ts +1 -0
  210. package/src/v4/http/responseBuilder.spec.js +42 -0
  211. package/src/v4/http/responseBuilder.spec.js.map +1 -0
  212. package/src/v4/http/responseWithPluginBuilder.d.ts +1 -1
  213. package/src/v4/http/responseWithPluginBuilder.js +5 -25
  214. package/src/v4/http/responseWithPluginBuilder.js.map +1 -1
  215. package/src/v4/http/responseWithPluginBuilder.spec.d.ts +1 -0
  216. package/src/v4/http/responseWithPluginBuilder.spec.js +34 -0
  217. package/src/v4/http/responseWithPluginBuilder.spec.js.map +1 -0
  218. package/src/v4/http/types.d.ts +13 -4
  219. package/src/v4/http/unconfiguredInteraction.d.ts +6 -5
  220. package/src/v4/http/unconfiguredInteraction.js +31 -26
  221. package/src/v4/http/unconfiguredInteraction.js.map +1 -1
  222. package/src/v4/index.d.ts +6 -5
  223. package/src/v4/index.js +32 -35
  224. package/src/v4/index.js.map +1 -1
  225. package/src/v4/message/asynchronousMessage.d.ts +7 -6
  226. package/src/v4/message/asynchronousMessage.js +157 -190
  227. package/src/v4/message/asynchronousMessage.js.map +1 -1
  228. package/src/v4/message/index.d.ts +7 -6
  229. package/src/v4/message/index.js +188 -217
  230. package/src/v4/message/index.js.map +1 -1
  231. package/src/v4/message/types.d.ts +5 -3
  232. package/src/v4/types.d.ts +3 -3
  233. package/src/xml/index.d.ts +4 -0
  234. package/src/xml/index.js +21 -0
  235. package/src/xml/index.js.map +1 -0
  236. package/src/{v3/xml → xml}/xmlBuilder.d.ts +1 -3
  237. package/src/{v3/xml → xml}/xmlBuilder.js +7 -9
  238. package/src/xml/xmlBuilder.js.map +1 -0
  239. package/src/{v3/xml → xml}/xmlElement.d.ts +2 -2
  240. package/src/xml/xmlElement.js +73 -0
  241. package/src/xml/xmlElement.js.map +1 -0
  242. package/src/xml/xmlElement.spec.d.ts +1 -0
  243. package/src/xml/xmlElement.spec.js +107 -0
  244. package/src/xml/xmlElement.spec.js.map +1 -0
  245. package/src/xml/xmlNode.js +7 -0
  246. package/src/xml/xmlNode.js.map +1 -0
  247. package/src/{v3/xml → xml}/xmlText.d.ts +1 -1
  248. package/src/xml/xmlText.js +15 -0
  249. package/src/xml/xmlText.js.map +1 -0
  250. package/scripts/install-plugins +0 -106
  251. package/src/v3/xml/xmlBuilder.js.map +0 -1
  252. package/src/v3/xml/xmlElement.js +0 -90
  253. package/src/v3/xml/xmlElement.js.map +0 -1
  254. package/src/v3/xml/xmlElement.spec.js +0 -113
  255. package/src/v3/xml/xmlElement.spec.js.map +0 -1
  256. package/src/v3/xml/xmlNode.js +0 -10
  257. package/src/v3/xml/xmlNode.js.map +0 -1
  258. package/src/v3/xml/xmlText.js +0 -31
  259. package/src/v3/xml/xmlText.js.map +0 -1
  260. /package/src/v3/{xml/xmlElement.spec.d.ts → pact.spec.d.ts} +0 -0
  261. /package/src/{v3/xml → xml}/xmlNode.d.ts +0 -0
@@ -1,121 +1,84 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- var __generator = (this && this.__generator) || function (thisArg, body) {
45
- 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);
46
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
47
- function verb(n) { return function (v) { return step([n, v]); }; }
48
- function step(op) {
49
- if (f) throw new TypeError("Generator is already executing.");
50
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
51
- 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;
52
- if (y = 0, t) op = [op[0] & 2, t.value];
53
- switch (op[0]) {
54
- case 0: case 1: t = op; break;
55
- case 4: _.label++; return { value: op[1], done: false };
56
- case 5: _.label++; y = op[1]; op = [0]; continue;
57
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
58
- default:
59
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
60
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
61
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
62
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
63
- if (t[2]) _.ops.pop();
64
- _.trys.pop(); continue;
65
- }
66
- op = body.call(thisArg, _);
67
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
68
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
69
- }
70
- };
71
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
72
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
73
4
  };
74
5
  Object.defineProperty(exports, "__esModule", { value: true });
75
- /* tslint:disable:no-unused-expression no-empty */
76
- var chai = __importStar(require("chai"));
77
- var chai_as_promised_1 = __importDefault(require("chai-as-promised"));
78
- var sinon_chai_1 = __importDefault(require("sinon-chai"));
79
- var axios_1 = __importDefault(require("axios"));
80
- var fs = require("fs");
81
- var net = require("net");
82
- var path = require("path");
83
- // eslint-disable-next-line import/first
84
- var v4_1 = require("./v4");
85
- var v3_1 = require("./v3");
86
- var expect = chai.expect;
87
- chai.use(sinon_chai_1.default);
88
- chai.use(chai_as_promised_1.default);
89
- describe('V4 Pact', function () {
90
- var pact;
91
- var pactFilePath = path.resolve(process.cwd(), 'pacts', 'v4consumer-v4provider.json');
92
- var interactionByDescription = function (description) {
93
- var pactJson = JSON.parse(fs.readFileSync(pactFilePath, 'utf8'));
94
- var matches = pactJson.interactions.filter(function (item) { return item.description === description; });
95
- expect(matches, "expected exactly one interaction for \"".concat(description, "\"")).to.have.lengthOf(1);
96
- var interaction = matches[0];
6
+ const axios_1 = __importDefault(require("axios"));
7
+ const fs = require("node:fs");
8
+ const net = require("node:net");
9
+ const path = require("node:path");
10
+ const v3_1 = require("./v3");
11
+ const v4_1 = require("./v4");
12
+ describe('V4 Pact', () => {
13
+ let pact;
14
+ const pactFilePath = path.resolve(process.cwd(), 'pacts', 'v4consumer-v4provider.json');
15
+ const interactionByDescription = (description) => {
16
+ const pactJson = JSON.parse(fs.readFileSync(pactFilePath, 'utf8'));
17
+ const matches = pactJson.interactions.filter((item) => item.description === description);
18
+ expect(matches, `expected exactly one interaction for "${description}"`).toHaveLength(1);
19
+ const [interaction] = matches;
97
20
  return interaction;
98
21
  };
99
- var expectCommentsToContain = function (interaction, reason, textComment, testName) {
100
- var comments = interaction.comments;
101
- expect(comments.reason).to.equal(reason);
102
- expect(comments.text).to.include(textComment);
103
- expect(comments.testname).to.equal(testName);
22
+ const expectCommentsToContain = (interaction, reason, textComment, testName) => {
23
+ const comments = interaction.comments;
24
+ expect(comments.reason).toBe(reason);
25
+ expect(comments.text).toContain(textComment);
26
+ expect(comments.testname).toBe(testName);
27
+ };
28
+ const expectReferenceToEqual = (interaction, group, name, value) => {
29
+ const comments = interaction.comments;
30
+ const references = comments.references;
31
+ expect(references[group][name]).toBe(value);
104
32
  };
105
- beforeEach(function () {
33
+ beforeEach(() => {
106
34
  pact = new v4_1.PactV4({
107
35
  consumer: 'v4consumer',
108
36
  provider: 'v4provider',
109
37
  });
110
38
  });
111
- describe('HTTP req/res contract', function () {
112
- it('generates a pact', function () {
113
- return pact
39
+ describe('HTTP req/res contract', () => {
40
+ it('generates a pact', () => pact
41
+ .addInteraction()
42
+ .given('some state')
43
+ .given('a second state')
44
+ .uponReceiving('a standard HTTP req/res')
45
+ .withRequest('POST', '/', (builder) => {
46
+ builder
47
+ .jsonBody({
48
+ foo: 'bar',
49
+ })
50
+ .headers({
51
+ 'x-foo': 'x-bar',
52
+ });
53
+ })
54
+ .willRespondWith(200, (builder) => {
55
+ builder
56
+ .jsonBody({
57
+ foo: 'bar',
58
+ })
59
+ .headers({
60
+ 'x-foo': 'x-bar',
61
+ });
62
+ })
63
+ .executeTest(async (server) => axios_1.default.post(server.url, {
64
+ foo: 'bar',
65
+ }, {
66
+ headers: {
67
+ 'x-foo': 'x-bar',
68
+ },
69
+ })));
70
+ it('generates a pact with interaction metadata', async () => {
71
+ const description = 'v4 metadata http req/res interaction';
72
+ await pact
114
73
  .addInteraction()
115
74
  .given('some state')
116
75
  .given('a second state')
117
- .uponReceiving('a standard HTTP req/res')
118
- .withRequest('POST', '/', function (builder) {
76
+ .uponReceiving(description)
77
+ .pending()
78
+ .comment({ key: 'reason', value: 'covered by HTTP metadata test' })
79
+ .comment('second note from HTTP metadata test')
80
+ .testName('http metadata test name')
81
+ .withRequest('POST', '/', (builder) => {
119
82
  builder
120
83
  .jsonBody({
121
84
  foo: 'bar',
@@ -124,7 +87,7 @@ describe('V4 Pact', function () {
124
87
  'x-foo': 'x-bar',
125
88
  });
126
89
  })
127
- .willRespondWith(200, function (builder) {
90
+ .willRespondWith(200, (builder) => {
128
91
  builder
129
92
  .jsonBody({
130
93
  foo: 'bar',
@@ -133,264 +96,200 @@ describe('V4 Pact', function () {
133
96
  'x-foo': 'x-bar',
134
97
  });
135
98
  })
136
- .executeTest(function (server) { return __awaiter(void 0, void 0, void 0, function () {
137
- return __generator(this, function (_a) {
138
- return [2 /*return*/, axios_1.default.post(server.url, {
139
- foo: 'bar',
140
- }, {
141
- headers: {
142
- 'x-foo': 'x-bar',
143
- },
144
- })];
145
- });
146
- }); });
99
+ .executeTest(async (server) => axios_1.default.post(server.url, {
100
+ foo: 'bar',
101
+ }, {
102
+ headers: {
103
+ 'x-foo': 'x-bar',
104
+ },
105
+ }));
106
+ const interaction = interactionByDescription(description);
107
+ expect(interaction.pending).toBe(true);
108
+ expectCommentsToContain(interaction, 'covered by HTTP metadata test', 'second note from HTTP metadata test', 'http metadata test name');
147
109
  });
148
- it('generates a pact with interaction metadata', function () { return __awaiter(void 0, void 0, void 0, function () {
149
- var description, interaction;
150
- return __generator(this, function (_a) {
151
- switch (_a.label) {
152
- case 0:
153
- description = 'v4 metadata http req/res interaction';
154
- return [4 /*yield*/, pact
155
- .addInteraction()
156
- .given('some state')
157
- .given('a second state')
158
- .uponReceiving(description)
159
- .pending()
160
- .comment({ key: 'reason', value: 'covered by HTTP metadata test' })
161
- .comment('second note from HTTP metadata test')
162
- .testName('http metadata test name')
163
- .withRequest('POST', '/', function (builder) {
164
- builder
165
- .jsonBody({
166
- foo: 'bar',
167
- })
168
- .headers({
169
- 'x-foo': 'x-bar',
170
- });
171
- })
172
- .willRespondWith(200, function (builder) {
173
- builder
174
- .jsonBody({
175
- foo: 'bar',
176
- })
177
- .headers({
178
- 'x-foo': 'x-bar',
179
- });
180
- })
181
- .executeTest(function (server) { return __awaiter(void 0, void 0, void 0, function () {
182
- return __generator(this, function (_a) {
183
- return [2 /*return*/, axios_1.default.post(server.url, {
184
- foo: 'bar',
185
- }, {
186
- headers: {
187
- 'x-foo': 'x-bar',
188
- },
189
- })];
190
- });
191
- }); })];
192
- case 1:
193
- _a.sent();
194
- interaction = interactionByDescription(description);
195
- expect(interaction.pending).to.equal(true);
196
- expectCommentsToContain(interaction, 'covered by HTTP metadata test', 'second note from HTTP metadata test', 'http metadata test name');
197
- return [2 /*return*/];
198
- }
199
- });
200
- }); });
201
- it('supports regex matcher for response content-type with optional charset', function () {
202
- return pact
110
+ it('records interaction references in the pact file', async () => {
111
+ const description = 'v4 http interaction with references';
112
+ await pact
203
113
  .addInteraction()
204
- .uponReceiving('a response with regex content-type header matcher')
114
+ .uponReceiving(description)
115
+ .reference('Jira', 'TICKET-123', 'https://jira.example.com/TICKET-123')
205
116
  .withRequest('GET', '/')
206
- .willRespondWith(200, function (builder) {
207
- builder
208
- .headers({
209
- 'Content-Type': v3_1.MatchersV3.regex(/^application\/json(;\s?charset=[\w-]+)?$/i, 'application/json'),
210
- })
211
- .jsonBody({
212
- foo: 'bar',
213
- });
117
+ .willRespondWith(200)
118
+ .executeTest(async (server) => axios_1.default.get(server.url));
119
+ const interaction = interactionByDescription(description);
120
+ expectReferenceToEqual(interaction, 'Jira', 'TICKET-123', 'https://jira.example.com/TICKET-123');
121
+ });
122
+ it('supports regex matcher for response content-type with optional charset', () => pact
123
+ .addInteraction()
124
+ .uponReceiving('a response with regex content-type header matcher')
125
+ .withRequest('GET', '/')
126
+ .willRespondWith(200, (builder) => {
127
+ builder
128
+ .headers({
129
+ 'Content-Type': v3_1.MatchersV3.regex(/^application\/json(;\s?charset=[\w-]+)?$/i, 'application/json'),
130
+ })
131
+ .jsonBody({
132
+ foo: 'bar',
133
+ });
134
+ })
135
+ .executeTest(async (server) => {
136
+ const response = await axios_1.default.get(server.url);
137
+ expect(response.data).toEqual({ foo: 'bar' });
138
+ }));
139
+ it('supports regex matcher for request content-type with optional charset', () => pact
140
+ .addInteraction()
141
+ .uponReceiving('a request with regex content-type header matcher')
142
+ .withRequest('POST', '/', (builder) => {
143
+ builder
144
+ .headers({
145
+ 'Content-Type': v3_1.MatchersV3.regex(/^application\/json(;\s?charset=[\w-]+)?$/i, 'application/json'),
214
146
  })
215
- .executeTest(function (server) { return __awaiter(void 0, void 0, void 0, function () {
216
- var response;
217
- return __generator(this, function (_a) {
218
- switch (_a.label) {
219
- case 0: return [4 /*yield*/, axios_1.default.get(server.url)];
220
- case 1:
221
- response = _a.sent();
222
- expect(response.data).to.deep.equal({ foo: 'bar' });
223
- return [2 /*return*/];
224
- }
147
+ .jsonBody({
148
+ foo: 'bar',
149
+ });
150
+ })
151
+ .willRespondWith(200, (builder) => {
152
+ builder.jsonBody({
153
+ ok: true,
154
+ });
155
+ })
156
+ .executeTest((server) => axios_1.default.post(server.url, {
157
+ foo: 'bar',
158
+ })));
159
+ });
160
+ describe('Asynchronous message contract', () => {
161
+ it('generates a pact with interaction metadata', async () => {
162
+ const description = 'v4 metadata async interaction message';
163
+ await pact
164
+ .addAsynchronousInteraction()
165
+ .given('an async message state')
166
+ .pending()
167
+ .comment({ key: 'reason', value: 'covered by async metadata test' })
168
+ .comment('second note from async metadata test')
169
+ .testName('async metadata test name')
170
+ .expectsToReceive(description, (builder) => {
171
+ builder.withJSONContent({
172
+ event: 'user.created',
225
173
  });
226
- }); });
174
+ })
175
+ .executeTest(async () => Promise.resolve());
176
+ const interaction = interactionByDescription(description);
177
+ expect(interaction.pending).toBe(true);
178
+ expectCommentsToContain(interaction, 'covered by async metadata test', 'second note from async metadata test', 'async metadata test name');
227
179
  });
228
- it('supports regex matcher for request content-type with optional charset', function () {
229
- return pact
230
- .addInteraction()
231
- .uponReceiving('a request with regex content-type header matcher')
232
- .withRequest('POST', '/', function (builder) {
233
- builder
234
- .headers({
235
- 'Content-Type': v3_1.MatchersV3.regex(/^application\/json(;\s?charset=[\w-]+)?$/i, 'application/json'),
236
- })
237
- .jsonBody({
238
- foo: 'bar',
239
- });
180
+ it('records interaction references in the pact file', async () => {
181
+ const description = 'v4 async interaction with references';
182
+ await pact
183
+ .addAsynchronousInteraction()
184
+ .reference('GitHub', 'PR-456', 'https://github.com/example/repo/pull/456')
185
+ .expectsToReceive(description, (builder) => {
186
+ builder.withJSONContent({ event: 'user.created' });
240
187
  })
241
- .willRespondWith(200, function (builder) {
242
- builder.jsonBody({
243
- ok: true,
188
+ .executeTest(async () => Promise.resolve());
189
+ const interaction = interactionByDescription(description);
190
+ expectReferenceToEqual(interaction, 'GitHub', 'PR-456', 'https://github.com/example/repo/pull/456');
191
+ });
192
+ });
193
+ describe('Synchronous message contract', () => {
194
+ it('generates a pact with interaction metadata', async () => {
195
+ const description = 'v4 metadata sync interaction message';
196
+ await pact
197
+ .addSynchronousInteraction(description)
198
+ .given('a synchronous message state')
199
+ .pending()
200
+ .comment({ key: 'reason', value: 'covered by sync metadata test' })
201
+ .comment('second note from sync metadata test')
202
+ .testName('sync metadata test name')
203
+ .withRequest((builder) => {
204
+ builder.withJSONContent({
205
+ request: 'ping',
244
206
  });
245
207
  })
246
- .executeTest(function (server) {
247
- return axios_1.default.post(server.url, {
248
- foo: 'bar',
208
+ .withResponse((builder) => {
209
+ builder.withJSONContent({
210
+ response: 'pong',
249
211
  });
250
- });
212
+ })
213
+ .executeTest(async () => Promise.resolve());
214
+ const interaction = interactionByDescription(description);
215
+ expect(interaction.pending).toBe(true);
216
+ expectCommentsToContain(interaction, 'covered by sync metadata test', 'second note from sync metadata test', 'sync metadata test name');
217
+ });
218
+ it('records interaction references in the pact file', async () => {
219
+ const description = 'v4 sync interaction with references';
220
+ await pact
221
+ .addSynchronousInteraction(description)
222
+ .reference('Jira', 'TICKET-789', 'https://jira.example.com/TICKET-789')
223
+ .withRequest((builder) => {
224
+ builder.withJSONContent({ request: 'ping' });
225
+ })
226
+ .withResponse((builder) => {
227
+ builder.withJSONContent({ response: 'pong' });
228
+ })
229
+ .executeTest(async () => Promise.resolve());
230
+ const interaction = interactionByDescription(description);
231
+ expectReferenceToEqual(interaction, 'Jira', 'TICKET-789', 'https://jira.example.com/TICKET-789');
251
232
  });
252
233
  });
253
- describe('Asynchronous message contract', function () {
254
- it('generates a pact with interaction metadata', function () { return __awaiter(void 0, void 0, void 0, function () {
255
- var description, interaction;
256
- return __generator(this, function (_a) {
257
- switch (_a.label) {
258
- case 0:
259
- description = 'v4 metadata async interaction message';
260
- return [4 /*yield*/, pact
261
- .addAsynchronousInteraction()
262
- .given('an async message state')
263
- .pending()
264
- .comment({ key: 'reason', value: 'covered by async metadata test' })
265
- .comment('second note from async metadata test')
266
- .testName('async metadata test name')
267
- .expectsToReceive(description, function (builder) {
268
- builder.withJSONContent({
269
- event: 'user.created',
270
- });
271
- })
272
- .executeTest(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
273
- return [2 /*return*/, Promise.resolve()];
274
- }); }); })];
275
- case 1:
276
- _a.sent();
277
- interaction = interactionByDescription(description);
278
- expect(interaction.pending).to.equal(true);
279
- expectCommentsToContain(interaction, 'covered by async metadata test', 'second note from async metadata test', 'async metadata test name');
280
- return [2 /*return*/];
281
- }
282
- });
283
- }); });
284
- });
285
- describe('Synchronous message contract', function () {
286
- it('generates a pact with interaction metadata', function () { return __awaiter(void 0, void 0, void 0, function () {
287
- var description, interaction;
288
- return __generator(this, function (_a) {
289
- switch (_a.label) {
290
- case 0:
291
- description = 'v4 metadata sync interaction message';
292
- return [4 /*yield*/, pact
293
- .addSynchronousInteraction(description)
294
- .given('a synchronous message state')
295
- .pending()
296
- .comment({ key: 'reason', value: 'covered by sync metadata test' })
297
- .comment('second note from sync metadata test')
298
- .testName('sync metadata test name')
299
- .withRequest(function (builder) {
300
- builder.withJSONContent({
301
- request: 'ping',
302
- });
303
- })
304
- .withResponse(function (builder) {
305
- builder.withJSONContent({
306
- response: 'pong',
307
- });
308
- })
309
- .executeTest(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
310
- return [2 /*return*/, Promise.resolve()];
311
- }); }); })];
312
- case 1:
313
- _a.sent();
314
- interaction = interactionByDescription(description);
315
- expect(interaction.pending).to.equal(true);
316
- expectCommentsToContain(interaction, 'covered by sync metadata test', 'second note from sync metadata test', 'sync metadata test name');
317
- return [2 /*return*/];
318
- }
319
- });
320
- }); });
321
- });
322
- describe('Plugin test', function () {
323
- describe('Using the MATT plugin', function () {
324
- var parseMattMessage = function (raw) {
325
- return raw.replace(/(MATT)+/g, '').trim();
326
- };
327
- var generateMattMessage = function (raw) { return "MATT".concat(raw, "MATT"); };
328
- describe('HTTP interface', function () {
329
- it('generates a pact', function () { return __awaiter(void 0, void 0, void 0, function () {
330
- var mattRequest, mattResponse;
331
- return __generator(this, function (_a) {
332
- switch (_a.label) {
333
- case 0:
334
- mattRequest = "{\"request\": {\"body\": \"hello\"}}";
335
- mattResponse = "{\"response\":{\"body\":\"world\"}}";
336
- return [4 /*yield*/, pact
337
- .addInteraction()
338
- .given('the Matt protocol exists')
339
- .uponReceiving('an HTTP request to /matt')
340
- .usingPlugin({
341
- plugin: 'matt',
342
- version: '0.1.1',
343
- })
344
- .withRequest('POST', '/matt', function (builder) {
345
- builder.pluginContents('application/matt', mattRequest);
346
- })
347
- .willRespondWith(200, function (builder) {
348
- builder.pluginContents('application/matt', mattResponse);
349
- })
350
- .executeTest(function (mockserver) {
351
- return axios_1.default
352
- .request({
353
- baseURL: mockserver.url,
354
- headers: {
355
- 'content-type': 'application/matt',
356
- Accept: 'application/matt',
357
- },
358
- data: generateMattMessage('hello'),
359
- method: 'POST',
360
- url: '/matt',
361
- })
362
- .then(function (res) {
363
- expect(parseMattMessage(res.data)).to.eq('world');
364
- });
365
- })];
366
- case 1:
367
- _a.sent();
368
- return [2 /*return*/];
369
- }
370
- });
371
- }); });
234
+ describe('Plugin test', () => {
235
+ describe('Using the MATT plugin', () => {
236
+ const parseMattMessage = (raw) => raw.replace(/(MATT)+/g, '').trim();
237
+ const generateMattMessage = (raw) => `MATT${raw}MATT`;
238
+ describe('HTTP interface', () => {
239
+ it('generates a pact', async () => {
240
+ const mattRequest = `{"request": {"body": "hello"}}`;
241
+ const mattResponse = `{"response":{"body":"world"}}`;
242
+ await pact
243
+ .addInteraction()
244
+ .given('the Matt protocol exists')
245
+ .uponReceiving('an HTTP request to /matt')
246
+ .usingPlugin({
247
+ plugin: 'matt',
248
+ version: '0.1.1',
249
+ })
250
+ .withRequest('POST', '/matt', (builder) => {
251
+ builder.pluginContents('application/matt', mattRequest);
252
+ })
253
+ .willRespondWith(200, (builder) => {
254
+ builder.pluginContents('application/matt', mattResponse);
255
+ })
256
+ .executeTest((mockserver) => axios_1.default
257
+ .request({
258
+ baseURL: mockserver.url,
259
+ headers: {
260
+ 'content-type': 'application/matt',
261
+ Accept: 'application/matt',
262
+ },
263
+ data: generateMattMessage('hello'),
264
+ method: 'POST',
265
+ url: '/matt',
266
+ })
267
+ .then((res) => {
268
+ expect(parseMattMessage(res.data)).toBe('world');
269
+ }));
270
+ });
372
271
  });
373
- describe('Synchronous Message (TCP) ', function () {
374
- describe('with MATT protocol', function () {
375
- var HOST = '127.0.0.1';
376
- var sendMattMessageTCP = function (message, host, port) {
377
- var socket = net.connect({
378
- port: port,
379
- host: host,
272
+ describe('Synchronous Message (TCP) ', () => {
273
+ describe('with MATT protocol', () => {
274
+ const HOST = '127.0.0.1';
275
+ const sendMattMessageTCP = (message, host, port) => {
276
+ const socket = net.connect({
277
+ port,
278
+ host,
380
279
  });
381
- var res = socket.write("".concat(generateMattMessage(message), "\n"));
280
+ const res = socket.write(`${generateMattMessage(message)}\n`);
382
281
  if (!res) {
383
282
  throw Error('unable to connect to host');
384
283
  }
385
- return new Promise(function (resolve) {
386
- socket.on('data', function (data) {
284
+ return new Promise((resolve) => {
285
+ socket.on('data', (data) => {
387
286
  resolve(parseMattMessage(data.toString()));
388
287
  socket.destroy();
389
288
  });
390
289
  });
391
290
  };
392
- it('generates a pact', function () {
393
- var mattMessage = "{\"request\": {\"body\": \"hellotcp\"}, \"response\":{\"body\":\"tcpworld\"}}";
291
+ it('generates a pact', () => {
292
+ const mattMessage = `{"request": {"body": "hellotcp"}, "response":{"body":"tcpworld"}}`;
394
293
  return pact
395
294
  .addSynchronousInteraction('a MATT message')
396
295
  .usingPlugin({
@@ -399,18 +298,10 @@ describe('V4 Pact', function () {
399
298
  })
400
299
  .withPluginContents(mattMessage, 'application/matt')
401
300
  .startTransport('matt', HOST)
402
- .executeTest(function (tc) { return __awaiter(void 0, void 0, void 0, function () {
403
- var message;
404
- return __generator(this, function (_a) {
405
- switch (_a.label) {
406
- case 0: return [4 /*yield*/, sendMattMessageTCP('hellotcp', HOST, tc.port)];
407
- case 1:
408
- message = _a.sent();
409
- expect(message).to.eq('tcpworld');
410
- return [2 /*return*/];
411
- }
412
- });
413
- }); });
301
+ .executeTest(async (tc) => {
302
+ const message = await sendMattMessageTCP('hellotcp', HOST, tc.port);
303
+ expect(message).toBe('tcpworld');
304
+ });
414
305
  });
415
306
  });
416
307
  });