lazy-socket
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -10,2 +10,3 @@ var net = require('net'); | ||
this._socket = null; | ||
this._callbacks = []; | ||
@@ -37,2 +38,3 @@ } | ||
this._lazyConnect(); | ||
try { | ||
@@ -64,3 +66,7 @@ this._socket.write.apply(this._socket, args); | ||
LazySocket.prototype.end = function() { | ||
this._socket.end(); | ||
if (this._socket) this._socket.end(); | ||
}; | ||
LazySocket.prototype.destroy = function() { | ||
if (this._socket) this._socket.destroy(); | ||
}; |
@@ -5,3 +5,3 @@ { | ||
"description": "A stateless socket that always lets you write().", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"homepage": "https://github.com/felixge/node-lazy-socket", | ||
@@ -20,3 +20,3 @@ "repository": { | ||
"utest": "0.0.3", | ||
"sinon": "~1.2.0", | ||
"sinon": "1.2.0", | ||
"urun": "0.0.4" | ||
@@ -23,0 +23,0 @@ }, |
@@ -5,2 +5,3 @@ var common = require('../common'); | ||
var LazySocket = common.LazySocket; | ||
var sinon = require('sinon'); | ||
var net = require('net'); | ||
@@ -20,1 +21,42 @@ | ||
}); | ||
var socket; | ||
var fakeSocket; | ||
test('LazySocket', { | ||
before: function() { | ||
socket = new LazySocket(); | ||
fakeSocket = sinon.stub(Object.create(net.Socket.prototype)); | ||
sinon.stub(net, 'createConnection').returns(fakeSocket); | ||
fakeSocket.once.returns(fakeSocket); | ||
// To establish a connection | ||
socket.write(); | ||
}, | ||
after: function() { | ||
net.createConnection.restore(); | ||
}, | ||
'#end when disconnected (does not blow up)': function() { | ||
socket = new LazySocket(); | ||
socket.end(); | ||
}, | ||
'#end when connected': function() { | ||
socket.end(); | ||
assert.ok(fakeSocket.end.calledOnce); | ||
}, | ||
'#destroy when disconnected (does not blow up)': function() { | ||
var socket = new LazySocket(); | ||
socket.destroy(); | ||
}, | ||
'#destroy when connected': function() { | ||
socket.destroy(); | ||
assert.ok(fakeSocket.destroy.calledOnce); | ||
}, | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
465548
211
Updatedsinon@1.2.0