Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var opts = {
providerStatesSetupUrl: <String>, // URL to send PUT requests to setup a given provider state. Optional.
pactBrokerUsername: <String>, // Username for Pact Broker basic authentication. Optional
pactBrokerPassword: <String>, // Password for Pact Broker basic authentication. Optional
timeout: <Number> // The duration in ms we should wait to confirm verification process was successful. Defaults to 30000, Optional.
};

pact.verifyPacts(opts).then(function () {
Expand Down
10 changes: 7 additions & 3 deletions src/verifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ var checkTypes = require('check-types'),
isWindows = process.platform === 'win32';

// Constructor
function Verifier(providerBaseUrl, pactUrls, providerStatesUrl, providerStatesSetupUrl, pactBrokerUsername, pactBrokerPassword) {
function Verifier(providerBaseUrl, pactUrls, providerStatesUrl, providerStatesSetupUrl, pactBrokerUsername, pactBrokerPassword, timeout) {
this._options = {};
this._options.providerBaseUrl = providerBaseUrl;
this._options.pactUrls = pactUrls;
this._options.providerStatesUrl = providerStatesUrl;
this._options.providerStatesSetupUrl = providerStatesSetupUrl;
this._options.pactBrokerUsername = pactBrokerUsername;
this._options.pactBrokerPassword = pactBrokerPassword;
this._options.timeout = timeout;
}

Verifier.prototype.verify = function () {
Expand Down Expand Up @@ -78,7 +79,7 @@ Verifier.prototype.verify = function () {
});

logger.info('Created Pact Verifier process with PID: ' + this._instance.pid);
return deferred.promise.timeout(10000, "Couldn't start Pact Verifier process with PID: " + this._instance.pid)
return deferred.promise.timeout(this._options.timeout, "Timeout waiting for verification process to complete (PID: " + this._instance.pid + ")")
.tap(function (data) {
logger.info('Pact Verification succeeded.');
});
Expand All @@ -91,6 +92,7 @@ module.exports = function (options) {
options.pactUrls = options.pactUrls || [];
options.providerStatesUrl = options.providerStatesUrl || '';
options.providerStatesSetupUrl = options.providerStatesSetupUrl || '';
options.timeout = options.timeout || 30000;

options.pactUrls = _.chain(options.pactUrls)
.map(function (uri) {
Expand Down Expand Up @@ -145,5 +147,7 @@ module.exports = function (options) {
checkTypes.assert.string(options.providerBaseUrl);
}

return new Verifier(options.providerBaseUrl, options.pactUrls, options.providerStatesUrl, options.providerStatesSetupUrl, options.pactBrokerUsername, options.pactBrokerPassword);
checkTypes.assert.positive(options.timeout);

return new Verifier(options.providerBaseUrl, options.pactUrls, options.providerStatesUrl, options.providerStatesSetupUrl, options.pactBrokerUsername, options.pactBrokerPassword, options.timeout);
};
11 changes: 11 additions & 0 deletions src/verifier.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ describe("Verifier Spec", function () {
}).to.throw(Error);
});
});
context("when given an invalid timeout", function () {
it("should fail with an error", function () {
expect(function () {
verifierFactory({
providerBaseUrl: "http://localhost",
pactUrls: ["http://idontexist"],
timeout: -10
});
}).to.throw(Error);
});
});
context("when given remote Pact URLs that don't exist", function () {
it("should pass through to the Pact Verifier regardless", function () {
expect(function () {
Expand Down