finished -> on-finished

removes the writable test because it’s fake and there are tests for
on-finished for this case
This commit is contained in:
Jonathan Ong 2014-08-16 02:58:06 -07:00
parent 920909c546
commit 9455726c00
5 changed files with 9 additions and 18 deletions

View file

@ -9,7 +9,7 @@ var isJSON = require('koa-is-json');
var response = require('./response');
var context = require('./context');
var request = require('./request');
var finished = require('finished');
var onFinished = require('on-finished');
var Cookies = require('cookies');
var accepts = require('accepts');
var status = require('statuses');
@ -121,7 +121,7 @@ app.callback = function(){
return function(req, res){
res.statusCode = 404;
var ctx = self.createContext(req, res);
finished(ctx, ctx.onerror);
onFinished(res, ctx.onerror);
fn.call(ctx, ctx.onerror);
}
};

View file

@ -7,7 +7,7 @@ var ensureErrorHandler = require('error-inject');
var getType = require('mime-types').contentType;
var isJSON = require('koa-is-json');
var escape = require('escape-html');
var onfinish = require('finished');
var onFinish = require('on-finished');
var typeis = require('type-is').is;
var status = require('statuses');
var destroy = require('destroy');
@ -127,7 +127,7 @@ module.exports = {
// stream
if ('function' == typeof val.pipe) {
onfinish(this, destroy.bind(null, val));
onFinish(this.res, destroy.bind(null, val));
ensureErrorHandler(val, this.ctx.onerror);
// overwriting

View file

@ -27,7 +27,7 @@
"type-is": "~1.3.1",
"mime-types": "~1.0.0",
"media-typer": "~0.2.0",
"finished": "~1.2.0",
"on-finished": "~2.0.0",
"co": "~3.1.0",
"debug": "*",
"fresh": "~0.2.1",

View file

@ -1,13 +1,14 @@
var ReadableStream = require('stream').Readable;
var Stream = require('stream');
var context = require('../lib/context');
var request = require('../lib/request');
var response = require('../lib/response');
var koa = require('..');
exports = module.exports = function(req, res){
req = req || { headers: {}, socket: new ReadableStream() };
res = res || { _headers: {} };
var socket = new Stream.Duplex();
req = req || { headers: {}, socket: socket, __proto__: Stream.Readable.prototype };
res = res || { _headers: {}, socket: socket, __proto__: Stream.Writable.prototype };
res.getHeader = function(k){ return res._headers[k.toLowerCase()] };
res.setHeader = function(k, v){ res._headers[k.toLowerCase()] = v };
res.removeHeader = function(k, v){ delete res._headers[k.toLowerCase()] };

View file

@ -1,10 +0,0 @@
var context = require('../context');
describe('ctx.writable', function(){
it('should not crash when the socket does not exist', function(){
var ctx = context();
ctx.socket = null;
ctx.writable.should.equal(false);
})
})