Remove co dependency

closes #558
closes #557

Change tests to use plain functions and promises

Add test

return promise in middleware

Change benchmarks to use plain functions and promises

typeerror
This commit is contained in:
Felix Becker 2015-10-27 15:59:40 +01:00 committed by jongleberry
parent ded7a17140
commit ebb4850709
15 changed files with 92 additions and 83 deletions

View file

@ -11,16 +11,17 @@ let n = parseInt(process.env.MW || '1', 10);
console.log(` ${n} middleware`); console.log(` ${n} middleware`);
while (n--) { while (n--) {
app.use(function *(ctx, next){ app.use(function(ctx, next){
yield next(); return next();
}); });
} }
const body = new Buffer('Hello World'); const body = new Buffer('Hello World');
app.use(function *(ctx, next){ app.use(function(ctx, next){
yield next(); return next().then(function(){
this.body = body; this.body = body;
});
}); });
app.listen(3333); app.listen(3333);

View file

@ -21,7 +21,6 @@ const assert = require('assert');
const Stream = require('stream'); const Stream = require('stream');
const http = require('http'); const http = require('http');
const only = require('only'); const only = require('only');
const co = require('co');
/** /**
* Expose `Application` class. * Expose `Application` class.
@ -93,7 +92,9 @@ module.exports = class Application extends Emitter {
use(fn) { use(fn) {
debug('use %s', fn._name || fn.name || '-'); debug('use %s', fn._name || fn.name || '-');
if (typeof fn !== 'function') throw new TypeError('middleware must be a function!'); if (typeof fn !== 'function') throw new TypeError('middleware must be a function!');
if (isGeneratorFunction(fn)) fn = co.wrap(fn); if (isGeneratorFunction(fn)) {
throw new TypeError('Support for generators has been removed. Use Promises or wrap your generator with co.wrap');
}
this.middleware.push(fn); this.middleware.push(fn);
return this; return this;
} }

View file

@ -19,7 +19,6 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"accepts": "^1.2.2", "accepts": "^1.2.2",
"co": "^4.4.0",
"content-disposition": "~0.5.0", "content-disposition": "~0.5.0",
"content-type": "^1.0.0", "content-type": "^1.0.0",
"cookies": "~0.5.0", "cookies": "~0.5.0",

View file

@ -11,7 +11,7 @@ describe('app.context', function(){
const app2 = new Koa(); const app2 = new Koa();
it('should merge properties', function(done){ it('should merge properties', function(done){
app1.use(function *(ctx, next){ app1.use(function(ctx, next){
assert.equal(ctx.msg, 'hello'); assert.equal(ctx.msg, 'hello');
ctx.status = 204; ctx.status = 204;
}); });
@ -22,7 +22,7 @@ describe('app.context', function(){
}); });
it('should not affect the original prototype', function(done){ it('should not affect the original prototype', function(done){
app2.use(function *(ctx, next){ app2.use(function(ctx, next){
assert.equal(ctx.msg, undefined); assert.equal(ctx.msg, undefined);
ctx.status = 204; ctx.status = 204;
}); });

View file

@ -9,7 +9,7 @@ describe('app', function(){
it('should handle socket errors', function(done){ it('should handle socket errors', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx, next){ app.use(function(ctx, next){
// triggers ctx.socket.writable == false // triggers ctx.socket.writable == false
ctx.socket.emit('error', new Error('boom')); ctx.socket.emit('error', new Error('boom'));
}); });
@ -27,7 +27,7 @@ describe('app', function(){
it('should not .writeHead when !socket.writable', function(done){ it('should not .writeHead when !socket.writable', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx, next){ app.use(function(ctx, next){
// set .writable to false // set .writable to false
ctx.socket.writable = false; ctx.socket.writable = false;
ctx.status = 204; ctx.status = 204;

View file

@ -11,7 +11,7 @@ describe('app.request', function(){
const app2 = new Koa(); const app2 = new Koa();
it('should merge properties', function(done){ it('should merge properties', function(done){
app1.use(function *(ctx, next){ app1.use(function(ctx, next){
assert.equal(ctx.request.message, 'hello'); assert.equal(ctx.request.message, 'hello');
ctx.status = 204; ctx.status = 204;
}); });
@ -22,7 +22,7 @@ describe('app.request', function(){
}); });
it('should not affect the original prototype', function(done){ it('should not affect the original prototype', function(done){
app2.use(function *(ctx, next){ app2.use(function(ctx, next){
assert.equal(ctx.request.message, undefined); assert.equal(ctx.request.message, undefined);
ctx.status = 204; ctx.status = 204;
}); });

View file

@ -9,10 +9,10 @@ const fs = require('fs');
describe('app.respond', function(){ describe('app.respond', function(){
describe('when ctx.respond === false', function(){ describe('when ctx.respond === false', function(){
it('should function *(ctx)', function(done){ it('should function (ctx)', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.body = 'Hello'; ctx.body = 'Hello';
ctx.respond = false; ctx.respond = false;
@ -38,7 +38,7 @@ describe('app.respond', function(){
it('should not send Content-Type header', function(done){ it('should not send Content-Type header', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.body = ''; ctx.body = '';
ctx.type = null; ctx.type = null;
}); });
@ -60,7 +60,7 @@ describe('app.respond', function(){
it('should not respond with the body', function(done){ it('should not respond with the body', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.body = 'Hello'; ctx.body = 'Hello';
}); });
@ -81,7 +81,7 @@ describe('app.respond', function(){
it('should keep json headers', function(done){ it('should keep json headers', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.body = { hello: 'world' }; ctx.body = { hello: 'world' };
}); });
@ -102,7 +102,7 @@ describe('app.respond', function(){
it('should keep string headers', function(done){ it('should keep string headers', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.body = 'hello world'; ctx.body = 'hello world';
}); });
@ -123,7 +123,7 @@ describe('app.respond', function(){
it('should keep buffer headers', function(done){ it('should keep buffer headers', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.body = new Buffer('hello world'); ctx.body = new Buffer('hello world');
}); });
@ -144,7 +144,7 @@ describe('app.respond', function(){
it('should respond with a 404 if no body was set', function(done){ it('should respond with a 404 if no body was set', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
}); });
@ -158,7 +158,7 @@ describe('app.respond', function(){
it('should respond with a 200 if body = ""', function(done){ it('should respond with a 200 if body = ""', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.body = ''; ctx.body = '';
}); });
@ -172,7 +172,7 @@ describe('app.respond', function(){
it('should not overwrite the content-type', function(done){ it('should not overwrite the content-type', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.status = 200; ctx.status = 200;
ctx.type = 'application/javascript'; ctx.type = 'application/javascript';
}); });
@ -202,7 +202,7 @@ describe('app.respond', function(){
it('should not cause an app error', function(done){ it('should not cause an app error', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx, next){ app.use(function(ctx, next){
const res = ctx.res; const res = ctx.res;
ctx.status = 200; ctx.status = 200;
res.setHeader('Content-Type', 'text/html'); res.setHeader('Content-Type', 'text/html');
@ -229,7 +229,7 @@ describe('app.respond', function(){
it('should send the right body', function(done){ it('should send the right body', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx, next){ app.use(function(ctx, next){
const res = ctx.res; const res = ctx.res;
ctx.status = 200; ctx.status = 200;
res.setHeader('Content-Type', 'text/html'); res.setHeader('Content-Type', 'text/html');
@ -253,7 +253,7 @@ describe('app.respond', function(){
it('should respond with the associated status message', function(done){ it('should respond with the associated status message', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.status = 400; ctx.status = 400;
}); });
@ -271,7 +271,7 @@ describe('app.respond', function(){
it('should respond without a body', function(done){ it('should respond without a body', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.status = 204; ctx.status = 204;
}); });
@ -294,7 +294,7 @@ describe('app.respond', function(){
it('should respond without a body', function(done){ it('should respond without a body', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.status = 205; ctx.status = 205;
}); });
@ -317,7 +317,7 @@ describe('app.respond', function(){
it('should respond without a body', function(done){ it('should respond without a body', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.status = 304; ctx.status = 304;
}); });
@ -341,7 +341,7 @@ describe('app.respond', function(){
const app = new Koa(); const app = new Koa();
statuses['700'] = 'custom status'; statuses['700'] = 'custom status';
app.use(function *(ctx){ app.use(function(ctx){
ctx.status = 700; ctx.status = 700;
}); });
@ -363,7 +363,7 @@ describe('app.respond', function(){
it('should respond with the custom status message', function(done){ it('should respond with the custom status message', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.status = 200; ctx.status = 200;
ctx.message = 'ok'; ctx.message = 'ok';
}); });
@ -386,7 +386,7 @@ describe('app.respond', function(){
it('should respond with the status code number', function(done){ it('should respond with the status code number', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.res.statusCode = 701; ctx.res.statusCode = 701;
}); });
@ -404,7 +404,7 @@ describe('app.respond', function(){
it('should respond 204 by default', function(done){ it('should respond 204 by default', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.body = null; ctx.body = null;
}); });
@ -425,7 +425,7 @@ describe('app.respond', function(){
it('should respond 204 with status=200', function(done){ it('should respond 204 with status=200', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.status = 200; ctx.status = 200;
ctx.body = null; ctx.body = null;
}); });
@ -447,7 +447,7 @@ describe('app.respond', function(){
it('should respond 205 with status=205', function(done){ it('should respond 205 with status=205', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.status = 205; ctx.status = 205;
ctx.body = null; ctx.body = null;
}); });
@ -469,7 +469,7 @@ describe('app.respond', function(){
it('should respond 304 with status=304', function(done){ it('should respond 304 with status=304', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.status = 304; ctx.status = 304;
ctx.body = null; ctx.body = null;
}); });
@ -493,7 +493,7 @@ describe('app.respond', function(){
it('should respond', function(done){ it('should respond', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.body = 'Hello'; ctx.body = 'Hello';
}); });
@ -509,7 +509,7 @@ describe('app.respond', function(){
it('should respond', function(done){ it('should respond', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.body = new Buffer('Hello'); ctx.body = new Buffer('Hello');
}); });
@ -525,7 +525,7 @@ describe('app.respond', function(){
it('should respond', function(done){ it('should respond', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.body = fs.createReadStream('package.json'); ctx.body = fs.createReadStream('package.json');
ctx.set('Content-Type', 'application/json; charset=utf-8'); ctx.set('Content-Type', 'application/json; charset=utf-8');
}); });
@ -547,7 +547,7 @@ describe('app.respond', function(){
it('should strip content-length when overwriting', function(done){ it('should strip content-length when overwriting', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.body = 'hello'; ctx.body = 'hello';
ctx.body = fs.createReadStream('package.json'); ctx.body = fs.createReadStream('package.json');
ctx.set('Content-Type', 'application/json; charset=utf-8'); ctx.set('Content-Type', 'application/json; charset=utf-8');
@ -570,7 +570,7 @@ describe('app.respond', function(){
it('should keep content-length if not overwritten', function(done){ it('should keep content-length if not overwritten', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.length = fs.readFileSync('package.json').length; ctx.length = fs.readFileSync('package.json').length;
ctx.body = fs.createReadStream('package.json'); ctx.body = fs.createReadStream('package.json');
ctx.set('Content-Type', 'application/json; charset=utf-8'); ctx.set('Content-Type', 'application/json; charset=utf-8');
@ -593,7 +593,7 @@ describe('app.respond', function(){
it('should keep content-length if overwritten with the same stream', function(done){ it('should keep content-length if overwritten with the same stream', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.length = fs.readFileSync('package.json').length; ctx.length = fs.readFileSync('package.json').length;
const stream = fs.createReadStream('package.json'); const stream = fs.createReadStream('package.json');
ctx.body = stream; ctx.body = stream;
@ -618,7 +618,7 @@ describe('app.respond', function(){
it('should handle errors', function(done){ it('should handle errors', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.set('Content-Type', 'application/json; charset=utf-8'); ctx.set('Content-Type', 'application/json; charset=utf-8');
ctx.body = fs.createReadStream('does not exist'); ctx.body = fs.createReadStream('does not exist');
}); });
@ -635,7 +635,7 @@ describe('app.respond', function(){
it('should handle errors when no content status', function(done){ it('should handle errors when no content status', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.status = 204; ctx.status = 204;
ctx.body = fs.createReadStream('does not exist'); ctx.body = fs.createReadStream('does not exist');
}); });
@ -650,7 +650,7 @@ describe('app.respond', function(){
it('should handle all intermediate stream body errors', function(done){ it('should handle all intermediate stream body errors', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.body = fs.createReadStream('does not exist'); ctx.body = fs.createReadStream('does not exist');
ctx.body = fs.createReadStream('does not exist'); ctx.body = fs.createReadStream('does not exist');
ctx.body = fs.createReadStream('does not exist'); ctx.body = fs.createReadStream('does not exist');
@ -668,7 +668,7 @@ describe('app.respond', function(){
it('should respond with json', function(done){ it('should respond with json', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.body = { hello: 'world' }; ctx.body = { hello: 'world' };
}); });
@ -685,7 +685,7 @@ describe('app.respond', function(){
it('should emit "error" on the app', function(done){ it('should emit "error" on the app', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
throw new Error('boom'); throw new Error('boom');
}); });
@ -703,7 +703,7 @@ describe('app.respond', function(){
it('should expose the message', function(done){ it('should expose the message', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
const err = new Error('sorry!'); const err = new Error('sorry!');
err.status = 403; err.status = 403;
err.expose = true; err.expose = true;
@ -721,7 +721,7 @@ describe('app.respond', function(){
it('should respond with .status', function(done){ it('should respond with .status', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
const err = new Error('s3 explodes'); const err = new Error('s3 explodes');
err.status = 403; err.status = 403;
throw err; throw err;
@ -737,7 +737,7 @@ describe('app.respond', function(){
it('should respond with 500', function(done){ it('should respond with 500', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
throw new Error('boom!'); throw new Error('boom!');
}); });
@ -752,16 +752,15 @@ describe('app.respond', function(){
it('should be catchable', function(done){ it('should be catchable', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx, next){ app.use(function(ctx, next){
try { return next().then(function(){
yield next();
ctx.body = 'Hello'; ctx.body = 'Hello';
} catch (err) { }).catch(function(){
ctx.body = 'Got error'; ctx.body = 'Got error';
} });
}); });
app.use(function *(ctx, next){ app.use(function(ctx, next){
throw new Error('boom!'); throw new Error('boom!');
}); });
@ -778,7 +777,7 @@ describe('app.respond', function(){
it('should 200', function(done){ it('should 200', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.status = 304; ctx.status = 304;
ctx.body = 'hello'; ctx.body = 'hello';
ctx.status = 200; ctx.status = 200;
@ -795,7 +794,7 @@ describe('app.respond', function(){
it('should 204', function(done){ it('should 204', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.status = 200; ctx.status = 200;
ctx.body = 'hello'; ctx.body = 'hello';
ctx.set('content-type', 'text/plain; charset=utf8'); ctx.set('content-type', 'text/plain; charset=utf8');

View file

@ -11,7 +11,7 @@ describe('app.response', function(){
const app2 = new Koa(); const app2 = new Koa();
it('should merge properties', function(done){ it('should merge properties', function(done){
app1.use(function *(ctx, next){ app1.use(function(ctx, next){
assert.equal(ctx.response.msg, 'hello'); assert.equal(ctx.response.msg, 'hello');
ctx.status = 204; ctx.status = 204;
}); });
@ -22,7 +22,7 @@ describe('app.response', function(){
}); });
it('should not affect the original prototype', function(done){ it('should not affect the original prototype', function(done){
app2.use(function *(ctx, next){ app2.use(function(ctx, next){
assert.equal(ctx.response.msg, undefined); assert.equal(ctx.response.msg, undefined);
ctx.status = 204; ctx.status = 204;
}); });

View file

@ -9,22 +9,25 @@ describe('app.use(fn)', function(){
const app = new Koa(); const app = new Koa();
const calls = []; const calls = [];
app.use(function *(ctx, next){ app.use(function(ctx, next){
calls.push(1); calls.push(1);
yield next(); return next().then(function(){
calls.push(6); calls.push(6);
});
}); });
app.use(function *(ctx, next){ app.use(function(ctx, next){
calls.push(2); calls.push(2);
yield next(); return next().then(function(){
calls.push(5); calls.push(5);
});
}); });
app.use(function *(ctx, next){ app.use(function(ctx, next){
calls.push(3); calls.push(3);
yield next(); return next().then(function(){
calls.push(4); calls.push(4);
});
}); });
const server = app.listen(); const server = app.listen();
@ -59,4 +62,10 @@ describe('app.use(fn)', function(){
(() => app.use('not a function')).should.throw('middleware must be a function!'); (() => app.use('not a function')).should.throw('middleware must be a function!');
done(); done();
}); });
it('should throw error for generator', function(){
const app = new Koa();
(() => app.use(function *(){})).should.throw('Support for generators has been removed. Use Promises or wrap your generator with co.wrap');
});
}); });

View file

@ -8,7 +8,7 @@ describe('ctx.cookies.set()', function(){
it('should set an unsigned cookie', function(done){ it('should set an unsigned cookie', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx, next){ app.use(function(ctx, next){
ctx.cookies.set('name', 'jon'); ctx.cookies.set('name', 'jon');
ctx.status = 204; ctx.status = 204;
}); });
@ -33,7 +33,7 @@ describe('ctx.cookies.set()', function(){
it('should error', function(done){ it('should error', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx, next){ app.use(function(ctx, next){
try { try {
ctx.cookies.set('foo', 'bar', { signed: true }); ctx.cookies.set('foo', 'bar', { signed: true });
} catch (err) { } catch (err) {
@ -52,7 +52,7 @@ describe('ctx.cookies.set()', function(){
app.keys = ['a', 'b']; app.keys = ['a', 'b'];
app.use(function *(ctx, next){ app.use(function(ctx, next){
ctx.cookies.set('name', 'jon', { signed: true }); ctx.cookies.set('name', 'jon', { signed: true });
ctx.status = 204; ctx.status = 204;
}); });

View file

@ -8,7 +8,7 @@ describe('ctx.onerror(err)', function(){
it('should respond', function(done){ it('should respond', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx, next){ app.use(function(ctx, next){
ctx.body = 'something else'; ctx.body = 'something else';
ctx.throw(418, 'boom'); ctx.throw(418, 'boom');
@ -27,7 +27,7 @@ describe('ctx.onerror(err)', function(){
it('should unset all headers', function(done){ it('should unset all headers', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx, next){ app.use(function(ctx, next){
ctx.set('Vary', 'Accept-Encoding'); ctx.set('Vary', 'Accept-Encoding');
ctx.set('X-CSRF-Token', 'asdf'); ctx.set('X-CSRF-Token', 'asdf');
ctx.body = 'response'; ctx.body = 'response';
@ -57,7 +57,7 @@ describe('ctx.onerror(err)', function(){
it('should respond 500', function(done){ it('should respond 500', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx, next){ app.use(function(ctx, next){
ctx.body = 'something else'; ctx.body = 'something else';
const err = new Error('some error'); const err = new Error('some error');
err.status = 'notnumber'; err.status = 'notnumber';
@ -78,7 +78,7 @@ describe('ctx.onerror(err)', function(){
it('should respond 500', function(done){ it('should respond 500', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx, next){ app.use(function(ctx, next){
ctx.body = 'something else'; ctx.body = 'something else';
const err = new Error('some error'); const err = new Error('some error');
err.status = 9999; err.status = 9999;
@ -100,7 +100,7 @@ describe('ctx.onerror(err)', function(){
it('should response non-error thrown message', function(done){ it('should response non-error thrown message', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx, next){ app.use(function(ctx, next){
throw 'string error'; // eslint-disable-line no-throw-literal throw 'string error'; // eslint-disable-line no-throw-literal
}); });

View file

@ -9,7 +9,7 @@ describe('ctx.state', function(){
it('should provide a ctx.state namespace', function(done){ it('should provide a ctx.state namespace', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
assert.deepEqual(ctx.state, {}); assert.deepEqual(ctx.state, {});
}); });

View file

@ -26,7 +26,7 @@ describe('ctx.href', function(){
it('should work with `GET http://example.com/foo`', function(done){ it('should work with `GET http://example.com/foo`', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.body = ctx.href; ctx.body = ctx.href;
}); });
app.listen(function(){ app.listen(function(){

View file

@ -34,7 +34,7 @@ describe('ctx.attachment([filename])', function(){
it('should work with http client', function(done){ it('should work with http client', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx, next){ app.use(function(ctx, next){
ctx.attachment('path/to/include-no-ascii-char-中文名-ok.json'); ctx.attachment('path/to/include-no-ascii-char-中文名-ok.json');
ctx.body = {foo: 'bar'}; ctx.body = {foo: 'bar'};
}); });

View file

@ -62,7 +62,7 @@ describe('res.status=', function(){
it('should strip content related header fields', function(done){ it('should strip content related header fields', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.body = { foo: 'bar' }; ctx.body = { foo: 'bar' };
ctx.set('Content-Type', 'application/json; charset=utf-8'); ctx.set('Content-Type', 'application/json; charset=utf-8');
ctx.set('Content-Length', '15'); ctx.set('Content-Length', '15');
@ -88,7 +88,7 @@ describe('res.status=', function(){
it('should strip content releated header fields after status set', function(done){ it('should strip content releated header fields after status set', function(done){
const app = new Koa(); const app = new Koa();
app.use(function *(ctx){ app.use(function(ctx){
ctx.status = status; ctx.status = status;
ctx.body = { foo: 'bar' }; ctx.body = { foo: 'bar' };
ctx.set('Content-Type', 'application/json; charset=utf-8'); ctx.set('Content-Type', 'application/json; charset=utf-8');