Comparing version 1.2.0 to 1.3.0
@@ -42,3 +42,2 @@ function FluentInterface(server, o) { | ||
route.response.code = status; | ||
cr(); | ||
return this; | ||
@@ -49,5 +48,9 @@ }, | ||
route.response.body = body; | ||
cr(); | ||
return this; | ||
}, | ||
delay: function(delay) { | ||
debug('Replacing delay for', url, 'with', delay); | ||
route.response.delay = delay; | ||
return this; | ||
}, | ||
creates: { | ||
@@ -54,0 +57,0 @@ get: forMethod('get', route, top || route), |
@@ -88,2 +88,3 @@ var express = require('express'); | ||
var afterSpecifiedResponse = req.route.afterResponseData; | ||
var responseDelay = specifiedResponse.delay || 0; | ||
@@ -102,11 +103,12 @@ debug(req.method, 'request to', req.url, 'returning', specifiedResponse.code); | ||
} | ||
setTimeout(function() { | ||
res.send(specifiedResponse.code, responseBody); | ||
res.send(specifiedResponse.code, responseBody); | ||
if (afterSpecifiedResponse && afterSpecifiedResponse.endpoints) { | ||
debug('Response sent, setting up', afterSpecifiedResponse.endpoints.length, 'endpoints'); | ||
afterSpecifiedResponse.endpoints.forEach(function (endpoint) { | ||
createRoute(endpoint); | ||
}); | ||
} | ||
if (afterSpecifiedResponse && afterSpecifiedResponse.endpoints) { | ||
debug('Response sent, setting up', afterSpecifiedResponse.endpoints.length, 'endpoints'); | ||
afterSpecifiedResponse.endpoints.forEach(function (endpoint) { | ||
createRoute(endpoint); | ||
}); | ||
} | ||
}, responseDelay) | ||
}); | ||
@@ -113,0 +115,0 @@ |
{ | ||
"name": "interfake", | ||
"preferGlobal": true, | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"author": "Daniel Hough <daniel.hough@gmail.com>", | ||
@@ -6,0 +6,0 @@ "description": "A simple way to create dummy APIs", |
@@ -145,4 +145,5 @@ # Interfake: Quick JSON APIs | ||
response: { | ||
code: 200, | ||
body: { | ||
code: 200, // HTTP Status Code | ||
delay: 50, // Delay in milliseconds | ||
body: { // JSON Body Response | ||
next:'more stuff' | ||
@@ -170,2 +171,3 @@ } | ||
* `#body(body)`: Set the JSON response body of the end point | ||
* `#delay(milliseconds)`: Set the number of milliseconds to delay the response by to mimic network of processing lag | ||
* `#create#get|post|put|delete(url)`: Specify an endpoint to create *after* the first execution of this one. API is the same as above. | ||
@@ -196,2 +198,3 @@ | ||
"code": 200, | ||
"delay": 100, | ||
"body": { | ||
@@ -224,3 +227,3 @@ "theTime": "Adventure Time!", | ||
Run `interfake -?` for a full list of command-line options. | ||
Run `interfake --help` for a full list of command-line options. | ||
@@ -328,2 +331,7 @@ ### Conditional endpoints | ||
## Works well with | ||
* [Mocha](http://visionmedia.github.io/mocha/) - the test framework | ||
* [Zombie.js](http://zombie.labnotes.org/) - the Node.js-powered headless web browser | ||
## Thank yous | ||
@@ -330,0 +338,0 @@ |
21174
233
346