Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mockserver-client

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockserver-client - npm Package Compare versions

Comparing version 1.0.12 to 1.0.13

.buildkite/pipeline.yml

2

bower.json
{
"name": "mockserver-client",
"version": "1.0.12",
"version": "1.0.13",
"homepage": "https://github.com/jamesdbloom/mockserver-client-node",

@@ -5,0 +5,0 @@ "authors": [

@@ -32,5 +32,4 @@ /*

serverPort: 1080,
serverSecurePort: 1082,
proxyPort: 1090,
proxySecurePort: 1092
systemProperties: "-Dmockserver.enableCORSForAllResponses=true"
}

@@ -54,2 +53,56 @@ },

}
},
webdriver_jasmine_runner: {
with_proxy: {
options: {
browser: 'chrome',
testServer: 'localhost',
testServerPort: 1080,
testFile: 'test/SpecRunner.html?proxy=true',
proxy: {
proxyType: 'manual',
httpProxy: 'localhost:1090'
}
}
}
},
karma: {
options: {
configFile: 'test/karma.conf.js',
logLevel: 'INFO',
reporters: 'spec',
browserDisconnectTimeout: 10 * 10000,
browserNoActivityTimeout: 10 * 10000,
singleRun: true,
files: [
'mockServerClient.js',
'proxyClient.js',
'test/no_proxy/mock_server_browser_client_spec.js',
'test/with_proxy/proxy_browser_client_spec.js'
]
},
no_proxy_phantom: {
browsers: ['PhantomJS'],
mode: 'no_proxy'
},
with_proxy_phantom: {
browsers: ['PhantomJS_with_proxy'],
mode: 'with_proxy'
},
no_proxy_chrome: {
browsers: ['Chrome'],
mode: 'no_proxy'
},
with_proxy_chrome: {
browsers: ['Chrome_with_proxy'],
// browsers: ['Chrome'],
mode: 'with_proxy',
proxies: {
'/somePath': 'http://127.0.0.1:1090/somePath',
'/someOtherPath': 'http://127.0.0.1:1090/someOtherPath',
'/one': 'http://127.0.0.1:1090/one',
'/two': 'http://127.0.0.1:1090/two',
'/three': 'http://127.0.0.1:1090/three'
}
}
}

@@ -63,7 +116,10 @@ });

grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-webdriver-jasmine-runner');
grunt.registerTask('test', ['start_mockserver', 'nodeunit', 'stop_mockserver']);
grunt.registerTask('test_node', ['start_mockserver', 'nodeunit', 'stop_mockserver']);
grunt.registerTask('test_browser', ['start_mockserver', 'karma:no_proxy_chrome', 'karma:with_proxy_chrome', 'stop_mockserver']);
grunt.registerTask('test', ['start_mockserver', 'nodeunit', 'karma:no_proxy_chrome', /*'karma:with_proxy_chrome', */'stop_mockserver']);
grunt.registerTask('wrecker', ['jshint', 'test']);
grunt.registerTask('default', ['exec', 'wrecker']);
grunt.registerTask('default', ['exec:stop_existing_mockservers', 'jshint', 'test_node']);
};

