http-mockserver
Advanced tools
Comparing version 2.2.0 to 2.2.2
{ | ||
"name": "http-mockserver", | ||
"description": "Testing made easy with mocked http servers", | ||
"version": "2.2.0", | ||
"version": "2.2.2", | ||
"license": "MIT", | ||
@@ -31,2 +31,3 @@ "jest": { | ||
"express": "4.14.0", | ||
"express-xml-bodyparser": "^0.3.0", | ||
"http-proxy": "1.16.2", | ||
@@ -33,0 +34,0 @@ "lodash": "4.17.4", |
@@ -36,6 +36,2 @@ class MockServerFactory { | ||
addMocks (...args) { | ||
return this.addMocks(...args); | ||
} | ||
sendData (options) { | ||
@@ -42,0 +38,0 @@ return this.service.sendData(this.port, options); |
@@ -69,6 +69,2 @@ const Q = require('q'); | ||
clientService.addMocks = function (...mocks) { | ||
return Q.all(mocks.map(clientService.addMock)); | ||
}; | ||
clientService.sendData = function (port, options) { | ||
@@ -75,0 +71,0 @@ return req({ |
@@ -10,2 +10,3 @@ const _ = require('lodash'); | ||
const pathRegexp = require('path-to-regexp'); | ||
const xmlparser = require('express-xml-bodyparser'); | ||
@@ -20,2 +21,3 @@ class Listener { | ||
app.use(bodyParser.text()); | ||
app.use(xmlparser({trim: false, explicitArray: false})); | ||
app.use((req, res, next) => { | ||
@@ -48,10 +50,7 @@ requestLogService.addEntry(req, res); | ||
this.mocks[uri] = this.mocks[uri] || {}; | ||
// Register mock if it hasn't been registered before | ||
if (!this.mocks[uri][method]) { | ||
this.app[method.toLowerCase()](uri, (req, res) => { | ||
return this.mocks[uri][method].handler(req, res); | ||
}); | ||
const oldMock = this.mocks[uri][method]; | ||
if (oldMock) { | ||
// close pending requests | ||
oldMock.clients.forEach(client => client.end()); | ||
} | ||
this.mocks[uri][method] = { | ||
@@ -63,2 +62,9 @@ options: options, | ||
}; | ||
// Register mock if it hasn't been registered before | ||
if (!oldMock) { | ||
this.app[method.toLowerCase()](uri, (req, res) => { | ||
return this.mocks[uri][method].handler(req, res); | ||
}); | ||
} | ||
} | ||
@@ -65,0 +71,0 @@ |
@@ -31,2 +31,6 @@ const Listener = require('./Listener'); | ||
if (!isValidHttpMethod(options.method)) { | ||
throw new Error(`"${options.method}" is not a valid http method`); | ||
} | ||
const listener = listeners[port] || listenerService.addListener(port); | ||
@@ -68,2 +72,7 @@ const hasMock = listener.get(options.uri, options.method); | ||
function isValidHttpMethod (method) { | ||
const methods = require('http').METHODS; | ||
return methods.includes(method.toUpperCase()); | ||
} | ||
module.exports = listenerService; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
34007
959
12
28
5
+ Addedexpress-xml-bodyparser@0.3.0(transitive)
+ Addedsax@1.4.1(transitive)
+ Addedxml2js@0.4.23(transitive)
+ Addedxmlbuilder@11.0.1(transitive)