Socket
Socket
Sign inDemoInstall

@pact-foundation/pact-node

Package Overview
Dependencies
Maintainers
4
Versions
187
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pact-foundation/pact-node - npm Package Compare versions

Comparing version 4.5.1 to 4.5.2

76

bin/pact-node.spec.js

@@ -15,5 +15,5 @@ /* global describe:true, before:true, after:true, it:true, global:true, process:true */

var procs;
function spawn(args) {
args = args || { port: 1234, host: 'localhost'};
args = args || {port: 1234, host: 'localhost'};
var deferred = q.defer();

@@ -28,3 +28,3 @@ var amount = 0;

check();
function check() {

@@ -39,3 +39,3 @@ amount++;

}
function call(options) {

@@ -65,13 +65,13 @@ var deferred = q.defer();

});
return deferred.promise;
}
return deferred.promise.timeout(10000, 'Process took too long');
}
beforeEach(function () {
procs = [];
});
afterEach(function () {

@@ -86,11 +86,11 @@ for (var i = 0, len = procs.length; i < len; i++) {

});
describe("run pact-node command", function () {
context("when no options are set", function () {
/*it("should use defaults and start running", function (done) {
spawn();
done();
});*/
spawn();
done();
});*/
});
/*context("when user specifies valid options", function () {

@@ -105,3 +105,3 @@ var dirPath;

});
it("should return serverFactory using specified options", function () {

@@ -119,22 +119,22 @@ var options = {

};
});
});
context("when user specifies invalid port", function () {
it("should return an error on negative port number", function () {
});
it("should return an error on non-integer", function () {
});
it("should return an error on non-number", function () {
});
it("should return an error on outside port range", function () {
});
});
context("when user specifies port that's currently in use", function () {

@@ -144,45 +144,45 @@ it("should return a port conflict error", function () {

});
context("when user specifies invalid host", function () {
it("should return an error on non-string", function () {
});
});
context("when user specifies invalid directory", function () {
it("should return an error on invalid path", function () {
});
});
context("when user specifies invalid ssl", function () {
it("should return an error on non-boolean", function () {
});
});
context("when user specifies invalid cors", function () {
it("should return an error on non-boolean", function () {
});
});
context("when user specifies invalid log", function () {
it("should return an error on invalid path", function () {
});
});
context("when user specifies invalid spec", function () {
it("should return an error on non-number", function () {
});
it("should return an error on negative number", function () {
});
it("should return an error on non-integer", function () {
});
});
context("when user specifies invalid consumer name", function () {

@@ -192,3 +192,3 @@ it("should return an error on non-string", function () {

});
context("when user specifies invalid provider name", function () {

@@ -195,0 +195,0 @@ it("should return an error on non-string", function () {

{
"name": "@pact-foundation/pact-node",
"version": "4.5.1",
"version": "4.5.2",
"description": "A wrapper for the Ruby version of Pact to work within Node",

@@ -62,7 +62,7 @@ "main": "./src/pact.js",

"cors": "^2.7.1",
"cross-env": "^1.0.8",
"express": "^4.14.0",
"jscs": "^3.0.6",
"mocha": "^2.5.3",
"nodemon": "^1.9.2",
"cross-env": "^1.0.7",
"express": "^4.13.4",
"jscs": "2.1.0",
"mocha": "^2.2.5",
"nodemon": "^1.4.1",
"rewire": "^2.5.2",

@@ -69,0 +69,0 @@ "rimraf": "^2.5.3",

@@ -31,7 +31,7 @@ 'use strict';

}
var server = serverFactory(options);
servers.push(server);
logger.info('Creating Pact Server with options: \n' + stringify(server.options));
// Listen to server delete events, to remove from server list

@@ -42,3 +42,3 @@ server.once('delete', function (server) {

});
return server;

@@ -45,0 +45,0 @@ }

@@ -17,3 +17,3 @@ /* global describe:true, before:true, after:true, it:true, global:true, process:true */

});
afterEach(function (done) {

@@ -24,3 +24,3 @@ pact.removeAllServers().then(function () {

});
describe("Set Log Level", function () {

@@ -32,3 +32,3 @@ context("when setting a log level", function () {

});
it("should be able to set log level 'debug'", function () {

@@ -38,3 +38,3 @@ pact.logLevel('debug');

});
it("should be able to set log level 'info'", function () {

@@ -44,3 +44,3 @@ pact.logLevel('info');

});
it("should be able to set log level 'warn'", function () {

@@ -50,3 +50,3 @@ pact.logLevel('warn');

});
it("should be able to set log level 'error'", function () {

@@ -56,3 +56,3 @@ pact.logLevel('error');

});
it("should be able to set log level 'fatal'", function () {

@@ -64,5 +64,5 @@ pact.logLevel('fatal');

});
describe("Create serverFactory", function () {
var fs = require('fs'),

@@ -75,3 +75,3 @@ path = require('path'),

});
afterEach(function (done) {

@@ -86,3 +86,3 @@ try {

});
context("when no options are set", function () {

@@ -99,5 +99,4 @@ it("should use defaults and return serverFactory", function () {

});
context("when user specifies valid options", function () {
it("should return serverFactory using specified options", function () {

@@ -129,3 +128,3 @@ var options = {

});
context("when user specifies invalid port", function () {

@@ -137,3 +136,3 @@ it("should return an error on negative port number", function () {

});
it("should return an error on non-integer", function () {

@@ -144,3 +143,3 @@ expect(function () {

});
it("should return an error on non-number", function () {

@@ -151,3 +150,3 @@ expect(function () {

});
it("should return an error on outside port range", function () {

@@ -159,3 +158,3 @@ expect(function () {

});
context("when user specifies port that's currently in use", function () {

@@ -169,3 +168,3 @@ it("should return a port conflict error", function () {

});
context("when user specifies invalid host", function () {

@@ -178,3 +177,3 @@ it("should return an error on non-string", function () {

});
context("when user specifies invalid pact directory", function () {

@@ -186,3 +185,3 @@ it("should create the directory for us", function () {

});
context("when user specifies invalid ssl", function () {

@@ -195,3 +194,3 @@ it("should return an error on non-boolean", function () {

});
context("when user specifies invalid cors", function () {

@@ -204,3 +203,3 @@ it("should return an error on non-boolean", function () {

});
context("when user specifies invalid log", function () {

@@ -212,3 +211,3 @@ it("should return an error on invalid path", function () {

});
context("when user specifies invalid spec", function () {

@@ -220,3 +219,3 @@ it("should return an error on non-number", function () {

});
it("should return an error on negative number", function () {

@@ -227,3 +226,3 @@ expect(function () {

});
it("should return an error on non-integer", function () {

@@ -235,3 +234,3 @@ expect(function () {

});
context("when user specifies invalid consumer name", function () {

@@ -244,3 +243,3 @@ it("should return an error on non-string", function () {

});
context("when user specifies invalid provider name", function () {

@@ -254,3 +253,3 @@ it("should return an error on non-string", function () {

});
describe("List servers", function () {

@@ -262,3 +261,3 @@ context("when called and there are no servers", function () {

});
context("when called and there are servers in list", function () {

@@ -272,3 +271,3 @@ it("should return a list of all servers", function () {

});
context("when server is removed", function () {

@@ -285,3 +284,3 @@ it("should update the list", function (done) {

});
describe("Remove all servers", function () {

@@ -300,3 +299,3 @@ context("when removeAll() is called and there are servers to remove", function () {

});
describe("Verify Pacts", function () {

@@ -313,3 +312,3 @@ context("With provider states", function () {

});
describe("Publish Pacts", function () {

@@ -316,0 +315,0 @@ it("should start running the Pact publishing process", function () {

@@ -26,3 +26,3 @@ 'use strict';

logger.info('Publishing pacts to broker at: ' + options.pactBroker);
// Stat all paths in pactUrls to make sure they exist

@@ -47,3 +47,3 @@ // publish template $pactHost/pacts/provider/$provider/consumer/$client/$version

.value();
// Return a merge of all promises...

@@ -64,3 +64,2 @@ return q.allSettled(

},
json: true,
body: data

@@ -71,3 +70,3 @@ }).fail(function (err) {

});
})

@@ -84,2 +83,3 @@ .map(function (publish) {

headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'

@@ -121,5 +121,6 @@ }

'Accept': 'application/json'
}
},
json: true
}, config);
// Authentication

@@ -132,3 +133,3 @@ if (options.pactBrokerUsername && options.pactBrokerPassword) {

}
return request(config).then(function (data) {

@@ -156,4 +157,3 @@ return data[0]; // return response only

return callPact(options, {
uri: uri,
json: true
uri: uri
}).fail(function (err) {

@@ -171,7 +171,7 @@ return q.reject(new Error('Cannot GET ' + uri + '. Nested exception: ' + err.message))

}
if (!_.has(options, 'consumerVersion')) {
throw new Error("Cannot construct Pact publish URL: 'consumerVersion' not specified");
}
if (!_.isObject(options)

@@ -185,3 +185,3 @@ || !_.has(data, 'consumer')

}
return urlJoin(options.pactBroker, 'pacts/provider', data.provider.name, 'consumer', data.consumer.name, 'version', options.consumerVersion)

@@ -194,7 +194,7 @@ }

}
if (!_.has(options, 'consumerVersion')) {
throw new Error("Cannot construct Pact Tag URL: 'consumerVersion' not specified");
}
if (!_.isObject(options)

@@ -206,4 +206,4 @@ || !_.has(data, 'consumer')

}
return urlJoin(options.pactBroker, 'pacticipants', data.consumer.name, 'versions', options.consumerVersion, 'tags', tag)
return urlJoin(options.pactBroker, 'pacticipants', data.consumer.name, 'version', options.consumerVersion, 'tags', tag)
}

@@ -217,7 +217,7 @@

options.tags = options.tags || [];
if (options.pactUrls) {
checkTypes.assert.array.of.string(options.pactUrls);
}
// Stat all paths in pactUrls to make sure they exist

@@ -236,24 +236,24 @@ var url = require('url');

});
checkTypes.assert.nonEmptyString(options.pactBroker, 'Must provide the pactBroker argument');
checkTypes.assert.nonEmptyString(options.consumerVersion, 'Must provide the consumerVersion argument');
checkTypes.assert.not.emptyArray(options.pactUrls, 'Must provide the pactUrls argument');
if (options.pactBrokerUsername) {
checkTypes.assert.string(options.pactBrokerUsername);
}
if (options.pactBrokerPassword) {
checkTypes.assert.string(options.pactBrokerPassword);
}
if ((options.pactBrokerUsername && !options.pactBrokerPassword) || (options.pactBrokerPassword && !options.pactBrokerUsername)) {
throw new Error('Must provide both or none of --provider-states-url and --provider-states-setup-url.');
}
if (options.pactBroker) {
checkTypes.assert.string(options.pactBroker);
}
return new Publisher(options.pactBroker, options.pactUrls, options.consumerVersion, options.pactBrokerUsername, options.pactBrokerPassword, options.tags);
};

@@ -22,3 +22,3 @@ /* global describe:true, before:true, after:true, it:true, global:true, process:true */

authenticatedPactBrokerBaseUrl = 'http://localhost:' + PORT + '/auth';
before(function (done) {

@@ -31,3 +31,3 @@ logger.level('debug');

});
describe("Publisher", function () {

@@ -44,3 +44,3 @@ context("when not given pactUrls", function () {

});
context("when not given pactBroker", function () {

@@ -56,3 +56,3 @@ it("should fail with an error", function () {

});
context("when not given consumerVersion", function () {

@@ -68,3 +68,3 @@ it("should fail with an error", function () {

});
context("when given local Pact URLs that don't exist", function () {

@@ -80,3 +80,3 @@ it("should fail with an error", function () {

});
context("when given local Pact URLs that do exist", function () {

@@ -93,3 +93,3 @@ it("should not fail", function () {

});
context("when given the correct arguments", function () {

@@ -107,8 +107,8 @@ it("should return a Publisher object", function () {

});
context("constructPutUrl", function () {
context("when given a valid config object and pact JSON", function () {
it("should return a PUT url", function () {
var options = { 'pactBroker': 'http://foo', 'consumerVersion': '1' };
var data = { 'consumer': { 'name': 'consumerName' }, 'provider': { 'name': 'providerName' } };
var options = {'pactBroker': 'http://foo', 'consumerVersion': '1'};
var data = {'consumer': {'name': 'consumerName'}, 'provider': {'name': 'providerName'}};
expect(constructPutUrl(options, data)).to.eq('http://foo/pacts/provider/providerName/consumer/consumerName/version/1');

@@ -119,5 +119,5 @@ });

it("should throw Error when pactBroker is not specified", function () {
var options = { 'someotherurl': 'http://foo' };
var data = { 'consumer': { 'name': 'consumerName' }, 'provider': { 'name': 'providerName' } };
expect(function() {
var options = {'someotherurl': 'http://foo'};
var data = {'consumer': {'name': 'consumerName'}, 'provider': {'name': 'providerName'}};
expect(function () {
constructPutUrl(options, data);

@@ -127,5 +127,5 @@ }).to.throw(Error, "Cannot construct Pact publish URL: 'pactBroker' not specified");

it("should throw Error when consumerVersion is not specified", function () {
var options = { 'pactBroker': 'http://foo' };
var data = { 'consumer': { 'name': 'consumerName' }, 'provider': { 'name': 'providerName' } };
expect(function() {
var options = {'pactBroker': 'http://foo'};
var data = {'consumer': {'name': 'consumerName'}, 'provider': {'name': 'providerName'}};
expect(function () {
constructPutUrl(options, data);

@@ -137,5 +137,5 @@ }).to.throw(Error, "Cannot construct Pact publish URL: 'consumerVersion' not specified");

it("should return a PUT url", function () {
var options = { 'pactBroker': 'http://foo', 'consumerVersion': '1' };
var data = { };
expect(function() {
var options = {'pactBroker': 'http://foo', 'consumerVersion': '1'};
var data = {};
expect(function () {
constructPutUrl(options, data);

@@ -147,5 +147,5 @@ }).to.throw(Error, "Invalid Pact file given. Unable to parse consumer and provider name");

it("should return a PUT url", function () {
var options = { 'pactBroker': 'http://foo', 'consumerVersion': '1' };
var data = { 'consumer': {}, 'provider': {} };
expect(function() {
var options = {'pactBroker': 'http://foo', 'consumerVersion': '1'};
var data = {'consumer': {}, 'provider': {}};
expect(function () {
constructPutUrl(options, data);

@@ -156,9 +156,9 @@ }).to.throw(Error, "Invalid Pact file given. Unable to parse consumer and provider name");

});
context("constructTagUrl", function () {
context("when given a valid config object and pact JSON", function () {
it("should return a PUT url", function () {
var options = { 'pactBroker': 'http://foo', consumerVersion: '1.0' };
var data = { 'consumer': { 'name': 'consumerName' } };
expect(constructTagUrl(options, 'test', data)).to.eq('http://foo/pacticipants/consumerName/versions/1.0/tags/test');
var options = {'pactBroker': 'http://foo', consumerVersion: '1.0'};
var data = {'consumer': {'name': 'consumerName'}};
expect(constructTagUrl(options, 'test', data)).to.eq('http://foo/pacticipants/consumerName/version/1.0/tags/test');
});

@@ -168,5 +168,5 @@ });

it("should throw Error when pactBroker is not specified", function () {
var options = { 'someotherurl': 'http://foo', consumerVersion: '1.0' };
var data = { 'consumer': { 'name': 'consumerName' } };
expect(function() {
var options = {'someotherurl': 'http://foo', consumerVersion: '1.0'};
var data = {'consumer': {'name': 'consumerName'}};
expect(function () {
constructTagUrl(options, data);

@@ -176,5 +176,5 @@ }).to.throw(Error, "Cannot construct Pact Tag URL: 'pactBroker' not specified");

it("should throw Error when consumerVersion is not specified", function () {
var options = { 'pactBroker': 'http://foo' };
var data = { 'consumer': { 'name': 'consumerName' }, 'provider': { 'name': 'providerName' } };
expect(function() {
var options = {'pactBroker': 'http://foo'};
var data = {'consumer': {'name': 'consumerName'}, 'provider': {'name': 'providerName'}};
expect(function () {
constructTagUrl(options, data);

@@ -186,5 +186,5 @@ }).to.throw(Error, "Cannot construct Pact Tag URL: 'consumerVersion' not specified");

it("should return a PUT url", function () {
var options = { 'pactBroker': 'http://foo', consumerVersion: '1.0' };
var data = { };
expect(function() {
var options = {'pactBroker': 'http://foo', consumerVersion: '1.0'};
var data = {};
expect(function () {
constructTagUrl(options, data);

@@ -196,5 +196,5 @@ }).to.throw(Error, "Invalid Pact file given. Unable to parse consumer name");

it("should return a PUT url", function () {
var options = { 'pactBroker': 'http://foo', consumerVersion: '1.0' };
var data = { 'consumer': {} };
expect(function() {
var options = {'pactBroker': 'http://foo', consumerVersion: '1.0'};
var data = {'consumer': {}};
expect(function () {
constructTagUrl(options, data);

@@ -201,0 +201,0 @@ }).to.throw(Error, "Invalid Pact file given. Unable to parse consumer name");

@@ -14,4 +14,4 @@ 'use strict';

pactPath = require('@pact-foundation/pact-mock-service'),
mkdirp = require('mkdirp');
var isWindows = process.platform === 'win32';
mkdirp = require('mkdirp'),
isWindows = process.platform === 'win32';

@@ -39,32 +39,7 @@ var CHECKTIME = 500;

Server.prototype.start = function () {
var deferred = q.defer();
// Wait for pact-mock-service to be initialized and ready
var amount = 0;
function check() {
amount++;
function retry() {
if (amount >= 10) {
deferred.reject(new Error("Pact startup failed; tried calling service 10 times with no result."));
}
setTimeout(check.bind(this), CHECKTIME);
}
if (this.options.port) {
call(this.options).then((function () {
this.$running = true;
this.emit('start', this);
deferred.resolve(this);
}).bind(this), retry.bind(this));
} else {
retry.call(this);
}
}
if (this.instance && this.instance.connected) {
logger.warn('You already have a process running with PID: ' + this.instance.pid);
check.call(this);
return;
}
var envVars = JSON.parse(JSON.stringify(process.env)); // Create copy of environment variables

@@ -92,9 +67,9 @@ // Remove environment variable if there

};
var args = _.compact(_.map(mapping, (function (value, key) {
return this.options[key] ? value + ' ' + this.options[key] : null;
}).bind(this)));
var cmd = [pactPath.file].concat(args).join(' ');
if (isWindows) {

@@ -109,5 +84,5 @@ file = 'cmd.exe';

}
this.instance = cp.spawn(file, args, opts);
this.instance.stdout.setEncoding('utf8');

@@ -118,3 +93,3 @@ this.instance.stdout.on('data', logger.debug.bind(logger));

this.instance.on('error', logger.error.bind(logger));
// if port isn't specified, listen for it when pact runs

@@ -129,3 +104,3 @@ function catchPort(data) {

}
if (!this.options.port) {

@@ -135,5 +110,5 @@ this.instance.stdout.on('data', catchPort.bind(this));

}
logger.info('Creating Pact with PID: ' + this.instance.pid);
this.instance.once('close', (function (code) {

@@ -145,6 +120,11 @@ if (code !== 0) {

}).bind(this));
// check service is available
check.call(this);
return deferred.promise.timeout(10000, "Couldn't start Pact with PID: " + this.instance.pid);
return waitForServerUp(this.options)
.timeout(10000, "Couldn't start Pact with PID: " + this.instance.pid)
.then((function () {
this.$running = true;
this.emit('start', this);
return this;
}).bind(this));
};

@@ -154,25 +134,2 @@

Server.prototype.stop = function () {
var deferred = q.defer();
var amount = 0;
function done() {
this.$running = false;
this.emit('stop', this);
deferred.resolve(this);
}
function check() {
amount++;
if (this.options.port) {
call(this.options).then((function () {
if (amount >= 10) {
deferred.reject(new Error("Pact stop failed; tried calling service 10 times with no result."));
}
setTimeout(check.bind(this), CHECKTIME);
}).bind(this), done.bind(this));
} else {
done.call(this);
}
}
var pid = -1;

@@ -191,5 +148,10 @@ if (this.instance) {

}
check.call(this);
return deferred.promise.timeout(10000, "Couldn't stop Pact with PID: " + pid);
return waitForServerDown(this.options)
.timeout(10000, "Couldn't stop Pact with PID: " + pid)
.then((function () {
this.$running = false;
this.emit('stop', this);
return this;
}).bind(this));
};

@@ -205,2 +167,52 @@

// Wait for pact-mock-service to be initialized and ready
function waitForServerUp(options) {
var amount = 0, deferred = q.defer();
function retry() {
if (amount >= 10) {
deferred.reject(new Error("Pact startup failed; tried calling service 10 times with no result."));
}
setTimeout(check.bind(this), CHECKTIME);
}
function check() {
amount++;
if (options.port) {
call(options).then(function () {
deferred.resolve();
}, retry);
} else {
retry();
}
}
check(); // Check first time, start polling
return deferred.promise;
}
function waitForServerDown(options) {
var amount = 0, deferred = q.defer();
function check() {
amount++;
if (options.port) {
call(options).then(function () {
if (amount >= 10) {
deferred.reject(new Error("Pact stop failed; tried calling service 10 times with no result."));
return;
}
setTimeout(check, CHECKTIME);
}, function () {
deferred.resolve();
});
} else {
deferred.resolve();
}
}
check(); // Check first time, start polling
return deferred.promise;
}
function call(options) {

@@ -216,2 +228,3 @@ var deferred = q.defer();

};
if (options.ssl) {

@@ -224,4 +237,5 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

}
http(config, function (error, response) {
if (!error && response.statusCode == 200) {
http(config, function (err, res) {
if (!err && res.statusCode == 200) {
deferred.resolve();

@@ -232,3 +246,3 @@ } else {

});
return deferred.promise;

@@ -240,3 +254,3 @@ }

options = options || {};
// defaults

@@ -252,3 +266,3 @@ //options.port = options.port;

// options.provider = options.provider || 'provider name';
// port checking

@@ -260,3 +274,3 @@ if (options.port) {

checkTypes.assert.inRange(options.port, 0, 65535);
if (checkTypes.not.inRange(options.port, 1024, 49151)) {

@@ -266,9 +280,9 @@ logger.warn("Like a Boss, you used a port outside of the recommended range (1024 to 49151); I too like to live dangerously.");

}
// ssl check
checkTypes.assert.boolean(options.ssl);
// cors check'
checkTypes.assert.boolean(options.cors);
// spec checking

@@ -280,3 +294,3 @@ if (options.spec) {

}
// dir check

@@ -290,3 +304,3 @@ if (options.dir) {

}
// log check

@@ -302,3 +316,3 @@ if (options.log) {

}
// host check

@@ -308,3 +322,3 @@ if (options.host) {

}
// consumer name check

@@ -314,3 +328,3 @@ if (options.consumer) {

}
// provider name check

@@ -320,4 +334,4 @@ if (options.provider) {

}
return new Server(options.port, options.host, options.dir, options.ssl, options.cors, options.log, options.spec, options.consumer, options.provider);
};
/* global describe:true, before:true, after:true, it:true, global:true, process:true */
var serverFactory = require('./server'),
var rewire = require("rewire"),
serverFactory = rewire('./server'),
logger = require('./logger'),
expect = require('chai').expect,
fs = require('fs'),
path = require('path');
path = require('path'),
q = require('q'),
_ = require('underscore');
describe("Server Spec", function () {
var server;
before(function () {
logger.level('debug');
});
afterEach(function (done) {

@@ -25,3 +27,3 @@ if (server) {

});
describe("Start server", function () {

@@ -36,11 +38,11 @@ context("when no options are set", function () {

});
context("when valid options are set", function () {
var dirPath;
beforeEach(function () {
dirPath = path.resolve(__dirname, '../.tmp/' + Math.floor(Math.random() * 1000));
});
afterEach(function (done) {

@@ -55,3 +57,20 @@ try {

});
it("should start correctly when instance is delayed", function (done) {
server = serverFactory();
var waitForServerUp = serverFactory.__get__('waitForServerUp');
q.allSettled([
waitForServerUp(server.options),
q.delay(5000).then(function () {
server.start()
})
]).then(function (results) {
expect(_.reduce(results, function (m, r) {
return m && r.state === 'fulfilled'
})).to.be.true;
done();
});
});
it("should start correctly with ssl", function (done) {

@@ -64,3 +83,3 @@ server = serverFactory({ssl: true});

});
it("should start correctly with cors", function (done) {

@@ -73,3 +92,3 @@ server = serverFactory({cors: true});

});
it("should start correctly with port", function (done) {

@@ -82,3 +101,3 @@ server = serverFactory({port: 9500});

});
it("should start correctly with host", function (done) {

@@ -91,3 +110,3 @@ server = serverFactory({host: 'localhost'});

});
it("should start correctly with spec version 1", function (done) {

@@ -100,3 +119,3 @@ server = serverFactory({spec: 1});

});
it("should start correctly with spec version 2", function (done) {

@@ -109,3 +128,3 @@ server = serverFactory({spec: 2});

});
it("should start correctly with dir", function (done) {

@@ -118,3 +137,3 @@ server = serverFactory({dir: dirPath});

});
it("should start correctly with log", function (done) {

@@ -128,3 +147,3 @@ var logPath = path.resolve(dirPath, 'log.txt');

});
it("should start correctly with consumer name", function (done) {

@@ -137,3 +156,3 @@ server = serverFactory({consumer: 'cName'});

});
it("should start correctly with provider name", function (done) {

@@ -147,3 +166,3 @@ server = serverFactory({provider: 'pName'});

});
it("should dispatch event when starting", function (done) {

@@ -156,3 +175,3 @@ server = serverFactory();

});
it("should change running state to true", function (done) {

@@ -166,3 +185,3 @@ server = serverFactory();

});
describe("Stop server", function () {

@@ -178,3 +197,3 @@ context("when already started", function () {

});
it("should dispatch event when stopping", function (done) {

@@ -189,3 +208,3 @@ server = serverFactory();

});
it("should change running state to false", function (done) {

@@ -202,3 +221,3 @@ server = serverFactory();

});
describe("Delete server", function () {

@@ -214,3 +233,3 @@ context("when already running", function () {

});
it("should dispatch event when deleting", function (done) {

@@ -225,3 +244,3 @@ server = serverFactory();

});
it("should change running state to false", function (done) {

@@ -238,3 +257,3 @@ server = serverFactory();

});
});

@@ -12,4 +12,4 @@ 'use strict';

url = require('url'),
verifierPath = require('@pact-foundation/pact-provider-verifier');
var isWindows = process.platform === 'win32';
verifierPath = require('@pact-foundation/pact-provider-verifier'),
isWindows = process.platform === 'win32';

@@ -30,9 +30,9 @@ // Constructor

var deferred = q.defer();
var stdout = ''; // Store output here in case of error
var output = ''; // Store output here in case of error
function outputHandler(data) {
logger.info(data);
stdout += data;
output += data;
}
var envVars = JSON.parse(JSON.stringify(process.env)); // Create copy of environment variables

@@ -43,3 +43,3 @@ // Remove environment variable if there

delete envVars['RUBYGEMS_GEMDEPS'];
var file,

@@ -59,9 +59,9 @@ opts = {

};
var args = _.compact(_.map(mapping, (function (value, key) {
return this.options[key] ? value + ' ' + (checkTypes.array(this.options[key]) ? this.options[key].join(',') : this.options[key]) : null;
}).bind(this)));
var cmd = [verifierPath.file].concat(args).join(' ');
if (isWindows) {

@@ -76,5 +76,5 @@ file = 'cmd.exe';

}
this.instance = cp.spawn(file, args, opts);
this.instance.stdout.setEncoding('utf8');

@@ -85,13 +85,13 @@ this.instance.stdout.on('data', outputHandler);

this.instance.on('error', logger.error.bind(logger));
this.instance.once('close', function (code) {
code == 0 ? deferred.resolve(stdout) : deferred.reject(new Error(stdout));
code == 0 ? deferred.resolve(output) : deferred.reject(new Error(output));
});
logger.info('Created Pact Verifier process with PID: ' + this.instance.pid);
return deferred.promise.then(function () {
logger.info('Pact Verification succeeded.');
}, function (err) {
return q.reject(err);
});
return deferred.promise.timeout(10000, "Couldn't start Pact Verifier process with PID: " + this.instance.pid)
.then(function (data) {
logger.info('Pact Verification succeeded.');
return data;
});
};

@@ -106,3 +106,3 @@

options.providerStatesSetupUrl = options.providerStatesSetupUrl || '';
options.pactUrls = _.chain(options.pactUrls)

@@ -114,3 +114,3 @@ .map(function (uri) {

fs.statSync(path.normalize(uri)).isFile();
// Unixify the paths. Pact in multiple places uses URI and matching and

@@ -130,35 +130,35 @@ // hasn't really taken Windows into account. This is much easier, albeit

.value();
checkTypes.assert.nonEmptyString(options.providerBaseUrl, 'Must provide the --provider-base-url argument');
checkTypes.assert.not.emptyArray(options.pactUrls, 'Must provide the --pact-urls argument');
if (options.providerStatesSetupUrl) {
checkTypes.assert.string(options.providerStatesSetupUrl);
}
if (options.providerStatesUrl) {
checkTypes.assert.string(options.providerStatesUrl);
}
if (options.pactBrokerUsername) {
checkTypes.assert.string(options.pactBrokerUsername);
}
if (options.pactBrokerPassword) {
checkTypes.assert.string(options.pactBrokerPassword);
}
if ((options.providerStatesUrl && !options.providerStatesSetupUrl) || (options.providerStatesSetupUrl && !options.providerStatesUrl)) {
throw new Error('Must provide both or none of --provider-states-url and --provider-states-setup-url.');
}
if (options.pactUrls) {
checkTypes.assert.array.of.string(options.pactUrls);
}
if (options.providerBaseUrl) {
checkTypes.assert.string(options.providerBaseUrl);
}
return new Verifier(options.providerBaseUrl, options.pactUrls, options.providerStatesUrl, options.providerStatesSetupUrl, options.pactBrokerUsername, options.pactBrokerPassword);
};

@@ -16,7 +16,7 @@ /* global describe:true, before:true, after:true, it:true, global:true, process:true */

describe("Verifier Spec", function () {
before(function () {
logger.level('debug');
});
describe("Verifier", function () {

@@ -85,3 +85,3 @@ context("when not given --pact-urls or --provider-base-url", function () {

});
describe("verify", function () {

@@ -88,0 +88,0 @@ context("when given a successful scenario", function () {

@@ -15,5 +15,5 @@ var cors = require('cors'),

// 1. Is there a body?
_.isEmpty(req.body) ||
// 2. Is there a consumer, provider and version in the request?
_.isEmpty(req.params.consumer) || _.isEmpty(req.params.provider) || _.isEmpty(req.params.version)
_.isEmpty(req.body) ||
// 2. Is there a consumer, provider and version in the request?
_.isEmpty(req.params.consumer) || _.isEmpty(req.params.provider) || _.isEmpty(req.params.version)
) {

@@ -43,7 +43,7 @@ return res.sendStatus(400);

server.get('/somebrokenpact', function(req, res) {
server.get('/somebrokenpact', function (req, res) {
res.json({});
});
server.get('/somepact', function(req, res) {
server.get('/somepact', function (req, res) {
res.json({'consumer': {'name': 'anotherclient'}, 'provider': {'name': 'they'}});

@@ -59,5 +59,5 @@ });

// Tagging
server.put('/pacticipants/:consumer/versions/:version/tags/:tag', tagPactFunction);
server.put('/auth/pacticipants/:consumer/versions/:version/tags/:tag', tagPactFunction);
server.put('/pacticipants/:consumer/version/:version/tags/:tag', tagPactFunction);
server.put('/auth/pacticipants/:consumer/version/:version/tags/:tag', tagPactFunction);
module.exports = server;

@@ -43,3 +43,3 @@ var cors = require('cors'),

};
var fileName = req.params.name;

@@ -46,0 +46,0 @@ res.sendFile(fileName, options, function (err) {

@@ -1,3 +0,1 @@

/* global describe:true, before:true, after:true, it:true, global:true, process:true */
var publisherFactory = require('./../src/publisher'),

@@ -19,3 +17,3 @@ logger = require('./../src/logger'),

authenticatedPactBrokerBaseUrl = 'http://localhost:' + PORT + '/auth';
before(function (done) {

@@ -27,7 +25,7 @@ server = broker.listen(PORT, function () {

});
after(function () {
server.close();
});
context("when publishing a to a broker", function () {

@@ -42,3 +40,3 @@ context("without authentication", function () {

});
expect(publisher).to.be.a('object');

@@ -48,3 +46,3 @@ expect(publisher).to.respondTo('publish');

});
it("should successfully tag all Pacts with 'test' and 'latest'", function () {

@@ -57,3 +55,3 @@ var publisher = publisherFactory({

});
expect(publisher).to.be.a('object');

@@ -71,3 +69,3 @@ expect(publisher).to.respondTo('publish');

});
expect(publisher).to.be.a('object');

@@ -79,3 +77,3 @@ expect(publisher).to.respondTo('publish');

});
context("with authentication", function () {

@@ -91,3 +89,3 @@ context("and valid credentials", function () {

});
expect(publisher).to.be.a('object');

@@ -98,3 +96,3 @@ expect(publisher).to.respondTo('publish');

});
context("and invalid credentials", function () {

@@ -109,3 +107,3 @@ it("should return a rejected promise", function () {

});
expect(publisher).to.be.a('object');

@@ -117,4 +115,5 @@ expect(publisher).to.respondTo('publish');

});
});
context("when publishing a directory of Pacts to a Broker", function () {

@@ -128,3 +127,3 @@ context("and the directory contains only valid pact files", function () {

});
expect(publisher).to.be.a('object');

@@ -137,3 +136,3 @@ expect(publisher).to.respondTo('publish');

});
it("should successfully tag all Pacts sent with 'test' and 'latest'", function () {

@@ -146,3 +145,3 @@ var publisher = publisherFactory({

});
expect(publisher).to.be.a('object');

@@ -156,3 +155,3 @@ expect(publisher).to.respondTo('publish');

});
context("and the directory contains Pact and non-Pact files", function () {

@@ -165,3 +164,3 @@ it("should asynchronously send only the Pact files to the broker", function () {

});
expect(publisher).to.be.a('object');

@@ -184,6 +183,6 @@ expect(publisher).to.respondTo('publish');

});
return expect(publisher.publish()).to.eventually.be.fulfilled;
});
it("should successfully tag all Pacts sent with 'test' and 'latest'", function () {

@@ -196,7 +195,7 @@ var publisher = publisherFactory({

});
return expect(publisher.publish()).to.eventually.be.fulfilled;
});
});
context("and the pact files do not exist (404)", function () {

@@ -209,8 +208,8 @@ it("should return a rejected promise", function () {

});
return publisher.publish()
.then(function() {
.then(function () {
throw new Error("Expected an error but got none");
})
.catch(function(results) {
.catch(function (results) {
expect(results[0].message).to.contain("Cannot GET /somepacturlthatdoesntexist")

@@ -220,2 +219,3 @@ })

});
context("and the pact files are invalid (no consumer/provider)", function () {

@@ -228,8 +228,8 @@ it("should return a rejected promise", function () {

});
return publisher.publish()
.then(function() {
.then(function () {
throw new Error("Expected an error but got none");
})
.catch(function(results) {
.catch(function (results) {
expect(results[0].message).to.contain("Invalid Pact file given. Unable to parse consumer and provider name");

@@ -236,0 +236,0 @@ })

@@ -1,3 +0,1 @@

/* global describe:true, before:true, after:true, it:true, global:true, process:true */
var verifierFactory = require('./../src/verifier.js'),

@@ -16,3 +14,3 @@ logger = require('./../src/logger'),

describe("Verifier Integration Spec", function () {
var server,

@@ -24,3 +22,3 @@ PORT = Math.floor(Math.random() * 999) + 9000,

pactBrokerBaseUrl = 'http://localhost:' + PORT;
before(function (done) {

@@ -32,7 +30,7 @@ server = provider.listen(PORT, function () {

});
after(function () {
server.close();
});
context("when given a successful contract", function () {

@@ -48,3 +46,3 @@ context("without provider states", function () {

});
context("with Provider States", function () {

@@ -62,3 +60,3 @@ it("should return a successful promise", function () {

});
context("when given a failing contract", function () {

@@ -73,3 +71,3 @@ it("should return a rejected promise", function () {

});
context("when given multiple successful API calls in a contract", function () {

@@ -86,3 +84,3 @@ it("should return a successful promise", function () {

});
context("when given multiple contracts", function () {

@@ -100,3 +98,3 @@ context("from a local file", function () {

});
context("from a Pact Broker", function () {

@@ -150,8 +148,8 @@ context("without authentication", function () {

return verifier.verify()
.then(function() {
throw new Error("Expected an error but got none");
})
.catch(function(err) {
expect(err.message).to.contain("Unauthorized")
})
.then(function () {
throw new Error("Expected an error but got none");
})
.catch(function (err) {
expect(err.message).to.contain("Unauthorized")
})
});

@@ -158,0 +156,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc