http-mockserver
Advanced tools
Comparing version 1.1.4 to 1.1.5
{ | ||
"name": "http-mockserver", | ||
"description": "Testing made easy with mocked http servers", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -8,3 +8,4 @@ const Q = require('q'); | ||
constructor (port, serverHost) { | ||
constructor (port, serverHost, debugMode) { | ||
this.debugMode = debugMode; | ||
this.port = port; | ||
@@ -76,2 +77,3 @@ this.serverHost = serverHost; | ||
addRoute (options) { | ||
this.log('Adding route', options); | ||
return this.req({ | ||
@@ -102,5 +104,5 @@ uri: '/listener/' + this.port, | ||
return request(options).spread((response, body) => { | ||
return request(options).spread((response) => { | ||
if (_.inRange(response.statusCode, 400, 600)) { | ||
throw new Error(`Request failed: ${request.method} ${request.href} with status=${response.statusCode}, body=${body}`); | ||
throw new Error(`Request failed: options=${JSON.stringify(options)}, response=${response.body}`); | ||
} | ||
@@ -110,4 +112,10 @@ return response; | ||
} | ||
log (...args) { | ||
if (this.debugMode) { | ||
console.log.apply(console, args); | ||
} | ||
} | ||
} | ||
module.exports = MockClient; |
16957
516