@pact-foundation/pact
Version:
Pact for all things Javascript
74 lines • 3.85 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Pact = exports.PactV4 = void 0;
const pact_core_1 = require("@pact-foundation/pact-core");
const package_json_1 = require("../../package.json");
const v3_1 = require("../v3");
const graphql_1 = require("./graphql");
const unconfiguredInteraction_1 = require("./http/unconfiguredInteraction");
const message_1 = require("./message");
const asynchronousMessage_1 = require("./message/asynchronousMessage");
class PactV4 {
opts;
pact;
constructor(opts) {
this.opts = opts;
this.setup();
}
setup() {
this.pact = (0, pact_core_1.makeConsumerPact)(this.opts.consumer, this.opts.provider, this.opts.spec ?? v3_1.SpecificationVersion.SPECIFICATION_VERSION_V4, this.opts.logLevel ?? 'info');
this.pact.addMetadata('pact-js', 'version', package_json_1.version);
}
addInteraction() {
return new unconfiguredInteraction_1.UnconfiguredInteraction(this.pact, this.pact.newInteraction(''), this.opts, () => {
// This function needs to be called if the PactV4 object is to be re-used (commonly expected by users)
// Because of the type-state model used here, it's a bit awkward as we need to thread this through
// to children, ultimately to be called on the "executeTest" stage.
this.setup();
});
}
addSynchronousInteraction(description) {
return new message_1.UnconfiguredSynchronousMessage(this.pact, this.pact.newSynchronousMessage(description), this.opts, () => {
// This function needs to be called if the PactV4 object is to be re-used (commonly expected by users)
// Because of the type-state model used here, it's a bit awkward as we need to thread this through
// to children, ultimately to be called on the "executeTest" stage.
this.setup();
});
}
addAsynchronousInteraction() {
return new asynchronousMessage_1.UnconfiguredAsynchronousMessage(this.pact, this.pact.newAsynchronousMessage(''), this.opts, () => {
// This function needs to be called if the PactV4 object is to be re-used (commonly expected by users)
// Because of the type-state model used here, it's a bit awkward as we need to thread this through
// to children, ultimately to be called on the "executeTest" stage.
this.setup();
});
}
addGraphQLInteraction() {
return new graphql_1.UnconfiguredGraphQLInteraction(this.pact, this.pact.newInteraction(''), this.opts, () => {
// This function needs to be called if the PactV4 object is to be re-used (commonly expected by users)
// Because of the type-state model used here, it's a bit awkward as we need to thread this through
// to children, ultimately to be called on the "executeTest" stage.
this.setup();
});
}
}
exports.PactV4 = PactV4;
exports.Pact = PactV4;
__exportStar(require("../xml"), exports);
__exportStar(require("./graphql"), exports);
__exportStar(require("./message/index"), exports);
//# sourceMappingURL=index.js.map