Comparing version 0.5.6 to 0.5.7
@@ -326,2 +326,7 @@ var path = require('path') | ||
http.request = function(options, callback) { | ||
if (!options.host) { | ||
options.host = options.hostname; | ||
if (options.port) | ||
options.host += ":" + options.port; | ||
} | ||
var basePath = 'http://' + options.host | ||
@@ -328,0 +333,0 @@ , interceptors = allInterceptors[basePath]; |
@@ -125,7 +125,7 @@ var path = require('path') | ||
function isDone() { | ||
return (Object.keys(interceptors).length === 0, "Mocks not yet satisfied:\n" + pendingMocks().join("\n")); | ||
return (Object.keys(interceptors).length === 0); | ||
} | ||
function done() { | ||
assert.ok(isDone); | ||
assert.ok(isDone(), "Mocks not yet satisfied:\n" + pendingMocks().join("\n")); | ||
} | ||
@@ -132,0 +132,0 @@ |
{ "name" : "nock" | ||
, "description" : "HTTP Server mocking for Node.js" | ||
, "tags" : ["Mock", "HTTP", "testing", "isolation"] | ||
, "version" : "0.5.6" | ||
, "version" : "0.5.7" | ||
, "author" : "Pedro Teixeira <pedro.teixeira@gmail.com>" | ||
@@ -11,2 +11,3 @@ , "contributors" : | ||
, {"name":"Nuno Job"} | ||
, {"name":"Ian Young"} | ||
] | ||
@@ -13,0 +14,0 @@ , "repository" : |
@@ -105,2 +105,25 @@ var nock = require('../.') | ||
tap.test("isDone", function(t) { | ||
var scope = nock('http://www.google.com') | ||
.get('/') | ||
.reply(200, "Hello World!"); | ||
t.notOk(scope.isDone(), "not done when a request is outstanding"); | ||
var req = http.request({ | ||
host: "www.google.com" | ||
, path: '/' | ||
, port: 80 | ||
}, function(res) { | ||
t.equal(res.statusCode, 200); | ||
res.on('end', function() { | ||
t.ok(scope.isDone(), "done after request is made"); | ||
scope.done(); | ||
t.end(); | ||
}); | ||
}); | ||
req.end(); | ||
}); | ||
tap.test("request headers exposed", function(t) { | ||
@@ -724,2 +747,61 @@ | ||
}); | ||
}); | ||
}); | ||
tap.test("can use hostname instead of host", function(t) { | ||
var dataCalled = false | ||
var scope = nock('http://www.google.com') | ||
.get('/') | ||
.reply(200, "Hello World!"); | ||
var req = http.request({ | ||
hostname: "www.google.com" | ||
, path: '/' | ||
}, function(res) { | ||
t.equal(res.statusCode, 200); | ||
res.on('end', function() { | ||
t.ok(dataCalled); | ||
scope.done(); | ||
t.end(); | ||
}); | ||
res.on('data', function(data) { | ||
dataCalled = true; | ||
t.ok(data instanceof Buffer, "data should be buffer"); | ||
t.equal(data.toString(), "Hello World!", "response should match"); | ||
}); | ||
}); | ||
req.end(); | ||
}); | ||
tap.test("can take a port", function(t) { | ||
var dataCalled = false | ||
var scope = nock('http://www.myserver.com:3333') | ||
.get('/') | ||
.reply(200, "Hello World!"); | ||
var req = http.request({ | ||
hostname: "www.myserver.com" | ||
, path: '/' | ||
, port: 3333 | ||
}, function(res) { | ||
t.equal(res.statusCode, 200); | ||
res.on('end', function() { | ||
t.ok(dataCalled); | ||
scope.done(); | ||
t.end(); | ||
}); | ||
res.on('data', function(data) { | ||
dataCalled = true; | ||
t.ok(data instanceof Buffer, "data should be buffer"); | ||
t.equal(data.toString(), "Hello World!", "response should match"); | ||
}); | ||
}); | ||
req.end(); | ||
}); |
41931
1202