From b08facb7bdcf87a6fd0169a97fe1d81c97e117ab Mon Sep 17 00:00:00 2001 From: Slobodan Stojanovic Date: Wed, 28 Oct 2015 08:53:49 +0100 Subject: [PATCH] Fix indentation and add .eslint rules closes #555 --- .eslintrc | 1 + lib/application.js | 4 +- lib/request.js | 11 +- lib/response.js | 8 +- test/application/context.js | 8 +- test/application/index.js | 8 +- test/application/request.js | 8 +- test/application/respond.js | 451 +++++++++++++++++---------------- test/application/response.js | 8 +- test/application/use.js | 20 +- test/context/cookies.js | 37 ++- test/context/onerror.js | 54 ++-- test/context/state.js | 6 +- test/response/attachment.js | 8 +- test/response/last-modified.js | 3 +- test/response/status.js | 2 +- 16 files changed, 318 insertions(+), 319 deletions(-) diff --git a/.eslintrc b/.eslintrc index f877f9e..a894fff 100644 --- a/.eslintrc +++ b/.eslintrc @@ -11,3 +11,4 @@ rules: yoda: 0 arrow-parens: [2, "as-needed"] arrow-spacing: 2 + dot-location: [2, "property"] diff --git a/lib/application.js b/lib/application.js index b6e2b03..ed9e231 100644 --- a/lib/application.js +++ b/lib/application.js @@ -92,9 +92,7 @@ module.exports = class Application extends Emitter { use(fn) { debug('use %s', fn._name || fn.name || '-'); if (typeof fn !== 'function') throw new TypeError('middleware must be a function!'); - if (isGeneratorFunction(fn)) { - throw new TypeError('Support for generators has been removed. Use Promises or wrap your generator with co.wrap'); - } + 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); return this; } diff --git a/lib/request.js b/lib/request.js index ce98d81..b0ed9ca 100644 --- a/lib/request.js +++ b/lib/request.js @@ -81,9 +81,7 @@ module.exports = { get href() { // support: `GET http://example.com/foo` - if (/^https?:\/\//i.test(this.originalUrl)) { - return this.originalUrl; - } + if (/^https?:\/\//i.test(this.originalUrl)) return this.originalUrl; return this.origin + this.originalUrl; }, @@ -400,12 +398,13 @@ module.exports = { /** * Return subdomains as an array. * - * Subdomains are the dot-separated parts of the host before the main domain of - * the app. By default, the domain of the app is assumed to be the last two + * Subdomains are the dot-separated parts of the host before the main domain + * 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`. * * 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"]`. * * @return {Array} diff --git a/lib/response.js b/lib/response.js index 7bcb151..5a814df 100644 --- a/lib/response.js +++ b/lib/response.js @@ -446,9 +446,11 @@ module.exports = { * * Examples: * - * this.append('Link', ['', '']); - * this.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly'); - * this.append('Warning', '199 Miscellaneous warning'); + * ``` + * this.append('Link', ['', '']); + * this.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly'); + * this.append('Warning', '199 Miscellaneous warning'); + * ``` * * @param {String} field * @param {String|Array} val diff --git a/test/application/context.js b/test/application/context.js index 257cb57..6ff32d0 100644 --- a/test/application/context.js +++ b/test/application/context.js @@ -17,8 +17,8 @@ describe('app.context', function(){ }); request(app1.listen()) - .get('/') - .expect(204, done); + .get('/') + .expect(204, done); }); it('should not affect the original prototype', function(done){ @@ -28,7 +28,7 @@ describe('app.context', function(){ }); request(app2.listen()) - .get('/') - .expect(204, done); + .get('/') + .expect(204, done); }); }); diff --git a/test/application/index.js b/test/application/index.js index 86320bb..9f18709 100644 --- a/test/application/index.js +++ b/test/application/index.js @@ -20,8 +20,8 @@ describe('app', function(){ }); request(app.listen()) - .get('/') - .end(function(){}); + .get('/') + .end(function(){}); }); it('should not .writeHead when !socket.writable', function(done){ @@ -42,8 +42,8 @@ describe('app', function(){ setImmediate(done); request(app.listen()) - .get('/') - .end(function(){}); + .get('/') + .end(function(){}); }); it('should set development env when NODE_ENV missing', function(){ diff --git a/test/application/request.js b/test/application/request.js index 3f85cc1..7e79966 100644 --- a/test/application/request.js +++ b/test/application/request.js @@ -17,8 +17,8 @@ describe('app.request', function(){ }); request(app1.listen()) - .get('/') - .expect(204, done); + .get('/') + .expect(204, done); }); it('should not affect the original prototype', function(done){ @@ -28,7 +28,7 @@ describe('app.request', function(){ }); request(app2.listen()) - .get('/') - .expect(204, done); + .get('/') + .expect(204, done); }); }); diff --git a/test/application/respond.js b/test/application/respond.js index bb7d640..ff2adeb 100644 --- a/test/application/respond.js +++ b/test/application/respond.js @@ -27,10 +27,10 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(200) - .expect('lol') - .end(done); + .get('/') + .expect(200) + .expect('lol') + .end(done); }); }); @@ -67,15 +67,15 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .head('/') - .expect(200) - .end(function(err, res){ - if (err) return done(err); - res.should.have.header('Content-Type', 'text/plain; charset=utf-8'); - res.should.have.header('Content-Length', '5'); - assert(0 == res.text.length); - done(); - }); + .head('/') + .expect(200) + .end(function(err, res){ + if (err) return done(err); + res.should.have.header('Content-Type', 'text/plain; charset=utf-8'); + res.should.have.header('Content-Length', '5'); + assert(0 == res.text.length); + done(); + }); }); it('should keep json headers', function(done){ @@ -88,15 +88,15 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .head('/') - .expect(200) - .end(function(err, res){ - if (err) return done(err); - res.should.have.header('Content-Type', 'application/json; charset=utf-8'); - res.should.have.header('Content-Length', '17'); - assert(0 == res.text.length); - done(); - }); + .head('/') + .expect(200) + .end(function(err, res){ + if (err) return done(err); + res.should.have.header('Content-Type', 'application/json; charset=utf-8'); + res.should.have.header('Content-Length', '17'); + assert(0 == res.text.length); + done(); + }); }); it('should keep string headers', function(done){ @@ -109,15 +109,15 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .head('/') - .expect(200) - .end(function(err, res){ - if (err) return done(err); - res.should.have.header('Content-Type', 'text/plain; charset=utf-8'); - res.should.have.header('Content-Length', '11'); - assert(0 == res.text.length); - done(); - }); + .head('/') + .expect(200) + .end(function(err, res){ + if (err) return done(err); + res.should.have.header('Content-Type', 'text/plain; charset=utf-8'); + res.should.have.header('Content-Length', '11'); + assert(0 == res.text.length); + done(); + }); }); it('should keep buffer headers', function(done){ @@ -130,15 +130,15 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .head('/') - .expect(200) - .end(function(err, res){ - if (err) return done(err); - res.should.have.header('Content-Type', 'application/octet-stream'); - res.should.have.header('Content-Length', '11'); - assert(0 == res.text.length); - done(); - }); + .head('/') + .expect(200) + .end(function(err, res){ + if (err) return done(err); + res.should.have.header('Content-Type', 'application/octet-stream'); + res.should.have.header('Content-Length', '11'); + assert(0 == res.text.length); + 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(); request(server) - .head('/') - .expect(404, done); + .head('/') + .expect(404, done); }); it('should respond with a 200 if body = ""', function(done){ @@ -165,8 +165,8 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .head('/') - .expect(200, done); + .head('/') + .expect(200, done); }); it('should not overwrite the content-type', function(done){ @@ -180,9 +180,9 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .head('/') - .expect('content-type', /application\/javascript/) - .expect(200, done); + .head('/') + .expect('content-type', /application\/javascript/) + .expect(200, done); }); }); @@ -193,8 +193,8 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(404, done); + .get('/') + .expect(404, done); }); }); @@ -217,13 +217,13 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(200) - .end(function(err, res){ - if (err) return done(err); - if (errorCaught) return done(errorCaught); - done(); - }); + .get('/') + .expect(200) + .end(function(err, res){ + if (err) return done(err); + if (errorCaught) return done(errorCaught); + done(); + }); }); it('should send the right body', function(done){ @@ -242,9 +242,9 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(200) - .expect('HelloGoodbye', done); + .get('/') + .expect(200) + .expect('HelloGoodbye', done); }); }); @@ -260,10 +260,10 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(400) - .expect('Content-Length', 11) - .expect('Bad Request', done); + .get('/') + .expect(400) + .expect('Content-Length', 11) + .expect('Bad Request', done); }); }); @@ -278,15 +278,15 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(204) - .expect('') - .end(function(err, res){ - if (err) return done(err); + .get('/') + .expect(204) + .expect('') + .end(function(err, res){ + if (err) return done(err); - res.header.should.not.have.property('content-type'); - done(); - }); + res.header.should.not.have.property('content-type'); + done(); + }); }); }); @@ -301,15 +301,15 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(205) - .expect('') - .end(function(err, res){ - if (err) return done(err); + .get('/') + .expect(205) + .expect('') + .end(function(err, res){ + if (err) return done(err); - res.header.should.not.have.property('content-type'); - done(); - }); + res.header.should.not.have.property('content-type'); + done(); + }); }); }); @@ -324,15 +324,15 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(304) - .expect('') - .end(function(err, res){ - if (err) return done(err); + .get('/') + .expect(304) + .expect('') + .end(function(err, res){ + if (err) return done(err); - res.header.should.not.have.property('content-type'); - done(); - }); + res.header.should.not.have.property('content-type'); + done(); + }); }); }); @@ -348,14 +348,14 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(700) - .expect('custom status') - .end(function(err, res){ - if (err) return done(err); - res.res.statusMessage.should.equal('custom status'); - done(); - }); + .get('/') + .expect(700) + .expect('custom status') + .end(function(err, res){ + if (err) return done(err); + res.res.statusMessage.should.equal('custom status'); + done(); + }); }); }); @@ -371,14 +371,14 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(200) - .expect('ok') - .end(function(err, res){ - if (err) return done(err); - res.res.statusMessage.should.equal('ok'); - done(); - }); + .get('/') + .expect(200) + .expect('ok') + .end(function(err, res){ + if (err) return done(err); + res.res.statusMessage.should.equal('ok'); + done(); + }); }); }); @@ -393,9 +393,9 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(701) - .expect('701', done); + .get('/') + .expect(701) + .expect('701', done); }); }); }); @@ -411,15 +411,15 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(204) - .expect('') - .end(function(err, res){ - if (err) return done(err); + .get('/') + .expect(204) + .expect('') + .end(function(err, res){ + if (err) return done(err); - res.header.should.not.have.property('content-type'); - done(); - }); + res.header.should.not.have.property('content-type'); + done(); + }); }); it('should respond 204 with status=200', function(done){ @@ -433,15 +433,15 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(204) - .expect('') - .end(function(err, res){ - if (err) return done(err); + .get('/') + .expect(204) + .expect('') + .end(function(err, res){ + if (err) return done(err); - res.header.should.not.have.property('content-type'); - done(); - }); + res.header.should.not.have.property('content-type'); + done(); + }); }); it('should respond 205 with status=205', function(done){ @@ -455,15 +455,15 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(205) - .expect('') - .end(function(err, res){ - if (err) return done(err); + .get('/') + .expect(205) + .expect('') + .end(function(err, res){ + if (err) return done(err); - res.header.should.not.have.property('content-type'); - done(); - }); + res.header.should.not.have.property('content-type'); + done(); + }); }); it('should respond 304 with status=304', function(done){ @@ -477,15 +477,15 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(304) - .expect('') - .end(function(err, res){ - if (err) return done(err); + .get('/') + .expect(304) + .expect('') + .end(function(err, res){ + if (err) return done(err); - res.header.should.not.have.property('content-type'); - done(); - }); + res.header.should.not.have.property('content-type'); + done(); + }); }); }); @@ -500,8 +500,8 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect('Hello', done); + .get('/') + .expect('Hello', done); }); }); @@ -516,8 +516,8 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect('Hello', done); + .get('/') + .expect('Hello', done); }); }); @@ -533,15 +533,15 @@ describe('app.respond', function(){ 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.not.have.header('Content-Length'); - res.body.should.eql(pkg); - done(); - }); + .get('/') + .expect('Content-Type', 'application/json; charset=utf-8') + .end(function(err, res){ + if (err) return done(err); + const pkg = require('../../package'); + res.should.not.have.header('Content-Length'); + res.body.should.eql(pkg); + done(); + }); }); it('should strip content-length when overwriting', function(done){ @@ -556,15 +556,15 @@ describe('app.respond', function(){ 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.not.have.header('Content-Length'); - res.body.should.eql(pkg); - done(); - }); + .get('/') + .expect('Content-Type', 'application/json; charset=utf-8') + .end(function(err, res){ + if (err) return done(err); + const pkg = require('../../package'); + res.should.not.have.header('Content-Length'); + res.body.should.eql(pkg); + done(); + }); }); it('should keep content-length if not overwritten', function(done){ @@ -579,42 +579,43 @@ describe('app.respond', function(){ 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(); - }); + .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 keep content-length if overwritten with the same stream', function(done){ - const app = new Koa(); + it('should keep content-length if overwritten with the same stream', + done => { + const app = new Koa(); - app.use(function(ctx){ - ctx.length = fs.readFileSync('package.json').length; - const stream = fs.createReadStream('package.json'); - ctx.body = stream; - ctx.body = stream; - ctx.set('Content-Type', 'application/json; charset=utf-8'); + app.use(function(ctx){ + ctx.length = fs.readFileSync('package.json').length; + const stream = fs.createReadStream('package.json'); + ctx.body = stream; + ctx.body = stream; + 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){ const app = new Koa(); @@ -626,10 +627,10 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect('Content-Type', 'text/plain; charset=utf-8') - .expect(404) - .end(done); + .get('/') + .expect('Content-Type', 'text/plain; charset=utf-8') + .expect(404) + .end(done); }); it('should handle errors when no content status', function(done){ @@ -643,8 +644,8 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(204, done); + .get('/') + .expect(204, done); }); it('should handle all intermediate stream body errors', function(done){ @@ -659,8 +660,8 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(404, done); + .get('/') + .expect(404, done); }); }); @@ -675,9 +676,9 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect('Content-Type', 'application/json; charset=utf-8') - .expect('{"hello":"world"}', done); + .get('/') + .expect('Content-Type', 'application/json; charset=utf-8') + .expect('{"hello":"world"}', done); }); }); @@ -695,8 +696,8 @@ describe('app.respond', function(){ }); request(app.listen()) - .get('/') - .end(function(){}); + .get('/') + .end(function(){}); }); describe('with an .expose property', function(){ @@ -711,9 +712,9 @@ describe('app.respond', function(){ }); request(app.listen()) - .get('/') - .expect(403, 'sorry!') - .end(done); + .get('/') + .expect(403, 'sorry!') + .end(done); }); }); @@ -728,9 +729,9 @@ describe('app.respond', function(){ }); request(app.listen()) - .get('/') - .expect(403, 'Forbidden') - .end(done); + .get('/') + .expect(403, 'Forbidden') + .end(done); }); }); @@ -744,9 +745,9 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(500, 'Internal Server Error') - .end(done); + .get('/') + .expect(500, 'Internal Server Error') + .end(done); }); it('should be catchable', function(done){ @@ -767,9 +768,9 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(200, 'Got error') - .end(done); + .get('/') + .expect(200, 'Got error') + .end(done); }); }); @@ -786,9 +787,9 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(200) - .expect('hello', done); + .get('/') + .expect(200) + .expect('hello', done); }); it('should 204', function(done){ @@ -804,12 +805,12 @@ describe('app.respond', function(){ const server = app.listen(); request(server) - .get('/') - .expect(204) - .end(function(err, res){ - res.should.not.have.header('content-type'); - done(err); - }); + .get('/') + .expect(204) + .end(function(err, res){ + res.should.not.have.header('content-type'); + done(err); + }); }); }); }); diff --git a/test/application/response.js b/test/application/response.js index 29b365c..1b5fc08 100644 --- a/test/application/response.js +++ b/test/application/response.js @@ -17,8 +17,8 @@ describe('app.response', function(){ }); request(app1.listen()) - .get('/') - .expect(204, done); + .get('/') + .expect(204, done); }); it('should not affect the original prototype', function(done){ @@ -28,7 +28,7 @@ describe('app.response', function(){ }); request(app2.listen()) - .get('/') - .expect(204, done); + .get('/') + .expect(204, done); }); }); diff --git a/test/application/use.js b/test/application/use.js index fd7e948..bdda573 100644 --- a/test/application/use.js +++ b/test/application/use.js @@ -33,13 +33,13 @@ describe('app.use(fn)', function(){ const server = app.listen(); request(server) - .get('/') - .expect(404) - .end(function(err){ - if (err) return done(err); - calls.should.eql([1, 2, 3, 4, 5, 6]); - done(); - }); + .get('/') + .expect(404) + .end(function(err){ + if (err) return done(err); + calls.should.eql([1, 2, 3, 4, 5, 6]); + done(); + }); }); // https://github.com/koajs/koa/pull/530#issuecomment-148138051 @@ -51,9 +51,9 @@ describe('app.use(fn)', function(){ }); request(app.listen()) - .get('/') - .expect(404) - .end(done); + .get('/') + .expect(404) + .end(done); }); it('should throw error for non function', function(done){ diff --git a/test/context/cookies.js b/test/context/cookies.js index a8641de..ba3500a 100644 --- a/test/context/cookies.js +++ b/test/context/cookies.js @@ -16,16 +16,15 @@ describe('ctx.cookies.set()', function(){ const server = app.listen(); request(server) - .get('/') - .expect(204) - .end(function(err, res){ - if (err) return done(err); + .get('/') + .expect(204) + .end(function(err, res){ + if (err) return done(err); - res.headers['set-cookie'].some(cookie => /^name=/.test(cookie)) - .should.be.ok; + res.headers['set-cookie'].some(cookie => /^name=/.test(cookie)).should.be.ok; - done(); - }); + done(); + }); }); describe('with .signed', function(){ @@ -42,8 +41,8 @@ describe('ctx.cookies.set()', function(){ }); request(app.listen()) - .get('/') - .expect('.keys required for signed cookies', done); + .get('/') + .expect('.keys required for signed cookies', done); }); }); @@ -60,19 +59,19 @@ describe('ctx.cookies.set()', function(){ const server = app.listen(); request(server) - .get('/') - .expect(204) - .end(function(err, res){ - if (err) return done(err); + .get('/') + .expect(204) + .end(function(err, res){ + 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(); + }); }); }); }); diff --git a/test/context/onerror.js b/test/context/onerror.js index b8e66a2..1d5a498 100644 --- a/test/context/onerror.js +++ b/test/context/onerror.js @@ -17,11 +17,11 @@ describe('ctx.onerror(err)', function(){ const server = app.listen(); request(server) - .get('/') - .expect(418) - .expect('Content-Type', 'text/plain; charset=utf-8') - .expect('Content-Length', '4') - .end(done); + .get('/') + .expect(418) + .expect('Content-Type', 'text/plain; charset=utf-8') + .expect('Content-Length', '4') + .end(done); }); it('should unset all headers', function(done){ @@ -38,18 +38,18 @@ describe('ctx.onerror(err)', function(){ const server = app.listen(); request(server) - .get('/') - .expect(418) - .expect('Content-Type', 'text/plain; charset=utf-8') - .expect('Content-Length', '4') - .end(function(err, res){ - if (err) return done(err); + .get('/') + .expect(418) + .expect('Content-Type', 'text/plain; charset=utf-8') + .expect('Content-Length', '4') + .end(function(err, res){ + if (err) return done(err); - res.headers.should.not.have.property('vary'); - res.headers.should.not.have.property('x-csrf-token'); + res.headers.should.not.have.property('vary'); + res.headers.should.not.have.property('x-csrf-token'); - done(); - }); + done(); + }); }); describe('when invalid err.status', function(){ @@ -67,10 +67,10 @@ describe('ctx.onerror(err)', function(){ const server = app.listen(); request(server) - .get('/') - .expect(500) - .expect('Content-Type', 'text/plain; charset=utf-8') - .expect('Internal Server Error', done); + .get('/') + .expect(500) + .expect('Content-Type', 'text/plain; charset=utf-8') + .expect('Internal Server Error', done); }); }); @@ -88,10 +88,10 @@ describe('ctx.onerror(err)', function(){ const server = app.listen(); request(server) - .get('/') - .expect(500) - .expect('Content-Type', 'text/plain; charset=utf-8') - .expect('Internal Server Error', done); + .get('/') + .expect(500) + .expect('Content-Type', 'text/plain; charset=utf-8') + .expect('Internal Server Error', done); }); }); }); @@ -107,10 +107,10 @@ describe('ctx.onerror(err)', function(){ const server = app.listen(); request(server) - .get('/') - .expect(500) - .expect('Content-Type', 'text/plain; charset=utf-8') - .expect('Internal Server Error', done); + .get('/') + .expect(500) + .expect('Content-Type', 'text/plain; charset=utf-8') + .expect('Internal Server Error', done); }); }); }); diff --git a/test/context/state.js b/test/context/state.js index b6bea98..27ee167 100644 --- a/test/context/state.js +++ b/test/context/state.js @@ -16,8 +16,8 @@ describe('ctx.state', function(){ const server = app.listen(); request(server) - .get('/') - .expect(404) - .end(done); + .get('/') + .expect(404) + .end(done); }); }); diff --git a/test/response/attachment.js b/test/response/attachment.js index 38d393e..b14530e 100644 --- a/test/response/attachment.js +++ b/test/response/attachment.js @@ -40,10 +40,10 @@ describe('ctx.attachment([filename])', function(){ }); request(app.listen()) - .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({foo: 'bar'}) - .expect(200, done); + .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({foo: 'bar'}) + .expect(200, done); }); }); }); diff --git a/test/response/last-modified.js b/test/response/last-modified.js index e008d68..0b276cd 100644 --- a/test/response/last-modified.js +++ b/test/response/last-modified.js @@ -23,8 +23,7 @@ describe('res.lastModified', function(){ const res = response(); const date = new Date(); res.lastModified = date; - (res.lastModified.getTime() / 1000) - .should.equal(Math.floor(date.getTime() / 1000)); + (res.lastModified.getTime() / 1000).should.equal(Math.floor(date.getTime() / 1000)); }); describe('when lastModified not set', function(){ diff --git a/test/response/status.js b/test/response/status.js index b00b2b6..bd717a1 100644 --- a/test/response/status.js +++ b/test/response/status.js @@ -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(); app.use(function(ctx){