@@ -12,467 +12,6 @@ /*

var Q = require('q');
var http = require('http');
function sendRequest(host, port, path, jsonBody, resolveCallback) {
var promise = (global.protractor ? protractor.promise : Q);
var deferred = promise.defer();
if (global.protractor)
{
deferred.resolve = deferred.fulfill;
}
var body = (typeof jsonBody === "string" ? jsonBody : JSON.stringify(jsonBody || ""));
var options = {
method: 'PUT',
host: host,
path: path,
port: port,
headers: {
'Content-Type': "application/json; charset=utf-8"
}
};
var req = http.request(options);
req.once('response', function (response) {
var data = '';
if (response.statusCode === 400 || response.statusCode === 404) {
deferred.reject(response.statusCode);
}
response.on('data', function (chunk) {
data += chunk;
});
response.on('end', function () {
if (resolveCallback) {
deferred.resolve(resolveCallback(data));
} else {
deferred.resolve({
statusCode: response.statusCode,
body: data
});
}
});
});
req.once('error', function (error) {
deferred.reject(error);
});
req.write(body);
req.end();
return deferred.promise;
}
/**
* Start the client communicating to a MockServer at the specified host and port
* for example:
*
* var client = mockServerClient("localhost", 1080);
*
* @param host the host for the MockServer to communicate with
* @param port the port for the MockServer to communicate with
*/
var mockServerClient = function (host, port) {
/**
* The default headers added to to the mocked response when using mockSimpleResponse(...)
*/
var defaultResponseHeaders = [
{"name": "Content-Type", "values": ["application/json; charset=utf-8"]},
{"name": "Cache-Control", "values": ["no-cache, no-store"]}
];
var createResponseMatcher = function (path) {
return {
method: "",
path: path,
body: "",
headers: [],
cookies: [],
queryStringParameters: []
};
};
var createExpectation = function (path, responseBody, statusCode) {
return {
httpRequest: createResponseMatcher(path),
httpResponse: {
statusCode: statusCode || 200,
body: JSON.stringify(responseBody),
cookies: [],
headers: defaultResponseHeaders,
delay: {
timeUnit: "MICROSECONDS",
value: 0
}
},
times: {
remainingTimes: 1,
unlimited: false
}
};
};
/**
* Setup an expectation in the MockServer by specifying an expectation object
* for example:
*
* mockServerClient("localhost", 1080).mockAnyResponse(
* {
* 'httpRequest': {
* 'path': '/somePath',
* 'body': {
* 'type': "STRING",
* 'value': 'someBody'
* }
* },
* 'httpResponse': {
* 'statusCode': 200,
* 'body': Base64.encode(JSON.stringify({ name: 'first_body' })),
* 'delay': {
* 'timeUnit': 'MILLISECONDS',
* 'value': 250
* }
* },
* 'times': {
* 'remainingTimes': 1,
* 'unlimited': false
* }
* }
* );
*
* @param expectation the expectation to setup on the MockServer
*/
var mockAnyResponse = function (expectation) {
return sendRequest(host, port, "/expectation", expectation);
};
/**
* Setup an expectation in the MockServer without having to specify the full expectation object
* for example:
*
* mockServerClient("localhost", 1080).mockSimpleResponse('/somePath', { name: 'value' }, 203);
*
* @param path the path to match requests against
* @param responseBody the response body to return if a request matches
* @param statusCode the response code to return if a request matches
*/
var mockSimpleResponse = function (path, responseBody, statusCode) {
return mockAnyResponse(createExpectation(path, responseBody, statusCode));
};
/**
* Override the default headers that are used to specify the response headers in mockSimpleResponse(...)
* (note: if you use mockAnyResponse(...) the default headers are not used)
* for example:
*
* mockServerClient("localhost", 1080).setDefaultHeaders([
* {"name": "Content-Type", "values": ["application/json; charset=utf-8"]},
* {"name": "Cache-Control", "values": ["no-cache, no-store"]}
* ])
*
* @param headers the path to match requests against
*/
var setDefaultHeaders = function (headers) {
defaultResponseHeaders = headers;
};
/**
* Verify a request has been sent for example:
*
* expect(client.verify({
* 'httpRequest': {
* 'method': 'POST',
* 'path': '/somePath'
* }
* })).toBeTruthy();
*
* @param request the http request that must be matched for this verification to pass
* @param count the number of times this request must be matched
* @param exact true if the count is matched as "equal to" or false if the count is matched as "greater than or equal to"
*/
var verify = function (request, count, exact) {
if (count === undefined) {
count = 1;
}
return sendRequest(host, port, "/verify", {
"httpRequest": request,
"times": {
"count": count,
"exact": exact
}
}).then(function (result) {
if (result.statusCode !== 202) {
console && console.error && console.error(result.body);
throw result.body;
}
return _this;
});
};
/**
* Verify a sequence of requests has been sent for example:
*
* client.verifySequence(
* {
* 'method': 'POST',
* 'path': '/first_request'
* },
* {
* 'method': 'POST',
* 'path': '/second_request'
* },
* {
* 'method': 'POST',
* 'path': '/third_request'
* }
* );
*
* @param arguments the list of http requests that must be matched for this verification to pass
*/
var verifySequence = function () {
var requestSequence = [];
for (var i = 0; i < arguments.length; i++) {
requestSequence.push(arguments[i]);
}
return sendRequest(host, port, "/verifySequence", {
"httpRequests": requestSequence
}).then(function (result) {
if (result.statusCode !== 202) {
console && console.error && console.error(result.body);
throw result.body;
}
return _this;
});
};
/**
* Reset MockServer by clearing all expectations
*/
var reset = function () {
return sendRequest(host, port, "/reset");
};
/**
* Clear all expectations that match the specified path
*
* @param pathOrRequestMatcher if a string is passed in the value will be treated as the path to
* decide which expectations to cleared, however if an object is passed
* in the value will be treated as a full request matcher object
*/
var clear = function (pathOrRequestMatcher) {
if (typeof pathOrRequestMatcher === "string") {
return sendRequest(host, port, "/clear", createResponseMatcher(pathOrRequestMatcher));
} else if (pathOrRequestMatcher) {
return sendRequest(host, port, "/clear", pathOrRequestMatcher);
} else {
return sendRequest(host, port, "/clear", createResponseMatcher(".*"));
}
};
/**
* Retrieve the recorded requests that match the parameter, as follows:
* - use a string value to match on path,
* - use a request matcher object to match on a full request,
* - or use null to retrieve all requests
*
* @param pathOrRequestMatcher if a string is passed in the value will be treated as the path, however
* if an object is passed in the value will be treated as a full request
* matcher object, if null is passed in it will be treated as match all
*/
var retrieveRequests = function (pathOrRequestMatcher) {
var resolveCallback = function(responseText) {
if (responseText) {
return JSON.parse(responseText);
} else {
return undefined;
}
};
if (typeof pathOrRequestMatcher === "string") {
return sendRequest(host, port, "/retrieve", createResponseMatcher(pathOrRequestMatcher), resolveCallback);
} else if (pathOrRequestMatcher) {
return sendRequest(host, port, "/retrieve", pathOrRequestMatcher, resolveCallback);
} else {
return sendRequest(host, port, "/retrieve", createResponseMatcher(".*"), resolveCallback);
}
};
/**
* Retrieve the setup expectations that match the parameter,
* the expectation is retrieved by matching the parameter
* on the expectations own request matcher, as follows:
* - use a string value to match on path,
* - use a request matcher object to match on a full request,
* - or use null to retrieve all requests
*
* @param pathOrRequestMatcher if a string is passed in the value will be treated as the path, however
* if an object is passed in the value will be treated as a full request
* matcher object, if null is passed in it will be treated as match all
*/
var retrieveExpectations = function (pathOrRequestMatcher) {
var resolveCallback = function(responseText) {
if (responseText) {
return JSON.parse(responseText);
} else {
return undefined;
}
};
if (typeof pathOrRequestMatcher === "string") {
return sendRequest(host, port, "/retrieve?type=expectation", createResponseMatcher(pathOrRequestMatcher), resolveCallback);
} else if (pathOrRequestMatcher) {
return sendRequest(host, port, "/retrieve?type=expectation", pathOrRequestMatcher, resolveCallback);
} else {
return sendRequest(host, port, "/retrieve?type=expectation", createResponseMatcher(".*"), resolveCallback);
}
};
var _this = {
mockAnyResponse: mockAnyResponse,
mockSimpleResponse: mockSimpleResponse,
setDefaultHeaders: setDefaultHeaders,
verify: verify,
verifySequence: verifySequence,
reset: reset,
clear: clear,
retrieveRequests: retrieveRequests,
retrieveExpectations: retrieveExpectations
};
return _this;
},
/**
* Start the client communicating to a MockServer proxy at the specified host and port
* for example:
*
* var client = proxyClient("localhost", 1080);
*
* @param host the host for the proxy to communicate with
* @param port the port for the proxy to communicate with
*/
proxyClient = function (host, port) {
var createResponseMatcher = function (path) {
return {
method: "",
path: path,
body: "",
headers: [],
cookies: [],
queryStringParameters: []
};
};
/**
* Verify a request has been sent for example:
*
* expect(client.verify({
* 'httpRequest': {
* 'method': 'POST',
* 'path': '/somePath'
* }
* })).toBeTruthy();
*
* @param request the http request that must be matched for this verification to pass
* @param count the number of times this request must be matched
* @param exact true if the count is matched as "equal to" or false if the count is matched as "greater than or equal to"
*/
var verify = function (request, count, exact) {
if (count === undefined) {
count = 1;
}
return sendRequest(host, port, "/verify", JSON.stringify({
"httpRequest": request,
"times": {
"count": count,
"exact": exact
}
})).then(function (result) {
if (result.statusCode !== 202) {
console && console.error && console.error(result.body);
throw result.body;
}
return _this;
});
};
/**
* Verify a sequence of requests has been sent for example:
*
* client.verifySequence(
* {
* 'method': 'POST',
* 'path': '/first_request'
* },
* {
* 'method': 'POST',
* 'path': '/second_request'
* },
* {
* 'method': 'POST',
* 'path': '/third_request'
* }
* );
*
* @param arguments the list of http requests that must be matched for this verification to pass
*/
var verifySequence = function () {
var requestSequence = [];
for (var i = 0; i < arguments.length; i++) {
requestSequence.push(arguments[i]);
}
return sendRequest(host, port, "/verifySequence", JSON.stringify({
"httpRequests": requestSequence
})).then(function (result) {
if (result.statusCode !== 202) {
console && console.error && console.error(result.body);
throw result.body;
}
return _this;
});
};
/**
* Reset the proxy by clearing all recorded requests
*/
var reset = function () {
return sendRequest(host, port, "/reset");
};
/**
* Clear all recorded requests that match the specified path
*
* @param pathOrRequestMatcher if a string is passed in the value will be treated as the path to
* decide which recorded requests to cleared, however if an object is
* passed in the value will be treated as a full request matcher object
*/
var clear = function (pathOrRequestMatcher) {
if (typeof pathOrRequestMatcher === "string") {
return sendRequest(host, port, "/clear", createResponseMatcher(pathOrRequestMatcher));
} else if (pathOrRequestMatcher) {
return sendRequest(host, port, "/clear", pathOrRequestMatcher);
} else {
return sendRequest(host, port, "/clear", createResponseMatcher(".*"));
}
};
/**
* Pretty-print the json for all requests / responses that match the specified path
* as Expectations to the log. They are printed into a dedicated log called mockserver_request.log
*
* @param pathOrRequestMatcher if a string is passed in the value will be treated as the path to
* decide which recorded requests to cleared, however if an object is
* passed in the value will be treated as a full request matcher object
*/
var dumpToLogs = function (pathOrRequestMatcher) {
if (typeof pathOrRequestMatcher === "string") {
return sendRequest(host, port, "/dumpToLog", createResponseMatcher(pathOrRequestMatcher));
} else if (pathOrRequestMatcher) {
return sendRequest(host, port, "/dumpToLog", pathOrRequestMatcher);
} else {
return sendRequest(host, port, "/dumpToLog", createResponseMatcher(".*"));
}
};
var _this = {
verify: verify,
verifySequence: verifySequence,
reset: reset,
clear: clear,
dumpToLogs: dumpToLogs
};
return _this;
};
module.exports = {
mockServerClient: mockServerClient,
proxyClient: proxyClient
mockServerClient: require('./mockServerClient').mockServerClient,
proxyClient: require('./proxyClient').proxyClient
};
})();
{
"name": "mockserver-client",
"description": "A node client for the MockServer",
"version": "1.0.12",
"homepage": "https://github.com/jamesdbloom/mockserver",
"author": {
"name": "James Bloom",
"email": "jamesdbloom@gmail.com",
"url": "http://mock-server.com"
},
"repository": {
"type": "git",
"url": "https://github.com/jamesdbloom/mockserver-client-node.git"
},
"bugs": {
"url": "https://github.com/jamesdbloom/mockserver-client-node/issues"
},
"license": "Apache-2.0",
"engines": {
"node": ">= 0.8.0"
},
"scripts": {
"test": "grunt"
},
"devDependencies": {
"grunt": ">=0.4",
"grunt-contrib-clean": "~1.0",
"grunt-contrib-jshint": "~1.0",
"grunt-contrib-nodeunit": "~1.0",
"grunt-exec": "~1.0",
"mockserver-grunt": "~1",
"nodeunit": "~0.10"
},
"peerDependencies": {
"grunt": ">=0.4"
},
"keywords": [
"mockserver",
"client",
"gruntplugin"
],
"dependencies": {
"q": "~2.0"
}
"name": "mockserver-client",
"description": "A node client for the MockServer",
"version": "1.0.13",
"homepage": "https://github.com/jamesdbloom/mockserver",
"author": {
"name": "James Bloom",
"email": "jamesdbloom@gmail.com",
"url": "http://mock-server.com"
},
"repository": {
"type": "git",
"url": "https://github.com/jamesdbloom/mockserver-client-node.git"
},
"bugs": {
"url": "https://github.com/jamesdbloom/mockserver-client-node/issues"
},
"license": "Apache-2.0",
"engines": {
"node": ">= 0.8.0"
},
"devDependencies": {
"grunt": ">=0.4",
"grunt-contrib-clean": "~1.1",
"grunt-contrib-jshint": "~1.1",
"grunt-contrib-nodeunit": "~1.0",
"grunt-exec": "~2.0",
"grunt-jasmine-runner": "~0.6",
"grunt-karma": "~2.0",
"grunt-webdriver-jasmine-runner": "~0.3",
"jasmine-core": "~2.5",
"karma": "~1.3",
"karma-chrome-launcher": "~2.0",
"karma-firefox-launcher": "~1.0",
"karma-jasmine": "~1.0",
"karma-phantomjs-launcher": "~1.0",
"karma-safari-launcher": "~1.0",
"karma-spec-reporter": "~0.0",
"mockserver-grunt": "~1.0",
"nodeunit": "~0.11"
},
"peerDependencies": {
"grunt": ">=0.4"
},
"keywords": [
"mockserver",
"client",
"gruntplugin"
],
"dependencies": {
"q": "~2.0",
"websocket": "~1.0"
}
}

@@ -5,9 +5,6 @@ # mockserver-client-node

[![Build Status](https://snap-ci.com/jamesdbloom/mockserver-client-node/branch/master/build_image)](https://snap-ci.com/jamesdbloom/mockserver-client-node/branch/master) [![Build Status](https://drone.io/github.com/jamesdbloom/mockserver-client-node/status.png)](https://drone.io/github.com/jamesdbloom/mockserver-client-node/latest) [![Dependency Status](https://david-dm.org/jamesdbloom/mockserver-client-node.png)](https://david-dm.org/jamesdbloom/mockserver-client-node) [![devDependency Status](https://david-dm.org/jamesdbloom/mockserver-client-node/dev-status.png)](https://david-dm.org/jamesdbloom/mockserver-client-node#info=devDependencies)
[![Build status](https://badge.buildkite.com/368c3b69e959f29725d8ab582f8d75dedddceee196d39b6d28.svg?style=square&theme=slack)](https://buildkite.com/mockserver/mockserver-client-node) [![Dependency Status](https://david-dm.org/jamesdbloom/mockserver-client-node.png)](https://david-dm.org/jamesdbloom/mockserver-client-node) [![devDependency Status](https://david-dm.org/jamesdbloom/mockserver-client-node/dev-status.png)](https://david-dm.org/jamesdbloom/mockserver-client-node#info=devDependencies) [![Code Climate](https://codeclimate.com/github/jamesdbloom/mockserver-client-node.png)](https://codeclimate.com/github/jamesdbloom/mockserver-client-node)
<!-- [![NPM](https://nodei.co/npm/mockserver-client.png?downloads=true&stars=true)](https://nodei.co/npm/mockserver-client/) -->
[![NPM](https://nodei.co/npm/mockserver-client.png?downloads=true&stars=true)](https://nodei.co/npm/mockserver-client/)
[![wercker status](https://app.wercker.com/status/7b78f11513b3dc5379f510a7ac82d0d6/m "wercker status")](https://app.wercker.com/project/bykey/7b78f11513b3dc5379f510a7ac82d0d6)
For chat room: [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jamesdbloom/mockserver?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

@@ -44,3 +41,3 @@

```js
mockServerClient("localhost", 1080).mockAnyResponse(
mockServerClient("localhost", 1080).mockAnyExpectation(
{

@@ -91,2 +88,5 @@ 'httpRequest': {

```
## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
## Release History

@@ -110,2 +110,3 @@ * 2014-28-10   v0.0.1   Initial release

* 2016-10-09   v1.0.12  Resolved issues with dependencies
* 2017-04-30   v1.0.13  Added websocket (i.e. method callbacks)

@@ -112,0 +113,0 @@ ---

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