Comparing version 0.1.0 to 0.2.0
@@ -26,2 +26,7 @@ 'use strict'; | ||
Client.prototype.close = function () { | ||
this.res.end(); | ||
this.res.removeAllListeners(); | ||
}; | ||
module.exports = Client; |
{ | ||
"name": "json-lines", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "json-lines streams JSON Lines.", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
@@ -39,2 +39,8 @@ # json-lines | ||
If you want to close the connection, call the `close` function. This will emit the `close` event and clean up any event listeners. | ||
```javascript | ||
client.close(); | ||
``` | ||
## Running the build | ||
@@ -41,0 +47,0 @@ |
@@ -59,2 +59,40 @@ 'use strict'; | ||
test('is able to close a client.', function (done) { | ||
app.get('/', route(function (client) { | ||
client.once('open', function () { | ||
client.send({ foo: 'bar' }); | ||
client.close(); | ||
}); | ||
})); | ||
http.get('http://localhost:' + port, function (res) { | ||
res.once('data', function (data) { | ||
assert.that(JSON.parse(data.toString())).is.equalTo({ foo: 'bar' }); | ||
}); | ||
res.once('end', function () { | ||
done(); | ||
}); | ||
}); | ||
}); | ||
test('emits a close event when the client is closed from the server.', function (done) { | ||
app.get('/', route(function (client) { | ||
client.once('open', function () { | ||
client.close(); | ||
}); | ||
client.once('close', function () { | ||
done(); | ||
}); | ||
})); | ||
http.get('http://localhost:' + port, function (res) { | ||
setTimeout(function () { | ||
res.socket.end(); | ||
res.removeAllListeners(); | ||
}, 0.5 * 1000); | ||
}); | ||
}); | ||
test('cleans up when the client disconnects.', function (done) { | ||
@@ -61,0 +99,0 @@ app.get('/', route(function (client) { |
10910
270
61