Fix indentation and add .eslint rules

closes #555
master
Slobodan Stojanovic 2015-10-28 08:53:49 +01:00 committed by jongleberry
parent 6d3b81fe50
commit b08facb7bd
16 changed files with 318 additions and 319 deletions

View File

@ -11,3 +11,4 @@ rules:
yoda: 0 yoda: 0
arrow-parens: [2, "as-needed"] arrow-parens: [2, "as-needed"]
arrow-spacing: 2 arrow-spacing: 2
dot-location: [2, "property"]

View File

@ -92,9 +92,7 @@ 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)) { if (isGeneratorFunction(fn)) throw new TypeError('Support for generators has been removed. Use Promises or wrap your generator with co.wrap');
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

@ -81,9 +81,7 @@ module.exports = {
get href() { get href() {
// support: `GET http://example.com/foo` // support: `GET http://example.com/foo`
if (/^https?:\/\//i.test(this.originalUrl)) { if (/^https?:\/\//i.test(this.originalUrl)) return this.originalUrl;
return this.originalUrl;
}
return this.origin + this.originalUrl; return this.origin + this.originalUrl;
}, },
@ -400,12 +398,13 @@ module.exports = {
/** /**
* Return subdomains as an array. * Return subdomains as an array.
* *
* Subdomains are the dot-separated parts of the host before the main domain of * Subdomains are the dot-separated parts of the host before the main domain
* the app. By default, the domain of the app is assumed to be the last two * of the app. By default, the domain of the app is assumed to be the last two
* parts of the host. This can be changed by setting `app.subdomainOffset`. * parts of the host. This can be changed by setting `app.subdomainOffset`.
* *
* For example, if the domain is "tobi.ferrets.example.com": * For example, if the domain is "tobi.ferrets.example.com":
* If `app.subdomainOffset` is not set, this.subdomains is `["ferrets", "tobi"]`. * If `app.subdomainOffset` is not set, this.subdomains is
* `["ferrets", "tobi"]`.
* If `app.subdomainOffset` is 3, this.subdomains is `["tobi"]`. * If `app.subdomainOffset` is 3, this.subdomains is `["tobi"]`.
* *
* @return {Array} * @return {Array}

View File

@ -446,9 +446,11 @@ module.exports = {
* *
* Examples: * Examples:
* *
* this.append('Link', ['<http://localhost/>', '<http://localhost:3000/>']); * ```
* this.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly'); * this.append('Link', ['<http://localhost/>', '<http://localhost:3000/>']);
* this.append('Warning', '199 Miscellaneous warning'); * this.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly');
* this.append('Warning', '199 Miscellaneous warning');
* ```
* *
* @param {String} field * @param {String} field
* @param {String|Array} val * @param {String|Array} val

View File

@ -17,8 +17,8 @@ describe('app.context', function(){
}); });
request(app1.listen()) request(app1.listen())
.get('/') .get('/')
.expect(204, done); .expect(204, done);
}); });
it('should not affect the original prototype', function(done){ it('should not affect the original prototype', function(done){
@ -28,7 +28,7 @@ describe('app.context', function(){
}); });
request(app2.listen()) request(app2.listen())
.get('/') .get('/')
.expect(204, done); .expect(204, done);
}); });
}); });

View File

@ -20,8 +20,8 @@ describe('app', function(){
}); });
request(app.listen()) request(app.listen())
.get('/') .get('/')
.end(function(){}); .end(function(){});
}); });
it('should not .writeHead when !socket.writable', function(done){ it('should not .writeHead when !socket.writable', function(done){
@ -42,8 +42,8 @@ describe('app', function(){
setImmediate(done); setImmediate(done);
request(app.listen()) request(app.listen())
.get('/') .get('/')
.end(function(){}); .end(function(){});
}); });
it('should set development env when NODE_ENV missing', function(){ it('should set development env when NODE_ENV missing', function(){

View File

@ -17,8 +17,8 @@ describe('app.request', function(){
}); });
request(app1.listen()) request(app1.listen())
.get('/') .get('/')
.expect(204, done); .expect(204, done);
}); });
it('should not affect the original prototype', function(done){ it('should not affect the original prototype', function(done){
@ -28,7 +28,7 @@ describe('app.request', function(){
}); });
request(app2.listen()) request(app2.listen())
.get('/') .get('/')
.expect(204, done); .expect(204, done);
}); });
}); });

View File

@ -27,10 +27,10 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(200) .expect(200)
.expect('lol') .expect('lol')
.end(done); .end(done);
}); });
}); });
@ -67,15 +67,15 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.head('/') .head('/')
.expect(200) .expect(200)
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
res.should.have.header('Content-Type', 'text/plain; charset=utf-8'); res.should.have.header('Content-Type', 'text/plain; charset=utf-8');
res.should.have.header('Content-Length', '5'); res.should.have.header('Content-Length', '5');
assert(0 == res.text.length); assert(0 == res.text.length);
done(); done();
}); });
}); });
it('should keep json headers', function(done){ it('should keep json headers', function(done){
@ -88,15 +88,15 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.head('/') .head('/')
.expect(200) .expect(200)
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
res.should.have.header('Content-Type', 'application/json; charset=utf-8'); res.should.have.header('Content-Type', 'application/json; charset=utf-8');
res.should.have.header('Content-Length', '17'); res.should.have.header('Content-Length', '17');
assert(0 == res.text.length); assert(0 == res.text.length);
done(); done();
}); });
}); });
it('should keep string headers', function(done){ it('should keep string headers', function(done){
@ -109,15 +109,15 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.head('/') .head('/')
.expect(200) .expect(200)
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
res.should.have.header('Content-Type', 'text/plain; charset=utf-8'); res.should.have.header('Content-Type', 'text/plain; charset=utf-8');
res.should.have.header('Content-Length', '11'); res.should.have.header('Content-Length', '11');
assert(0 == res.text.length); assert(0 == res.text.length);
done(); done();
}); });
}); });
it('should keep buffer headers', function(done){ it('should keep buffer headers', function(done){
@ -130,15 +130,15 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.head('/') .head('/')
.expect(200) .expect(200)
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
res.should.have.header('Content-Type', 'application/octet-stream'); res.should.have.header('Content-Type', 'application/octet-stream');
res.should.have.header('Content-Length', '11'); res.should.have.header('Content-Length', '11');
assert(0 == res.text.length); assert(0 == res.text.length);
done(); done();
}); });
}); });
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){
@ -151,8 +151,8 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.head('/') .head('/')
.expect(404, done); .expect(404, done);
}); });
it('should respond with a 200 if body = ""', function(done){ it('should respond with a 200 if body = ""', function(done){
@ -165,8 +165,8 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.head('/') .head('/')
.expect(200, done); .expect(200, done);
}); });
it('should not overwrite the content-type', function(done){ it('should not overwrite the content-type', function(done){
@ -180,9 +180,9 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.head('/') .head('/')
.expect('content-type', /application\/javascript/) .expect('content-type', /application\/javascript/)
.expect(200, done); .expect(200, done);
}); });
}); });
@ -193,8 +193,8 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(404, done); .expect(404, done);
}); });
}); });
@ -217,13 +217,13 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(200) .expect(200)
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
if (errorCaught) return done(errorCaught); if (errorCaught) return done(errorCaught);
done(); done();
}); });
}); });
it('should send the right body', function(done){ it('should send the right body', function(done){
@ -242,9 +242,9 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(200) .expect(200)
.expect('HelloGoodbye', done); .expect('HelloGoodbye', done);
}); });
}); });
@ -260,10 +260,10 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(400) .expect(400)
.expect('Content-Length', 11) .expect('Content-Length', 11)
.expect('Bad Request', done); .expect('Bad Request', done);
}); });
}); });
@ -278,15 +278,15 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(204) .expect(204)
.expect('') .expect('')
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
res.header.should.not.have.property('content-type'); res.header.should.not.have.property('content-type');
done(); done();
}); });
}); });
}); });
@ -301,15 +301,15 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(205) .expect(205)
.expect('') .expect('')
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
res.header.should.not.have.property('content-type'); res.header.should.not.have.property('content-type');
done(); done();
}); });
}); });
}); });
@ -324,15 +324,15 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(304) .expect(304)
.expect('') .expect('')
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
res.header.should.not.have.property('content-type'); res.header.should.not.have.property('content-type');
done(); done();
}); });
}); });
}); });
@ -348,14 +348,14 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(700) .expect(700)
.expect('custom status') .expect('custom status')
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
res.res.statusMessage.should.equal('custom status'); res.res.statusMessage.should.equal('custom status');
done(); done();
}); });
}); });
}); });
@ -371,14 +371,14 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(200) .expect(200)
.expect('ok') .expect('ok')
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
res.res.statusMessage.should.equal('ok'); res.res.statusMessage.should.equal('ok');
done(); done();
}); });
}); });
}); });
@ -393,9 +393,9 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(701) .expect(701)
.expect('701', done); .expect('701', done);
}); });
}); });
}); });
@ -411,15 +411,15 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(204) .expect(204)
.expect('') .expect('')
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
res.header.should.not.have.property('content-type'); res.header.should.not.have.property('content-type');
done(); done();
}); });
}); });
it('should respond 204 with status=200', function(done){ it('should respond 204 with status=200', function(done){
@ -433,15 +433,15 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(204) .expect(204)
.expect('') .expect('')
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
res.header.should.not.have.property('content-type'); res.header.should.not.have.property('content-type');
done(); done();
}); });
}); });
it('should respond 205 with status=205', function(done){ it('should respond 205 with status=205', function(done){
@ -455,15 +455,15 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(205) .expect(205)
.expect('') .expect('')
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
res.header.should.not.have.property('content-type'); res.header.should.not.have.property('content-type');
done(); done();
}); });
}); });
it('should respond 304 with status=304', function(done){ it('should respond 304 with status=304', function(done){
@ -477,15 +477,15 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(304) .expect(304)
.expect('') .expect('')
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
res.header.should.not.have.property('content-type'); res.header.should.not.have.property('content-type');
done(); done();
}); });
}); });
}); });
@ -500,8 +500,8 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect('Hello', done); .expect('Hello', done);
}); });
}); });
@ -516,8 +516,8 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect('Hello', done); .expect('Hello', done);
}); });
}); });
@ -533,15 +533,15 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect('Content-Type', 'application/json; charset=utf-8') .expect('Content-Type', 'application/json; charset=utf-8')
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
const pkg = require('../../package'); const pkg = require('../../package');
res.should.not.have.header('Content-Length'); res.should.not.have.header('Content-Length');
res.body.should.eql(pkg); res.body.should.eql(pkg);
done(); done();
}); });
}); });
it('should strip content-length when overwriting', function(done){ it('should strip content-length when overwriting', function(done){
@ -556,15 +556,15 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect('Content-Type', 'application/json; charset=utf-8') .expect('Content-Type', 'application/json; charset=utf-8')
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
const pkg = require('../../package'); const pkg = require('../../package');
res.should.not.have.header('Content-Length'); res.should.not.have.header('Content-Length');
res.body.should.eql(pkg); res.body.should.eql(pkg);
done(); done();
}); });
}); });
it('should keep content-length if not overwritten', function(done){ it('should keep content-length if not overwritten', function(done){
@ -579,42 +579,43 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect('Content-Type', 'application/json; charset=utf-8') .expect('Content-Type', 'application/json; charset=utf-8')
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
const pkg = require('../../package'); const pkg = require('../../package');
res.should.have.header('Content-Length'); res.should.have.header('Content-Length');
res.body.should.eql(pkg); res.body.should.eql(pkg);
done(); done();
}); });
}); });
it('should keep content-length if overwritten with the same stream', function(done){ it('should keep content-length if overwritten with the same stream',
const app = new Koa(); done => {
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;
ctx.body = stream; ctx.body = stream;
ctx.set('Content-Type', 'application/json; charset=utf-8'); ctx.set('Content-Type', 'application/json; charset=utf-8');
});
const server = app.listen();
request(server)
.get('/')
.expect('Content-Type', 'application/json; charset=utf-8')
.end(function(err, res){
if (err) return done(err);
const pkg = require('../../package');
res.should.have.header('Content-Length');
res.body.should.eql(pkg);
done();
});
}); });
const server = app.listen();
request(server)
.get('/')
.expect('Content-Type', 'application/json; charset=utf-8')
.end(function(err, res){
if (err) return done(err);
const pkg = require('../../package');
res.should.have.header('Content-Length');
res.body.should.eql(pkg);
done();
});
});
it('should handle errors', function(done){ it('should handle errors', function(done){
const app = new Koa(); const app = new Koa();
@ -626,10 +627,10 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect('Content-Type', 'text/plain; charset=utf-8') .expect('Content-Type', 'text/plain; charset=utf-8')
.expect(404) .expect(404)
.end(done); .end(done);
}); });
it('should handle errors when no content status', function(done){ it('should handle errors when no content status', function(done){
@ -643,8 +644,8 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(204, done); .expect(204, done);
}); });
it('should handle all intermediate stream body errors', function(done){ it('should handle all intermediate stream body errors', function(done){
@ -659,8 +660,8 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(404, done); .expect(404, done);
}); });
}); });
@ -675,9 +676,9 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect('Content-Type', 'application/json; charset=utf-8') .expect('Content-Type', 'application/json; charset=utf-8')
.expect('{"hello":"world"}', done); .expect('{"hello":"world"}', done);
}); });
}); });
@ -695,8 +696,8 @@ describe('app.respond', function(){
}); });
request(app.listen()) request(app.listen())
.get('/') .get('/')
.end(function(){}); .end(function(){});
}); });
describe('with an .expose property', function(){ describe('with an .expose property', function(){
@ -711,9 +712,9 @@ describe('app.respond', function(){
}); });
request(app.listen()) request(app.listen())
.get('/') .get('/')
.expect(403, 'sorry!') .expect(403, 'sorry!')
.end(done); .end(done);
}); });
}); });
@ -728,9 +729,9 @@ describe('app.respond', function(){
}); });
request(app.listen()) request(app.listen())
.get('/') .get('/')
.expect(403, 'Forbidden') .expect(403, 'Forbidden')
.end(done); .end(done);
}); });
}); });
@ -744,9 +745,9 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(500, 'Internal Server Error') .expect(500, 'Internal Server Error')
.end(done); .end(done);
}); });
it('should be catchable', function(done){ it('should be catchable', function(done){
@ -767,9 +768,9 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(200, 'Got error') .expect(200, 'Got error')
.end(done); .end(done);
}); });
}); });
@ -786,9 +787,9 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(200) .expect(200)
.expect('hello', done); .expect('hello', done);
}); });
it('should 204', function(done){ it('should 204', function(done){
@ -804,12 +805,12 @@ describe('app.respond', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(204) .expect(204)
.end(function(err, res){ .end(function(err, res){
res.should.not.have.header('content-type'); res.should.not.have.header('content-type');
done(err); done(err);
}); });
}); });
}); });
}); });

View File

@ -17,8 +17,8 @@ describe('app.response', function(){
}); });
request(app1.listen()) request(app1.listen())
.get('/') .get('/')
.expect(204, done); .expect(204, done);
}); });
it('should not affect the original prototype', function(done){ it('should not affect the original prototype', function(done){
@ -28,7 +28,7 @@ describe('app.response', function(){
}); });
request(app2.listen()) request(app2.listen())
.get('/') .get('/')
.expect(204, done); .expect(204, done);
}); });
}); });

View File

@ -33,13 +33,13 @@ describe('app.use(fn)', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(404) .expect(404)
.end(function(err){ .end(function(err){
if (err) return done(err); if (err) return done(err);
calls.should.eql([1, 2, 3, 4, 5, 6]); calls.should.eql([1, 2, 3, 4, 5, 6]);
done(); done();
}); });
}); });
// https://github.com/koajs/koa/pull/530#issuecomment-148138051 // https://github.com/koajs/koa/pull/530#issuecomment-148138051
@ -51,9 +51,9 @@ describe('app.use(fn)', function(){
}); });
request(app.listen()) request(app.listen())
.get('/') .get('/')
.expect(404) .expect(404)
.end(done); .end(done);
}); });
it('should throw error for non function', function(done){ it('should throw error for non function', function(done){

View File

@ -16,16 +16,15 @@ describe('ctx.cookies.set()', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(204) .expect(204)
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
res.headers['set-cookie'].some(cookie => /^name=/.test(cookie)) res.headers['set-cookie'].some(cookie => /^name=/.test(cookie)).should.be.ok;
.should.be.ok;
done(); done();
}); });
}); });
describe('with .signed', function(){ describe('with .signed', function(){
@ -42,8 +41,8 @@ describe('ctx.cookies.set()', function(){
}); });
request(app.listen()) request(app.listen())
.get('/') .get('/')
.expect('.keys required for signed cookies', done); .expect('.keys required for signed cookies', done);
}); });
}); });
@ -60,19 +59,19 @@ describe('ctx.cookies.set()', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(204) .expect(204)
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
const cookies = res.headers['set-cookie']; const cookies = res.headers['set-cookie'];
cookies.some(cookie => /^name=/.test(cookie)).should.be.ok; cookies.some(cookie => /^name=/.test(cookie)).should.be.ok;
cookies.some(cookie => /^name\.sig=/.test(cookie)).should.be.ok; cookies.some(cookie => /^name\.sig=/.test(cookie)).should.be.ok;
done(); done();
}); });
}); });
}); });
}); });

View File

@ -17,11 +17,11 @@ describe('ctx.onerror(err)', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(418) .expect(418)
.expect('Content-Type', 'text/plain; charset=utf-8') .expect('Content-Type', 'text/plain; charset=utf-8')
.expect('Content-Length', '4') .expect('Content-Length', '4')
.end(done); .end(done);
}); });
it('should unset all headers', function(done){ it('should unset all headers', function(done){
@ -38,18 +38,18 @@ describe('ctx.onerror(err)', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(418) .expect(418)
.expect('Content-Type', 'text/plain; charset=utf-8') .expect('Content-Type', 'text/plain; charset=utf-8')
.expect('Content-Length', '4') .expect('Content-Length', '4')
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
res.headers.should.not.have.property('vary'); res.headers.should.not.have.property('vary');
res.headers.should.not.have.property('x-csrf-token'); res.headers.should.not.have.property('x-csrf-token');
done(); done();
}); });
}); });
describe('when invalid err.status', function(){ describe('when invalid err.status', function(){
@ -67,10 +67,10 @@ describe('ctx.onerror(err)', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(500) .expect(500)
.expect('Content-Type', 'text/plain; charset=utf-8') .expect('Content-Type', 'text/plain; charset=utf-8')
.expect('Internal Server Error', done); .expect('Internal Server Error', done);
}); });
}); });
@ -88,10 +88,10 @@ describe('ctx.onerror(err)', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(500) .expect(500)
.expect('Content-Type', 'text/plain; charset=utf-8') .expect('Content-Type', 'text/plain; charset=utf-8')
.expect('Internal Server Error', done); .expect('Internal Server Error', done);
}); });
}); });
}); });
@ -107,10 +107,10 @@ describe('ctx.onerror(err)', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(500) .expect(500)
.expect('Content-Type', 'text/plain; charset=utf-8') .expect('Content-Type', 'text/plain; charset=utf-8')
.expect('Internal Server Error', done); .expect('Internal Server Error', done);
}); });
}); });
}); });

View File

@ -16,8 +16,8 @@ describe('ctx.state', function(){
const server = app.listen(); const server = app.listen();
request(server) request(server)
.get('/') .get('/')
.expect(404) .expect(404)
.end(done); .end(done);
}); });
}); });

View File

@ -40,10 +40,10 @@ describe('ctx.attachment([filename])', function(){
}); });
request(app.listen()) request(app.listen())
.get('/') .get('/')
.expect('content-disposition', 'attachment; filename="include-no-ascii-char-???-ok.json"; filename*=UTF-8\'\'include-no-ascii-char-%E4%B8%AD%E6%96%87%E5%90%8D-ok.json') .expect('content-disposition', 'attachment; filename="include-no-ascii-char-???-ok.json"; filename*=UTF-8\'\'include-no-ascii-char-%E4%B8%AD%E6%96%87%E5%90%8D-ok.json')
.expect({foo: 'bar'}) .expect({foo: 'bar'})
.expect(200, done); .expect(200, done);
}); });
}); });
}); });

View File

@ -23,8 +23,7 @@ describe('res.lastModified', function(){
const res = response(); const res = response();
const date = new Date(); const date = new Date();
res.lastModified = date; res.lastModified = date;
(res.lastModified.getTime() / 1000) (res.lastModified.getTime() / 1000).should.equal(Math.floor(date.getTime() / 1000));
.should.equal(Math.floor(date.getTime() / 1000));
}); });
describe('when lastModified not set', function(){ describe('when lastModified not set', function(){

View File

@ -85,7 +85,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', done => {
const app = new Koa(); const app = new Koa();
app.use(function(ctx){ app.use(function(ctx){