diff --git a/Makefile b/Makefile index 827dff9..7a089f6 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ include node_modules/make-lint/index.mk REQUIRED = --require should --require should-http -TESTS = test/application \ +TESTS = test/application/* \ test/context/* \ test/request/* \ test/response/* \ diff --git a/test/application/context.js b/test/application/context.js new file mode 100644 index 0000000..ad35427 --- /dev/null +++ b/test/application/context.js @@ -0,0 +1,34 @@ + +'use strict'; + +const request = require('supertest'); +const assert = require('assert'); +const koa = require('../..'); + +describe('app.context', function(){ + const app1 = koa(); + app1.context.msg = 'hello'; + const app2 = koa(); + + it('should merge properties', function(done){ + app1.use(function *(next){ + assert.equal(this.msg, 'hello') + this.status = 204 + }); + + request(app1.listen()) + .get('/') + .expect(204, done); + }) + + it('should not affect the original prototype', function(done){ + app2.use(function *(next){ + assert.equal(this.msg, undefined) + this.status = 204; + }); + + request(app2.listen()) + .get('/') + .expect(204, done); + }) +}) diff --git a/test/application/index.js b/test/application/index.js new file mode 100644 index 0000000..7dc0828 --- /dev/null +++ b/test/application/index.js @@ -0,0 +1,56 @@ + +'use strict'; + +const request = require('supertest'); +const assert = require('assert'); +const koa = require('../..'); + +describe('app', function(){ + it('should handle socket errors', function(done){ + const app = koa(); + + app.use(function *(next){ + // triggers this.socket.writable == false + this.socket.emit('error', new Error('boom')); + }); + + app.on('error', function(err){ + err.message.should.equal('boom'); + done(); + }); + + request(app.listen()) + .get('/') + .end(function(){}); + }) + + it('should not .writeHead when !socket.writable', function(done){ + const app = koa(); + + app.use(function *(next){ + // set .writable to false + this.socket.writable = false; + this.status = 204; + // throw if .writeHead or .end is called + this.res.writeHead = + this.res.end = function(){ + throw new Error('response sent'); + }; + }) + + // hackish, but the response should occur in a single tick + setImmediate(done); + + request(app.listen()) + .get('/') + .end(function(){}); + }) + + it('should set development env when NODE_ENV missing', function(){ + const NODE_ENV = process.env.NODE_ENV; + process.env.NODE_ENV = ''; + const app = koa(); + process.env.NODE_ENV = NODE_ENV; + assert.equal(app.env, 'development'); + }) +}) diff --git a/test/application/inspect.js b/test/application/inspect.js new file mode 100644 index 0000000..d3bcef1 --- /dev/null +++ b/test/application/inspect.js @@ -0,0 +1,12 @@ + +'use strict'; + +const koa = require('../..'); + +describe('app.inspect()', function(){ + it('should work', function(){ + const app = koa(); + const util = require('util'); + const str = util.inspect(app); + }) +}) diff --git a/test/application/onerror.js b/test/application/onerror.js new file mode 100644 index 0000000..df64177 --- /dev/null +++ b/test/application/onerror.js @@ -0,0 +1,84 @@ + +'use strict'; + +const stderr = require('test-console').stderr; +const koa = require('../..'); +const AssertionError = require('assert').AssertionError; + +describe('app.onerror(err)', function(){ + it('should throw an error if a non-error is given', function(done){ + const app = koa(); + + try { + app.onerror('foo'); + + should.fail(); + } catch (err) { + err.should.be.instanceOf(AssertionError); + err.message.should.equal('non-error thrown: foo'); + } + + done(); + }) + + it('should do nothing if status is 404', function(done){ + const app = koa(); + const err = new Error(); + + err.status = 404; + + const output = stderr.inspectSync(function() { + app.onerror(err); + }); + + output.should.eql([]); + + done(); + }) + + it('should do nothing if .silent', function(done){ + const app = koa(); + app.silent = true; + const err = new Error(); + + const output = stderr.inspectSync(function() { + app.onerror(err); + }); + + output.should.eql([]); + + done(); + }) + + it('should log the error to stderr', function(done){ + const app = koa(); + app.env = 'dev'; + + const err = new Error(); + err.stack = 'Foo'; + + const output = stderr.inspectSync(function() { + app.onerror(err); + }); + + output.should.eql(["\n", " Foo\n", "\n"]); + + done(); + }) + + it('should use err.toString() instad of err.stack', function(done){ + const app = koa(); + app.env = 'dev'; + + const err = new Error('mock stack null'); + err.stack = null; + + const output = stderr.inspectSync(function() { + app.onerror(err); + }); + + output.should.eql(["\n", " Error: mock stack null\n", "\n"]); + + done(); + }) +}) diff --git a/test/application/request.js b/test/application/request.js new file mode 100644 index 0000000..984e7de --- /dev/null +++ b/test/application/request.js @@ -0,0 +1,34 @@ + +'use strict'; + +const request = require('supertest'); +const assert = require('assert'); +const koa = require('../..'); + +describe('app.request', function(){ + const app1 = koa(); + app1.request.message = 'hello'; + const app2 = koa(); + + it('should merge properties', function(done){ + app1.use(function *(next){ + assert.equal(this.request.message, 'hello') + this.status = 204 + }); + + request(app1.listen()) + .get('/') + .expect(204, done); + }) + + it('should not affect the original prototype', function(done){ + app2.use(function *(next){ + assert.equal(this.request.message, undefined) + this.status = 204; + }); + + request(app2.listen()) + .get('/') + .expect(204, done); + }) +}) diff --git a/test/application.js b/test/application/respond.js similarity index 74% rename from test/application.js rename to test/application/respond.js index 5a455c2..a3a8c82 100644 --- a/test/application.js +++ b/test/application/respond.js @@ -1,214 +1,11 @@ 'use strict'; -const stderr = require('test-console').stderr; const request = require('supertest'); const statuses = require('statuses'); const assert = require('assert'); -const http = require('http'); -const koa = require('..'); +const koa = require('../..'); const fs = require('fs'); -const AssertionError = assert.AssertionError; - -describe('app', function(){ - it('should handle socket errors', function(done){ - const app = koa(); - - app.use(function *(next){ - // triggers this.socket.writable == false - this.socket.emit('error', new Error('boom')); - }); - - app.on('error', function(err){ - err.message.should.equal('boom'); - done(); - }); - - request(app.listen()) - .get('/') - .end(function(){}); - }) - - it('should not .writeHead when !socket.writable', function(done){ - const app = koa(); - - app.use(function *(next){ - // set .writable to false - this.socket.writable = false; - this.status = 204; - // throw if .writeHead or .end is called - this.res.writeHead = - this.res.end = function(){ - throw new Error('response sent'); - }; - }) - - // hackish, but the response should occur in a single tick - setImmediate(done); - - request(app.listen()) - .get('/') - .end(function(){}); - }) - - it('should set development env when NODE_ENV missing', function(){ - const NODE_ENV = process.env.NODE_ENV; - process.env.NODE_ENV = ''; - const app = koa(); - process.env.NODE_ENV = NODE_ENV; - assert.equal(app.env, 'development'); - }) -}) - -describe('app.toJSON()', function(){ - it('should work', function(){ - const app = koa(); - const obj = app.toJSON(); - - obj.should.eql({ - subdomainOffset: 2, - env: 'test' - }); - }) -}) - -describe('app.inspect()', function(){ - it('should work', function(){ - const app = koa(); - const util = require('util'); - const str = util.inspect(app); - }) -}) - -describe('app.use(fn)', function(){ - it('should compose middleware', function(done){ - const app = koa(); - const calls = []; - - app.use(function *(next){ - calls.push(1); - yield next; - calls.push(6); - }); - - app.use(function *(next){ - calls.push(2); - yield next; - calls.push(5); - }); - - app.use(function *(next){ - calls.push(3); - yield next; - calls.push(4); - }); - - 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(); - }); - }) - - it('should error when a non-generator function is passed', function(){ - const app = koa(); - - try { - app.use(function(){}); - } catch (err) { - err.message.should.equal('app.use() requires a generator function'); - } - }) - - it('should not error when a non-generator function is passed when .experimental=true', function(){ - const app = koa(); - app.experimental = true; - app.use(function(){}); - }) -}) - -describe('app.onerror(err)', function(){ - it('should throw an error if a non-error is given', function(done){ - const app = koa(); - - try { - app.onerror('foo'); - - should.fail(); - } catch (err) { - err.should.be.instanceOf(AssertionError); - err.message.should.equal('non-error thrown: foo'); - } - - done(); - }) - - it('should do nothing if status is 404', function(done){ - const app = koa(); - const err = new Error(); - - err.status = 404; - - const output = stderr.inspectSync(function() { - app.onerror(err); - }); - - output.should.eql([]); - - done(); - }) - - it('should do nothing if .silent', function(done){ - const app = koa(); - app.silent = true; - const err = new Error(); - - const output = stderr.inspectSync(function() { - app.onerror(err); - }); - - output.should.eql([]); - - done(); - }) - - it('should log the error to stderr', function(done){ - const app = koa(); - app.env = 'dev'; - - const err = new Error(); - err.stack = 'Foo'; - - const output = stderr.inspectSync(function() { - app.onerror(err); - }); - - output.should.eql(["\n", " Foo\n", "\n"]); - - done(); - }) - - it('should use err.toString() instad of err.stack', function(done){ - const app = koa(); - app.env = 'dev'; - - const err = new Error('mock stack null'); - err.stack = null; - - const output = stderr.inspectSync(function() { - app.onerror(err); - }); - - output.should.eql(["\n", " Error: mock stack null\n", "\n"]); - - done(); - }) -}) describe('app.respond', function(){ describe('when this.respond === false', function(){ @@ -722,7 +519,7 @@ describe('app.respond', function(){ .expect('Content-Type', 'application/json; charset=utf-8') .end(function(err, res){ if (err) return done(err); - const pkg = require('../package'); + const pkg = require('../../package'); res.should.not.have.header('Content-Length'); res.body.should.eql(pkg); done(); @@ -745,7 +542,7 @@ describe('app.respond', function(){ .expect('Content-Type', 'application/json; charset=utf-8') .end(function(err, res){ if (err) return done(err); - const pkg = require('../package'); + const pkg = require('../../package'); res.should.not.have.header('Content-Length'); res.body.should.eql(pkg); done(); @@ -768,7 +565,7 @@ describe('app.respond', function(){ .expect('Content-Type', 'application/json; charset=utf-8') .end(function(err, res){ if (err) return done(err); - const pkg = require('../package'); + const pkg = require('../../package'); res.should.have.header('Content-Length'); res.body.should.eql(pkg); done(); @@ -793,7 +590,7 @@ describe('app.respond', function(){ .expect('Content-Type', 'application/json; charset=utf-8') .end(function(err, res){ if (err) return done(err); - const pkg = require('../package'); + const pkg = require('../../package'); res.should.have.header('Content-Length'); res.body.should.eql(pkg); done(); @@ -1001,87 +798,3 @@ describe('app.respond', function(){ }); }) }) - -describe('app.context', function(){ - const app1 = koa(); - app1.context.msg = 'hello'; - const app2 = koa(); - - it('should merge properties', function(done){ - app1.use(function *(next){ - assert.equal(this.msg, 'hello') - this.status = 204 - }); - - request(app1.listen()) - .get('/') - .expect(204, done); - }) - - it('should not affect the original prototype', function(done){ - app2.use(function *(next){ - assert.equal(this.msg, undefined) - this.status = 204; - }); - - request(app2.listen()) - .get('/') - .expect(204, done); - }) -}) - -describe('app.request', function(){ - const app1 = koa(); - app1.request.message = 'hello'; - const app2 = koa(); - - it('should merge properties', function(done){ - app1.use(function *(next){ - assert.equal(this.request.message, 'hello') - this.status = 204 - }); - - request(app1.listen()) - .get('/') - .expect(204, done); - }) - - it('should not affect the original prototype', function(done){ - app2.use(function *(next){ - assert.equal(this.request.message, undefined) - this.status = 204; - }); - - request(app2.listen()) - .get('/') - .expect(204, done); - }) -}) - -describe('app.response', function(){ - const app1 = koa(); - app1.response.msg = 'hello'; - const app2 = koa(); - - it('should merge properties', function(done){ - app1.use(function *(next){ - assert.equal(this.response.msg, 'hello') - this.status = 204 - }); - - request(app1.listen()) - .get('/') - .expect(204, done); - }) - - it('should not affect the original prototype', function(done){ - app2.use(function *(next){ - assert.equal(this.response.msg, undefined) - this.status = 204; - }); - - request(app2.listen()) - .get('/') - .expect(204, done); - }) -}) diff --git a/test/application/response.js b/test/application/response.js new file mode 100644 index 0000000..d71785e --- /dev/null +++ b/test/application/response.js @@ -0,0 +1,34 @@ + +'use strict'; + +const request = require('supertest'); +const assert = require('assert'); +const koa = require('../..'); + +describe('app.response', function(){ + const app1 = koa(); + app1.response.msg = 'hello'; + const app2 = koa(); + + it('should merge properties', function(done){ + app1.use(function *(next){ + assert.equal(this.response.msg, 'hello') + this.status = 204 + }); + + request(app1.listen()) + .get('/') + .expect(204, done); + }) + + it('should not affect the original prototype', function(done){ + app2.use(function *(next){ + assert.equal(this.response.msg, undefined) + this.status = 204; + }); + + request(app2.listen()) + .get('/') + .expect(204, done); + }) +}) diff --git a/test/application/toJSON.js b/test/application/toJSON.js new file mode 100644 index 0000000..2c787f0 --- /dev/null +++ b/test/application/toJSON.js @@ -0,0 +1,16 @@ + +'use strict'; + +const koa = require('../..'); + +describe('app.toJSON()', function(){ + it('should work', function(){ + const app = koa(); + const obj = app.toJSON(); + + obj.should.eql({ + subdomainOffset: 2, + env: 'test' + }); + }) +}) diff --git a/test/application/use.js b/test/application/use.js new file mode 100644 index 0000000..16049ba --- /dev/null +++ b/test/application/use.js @@ -0,0 +1,57 @@ + +'use strict'; + +const request = require('supertest'); +const koa = require('../..'); + +describe('app.use(fn)', function(){ + it('should compose middleware', function(done){ + const app = koa(); + const calls = []; + + app.use(function *(next){ + calls.push(1); + yield next; + calls.push(6); + }); + + app.use(function *(next){ + calls.push(2); + yield next; + calls.push(5); + }); + + app.use(function *(next){ + calls.push(3); + yield next; + calls.push(4); + }); + + 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(); + }); + }) + + it('should error when a non-generator function is passed', function(){ + const app = koa(); + + try { + app.use(function(){}); + } catch (err) { + err.message.should.equal('app.use() requires a generator function'); + } + }) + + it('should not error when a non-generator function is passed when .experimental=true', function(){ + const app = koa(); + app.experimental = true; + app.use(function(){}); + }) +}) diff --git a/test/context/assert.js b/test/context/assert.js index eef693a..f7c86ae 100644 --- a/test/context/assert.js +++ b/test/context/assert.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); const assert = require('assert'); describe('ctx.assert(value, status)', function(){ diff --git a/test/context/inspect.js b/test/context/inspect.js index 9257830..dd0cf44 100644 --- a/test/context/inspect.js +++ b/test/context/inspect.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.inspect()', function(){ it('should return a json representation', function(){ diff --git a/test/context/throw.js b/test/context/throw.js index 173789e..1543d4a 100644 --- a/test/context/throw.js +++ b/test/context/throw.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); const assert = require('assert'); describe('ctx.throw(msg)', function(){ diff --git a/test/context/toJSON.js b/test/context/toJSON.js index 7318423..e8441af 100644 --- a/test/context/toJSON.js +++ b/test/context/toJSON.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.toJSON()', function(){ it('should return a json representation', function(){ diff --git a/test/context.js b/test/helpers/context.js similarity index 96% rename from test/context.js rename to test/helpers/context.js index 2144ad8..f4a9e77 100644 --- a/test/context.js +++ b/test/helpers/context.js @@ -2,7 +2,7 @@ 'use strict'; const Stream = require('stream'); -const koa = require('..'); +const koa = require('../..'); exports = module.exports = function(req, res){ const socket = new Stream.Duplex(); diff --git a/test/request/accepts.js b/test/request/accepts.js index 6094ac5..bcef845 100644 --- a/test/request/accepts.js +++ b/test/request/accepts.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.accepts(types)', function(){ describe('with no arguments', function(){ diff --git a/test/request/acceptsCharsets.js b/test/request/acceptsCharsets.js index ba67517..884157f 100644 --- a/test/request/acceptsCharsets.js +++ b/test/request/acceptsCharsets.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.acceptsCharsets()', function(){ describe('with no arguments', function(){ diff --git a/test/request/acceptsEncodings.js b/test/request/acceptsEncodings.js index b24011d..4deceeb 100644 --- a/test/request/acceptsEncodings.js +++ b/test/request/acceptsEncodings.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.acceptsEncodings()', function(){ describe('with no arguments', function(){ diff --git a/test/request/acceptsLanguages.js b/test/request/acceptsLanguages.js index 8e03668..3488dba 100644 --- a/test/request/acceptsLanguages.js +++ b/test/request/acceptsLanguages.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.acceptsLanguages(langs)', function(){ describe('with no arguments', function(){ diff --git a/test/request/charset.js b/test/request/charset.js index 400f465..c4bd78b 100644 --- a/test/request/charset.js +++ b/test/request/charset.js @@ -1,7 +1,7 @@ 'use strict'; -const request = require('../context').request; +const request = require('../helpers/context').request; const assert = require('assert'); describe('req.charset', function(){ diff --git a/test/request/fresh.js b/test/request/fresh.js index 3f574ee..65a99b3 100644 --- a/test/request/fresh.js +++ b/test/request/fresh.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.fresh', function(){ describe('the request method is not GET and HEAD', function (){ diff --git a/test/request/get.js b/test/request/get.js index 05ea090..fd52d0e 100644 --- a/test/request/get.js +++ b/test/request/get.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.get(name)', function(){ it('should return the field value', function(){ diff --git a/test/request/header.js b/test/request/header.js index 7c706a8..94d3581 100644 --- a/test/request/header.js +++ b/test/request/header.js @@ -1,7 +1,7 @@ 'use strict'; -const request = require('../context').request; +const request = require('../helpers/context').request; describe('req.header', function(){ it('should return the request header object', function(){ diff --git a/test/request/headers.js b/test/request/headers.js index 983e038..9820d80 100644 --- a/test/request/headers.js +++ b/test/request/headers.js @@ -1,7 +1,7 @@ 'use strict'; -const request = require('../context').request; +const request = require('../helpers/context').request; describe('req.headers', function(){ it('should return the request header object', function(){ diff --git a/test/request/host.js b/test/request/host.js index 943caee..1fe7319 100644 --- a/test/request/host.js +++ b/test/request/host.js @@ -1,7 +1,7 @@ 'use strict'; -const request = require('../context').request; +const request = require('../helpers/context').request; const assert = require('assert'); describe('req.host', function(){ diff --git a/test/request/hostname.js b/test/request/hostname.js index fb026b2..9e93aaa 100644 --- a/test/request/hostname.js +++ b/test/request/hostname.js @@ -1,7 +1,7 @@ 'use strict'; -const request = require('../context').request; +const request = require('../helpers/context').request; const assert = require('assert'); describe('req.hostname', function(){ diff --git a/test/request/href.js b/test/request/href.js index d934e03..f204504 100644 --- a/test/request/href.js +++ b/test/request/href.js @@ -4,7 +4,7 @@ const Stream = require('stream'); const http = require('http'); const koa = require('../../'); -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.href', function(){ it('should return the full request url', function(){ diff --git a/test/request/idempotent.js b/test/request/idempotent.js index 86db95b..036755f 100644 --- a/test/request/idempotent.js +++ b/test/request/idempotent.js @@ -1,7 +1,7 @@ 'use strict'; -const request = require('../context').request; +const request = require('../helpers/context').request; describe('ctx.idempotent', function(){ describe('when the request method is idempotent', function (){ diff --git a/test/request/inspect.js b/test/request/inspect.js index 841010f..2d5dd8c 100644 --- a/test/request/inspect.js +++ b/test/request/inspect.js @@ -1,7 +1,7 @@ 'use strict'; -const request = require('../context').request; +const request = require('../helpers/context').request; const assert = require('assert'); describe('req.inspect()', function(){ diff --git a/test/request/ip.js b/test/request/ip.js index 1fb1531..0169167 100644 --- a/test/request/ip.js +++ b/test/request/ip.js @@ -1,7 +1,7 @@ 'use strict'; -const request = require('../context').request; +const request = require('../helpers/context').request; describe('req.ip', function(){ describe('with req.ips present', function(){ diff --git a/test/request/ips.js b/test/request/ips.js index 5f11e27..4f41cc0 100644 --- a/test/request/ips.js +++ b/test/request/ips.js @@ -1,7 +1,7 @@ 'use strict'; -const request = require('../context').request; +const request = require('../helpers/context').request; describe('req.ips', function(){ describe('when X-Forwarded-For is present', function(){ diff --git a/test/request/is.js b/test/request/is.js index 03ebc59..9592ac4 100644 --- a/test/request/is.js +++ b/test/request/is.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); const should = require('should'); const assert = require('assert'); diff --git a/test/request/length.js b/test/request/length.js index abf5c40..2df2118 100644 --- a/test/request/length.js +++ b/test/request/length.js @@ -1,7 +1,7 @@ 'use strict'; -const request = require('../context').request; +const request = require('../helpers/context').request; const assert = require('assert'); describe('ctx.length', function(){ diff --git a/test/request/origin.js b/test/request/origin.js index e7829d9..5fc7840 100644 --- a/test/request/origin.js +++ b/test/request/origin.js @@ -4,7 +4,7 @@ const Stream = require('stream'); const http = require('http'); const koa = require('../../'); -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.origin', function(){ it('should return the origin of url', function(){ diff --git a/test/request/path.js b/test/request/path.js index 0a49d7e..cac7fe8 100644 --- a/test/request/path.js +++ b/test/request/path.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.path', function(){ it('should return the pathname', function(){ diff --git a/test/request/protocol.js b/test/request/protocol.js index 7ba1da9..f35a2ab 100644 --- a/test/request/protocol.js +++ b/test/request/protocol.js @@ -1,7 +1,7 @@ 'use strict'; -const request = require('../context').request; +const request = require('../helpers/context').request; describe('req.protocol', function(){ describe('when encrypted', function(){ diff --git a/test/request/query.js b/test/request/query.js index 06ed1a6..3840dda 100644 --- a/test/request/query.js +++ b/test/request/query.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.query', function(){ describe('when missing', function(){ diff --git a/test/request/querystring.js b/test/request/querystring.js index c78f44b..d1bfc3c 100644 --- a/test/request/querystring.js +++ b/test/request/querystring.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.querystring', function(){ it('should return the querystring', function(){ diff --git a/test/request/search.js b/test/request/search.js index 9a428c6..2a744e7 100644 --- a/test/request/search.js +++ b/test/request/search.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.search=', function(){ it('should replace the search', function(){ diff --git a/test/request/secure.js b/test/request/secure.js index dc8e337..d3bc7b2 100644 --- a/test/request/secure.js +++ b/test/request/secure.js @@ -1,7 +1,7 @@ 'use strict'; -const request = require('../context').request; +const request = require('../helpers/context').request; describe('req.secure', function(){ it('should return true when encrypted', function(){ diff --git a/test/request/stale.js b/test/request/stale.js index 6bbd0f3..d729193 100644 --- a/test/request/stale.js +++ b/test/request/stale.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); describe('req.stale', function(){ it('should be the inverse of req.fresh', function(){ diff --git a/test/request/subdomains.js b/test/request/subdomains.js index be9659e..9d2ccaa 100644 --- a/test/request/subdomains.js +++ b/test/request/subdomains.js @@ -1,7 +1,7 @@ 'use strict'; -const request = require('../context').request; +const request = require('../helpers/context').request; describe('req.subdomains', function(){ it('should return subdomain array', function(){ diff --git a/test/request/type.js b/test/request/type.js index 7b3b222..9447b50 100644 --- a/test/request/type.js +++ b/test/request/type.js @@ -1,7 +1,7 @@ 'use strict'; -const request = require('../context').request; +const request = require('../helpers/context').request; const assert = require('assert'); describe('req.type', function(){ diff --git a/test/response/append.js b/test/response/append.js index f1188c1..3dc2246 100644 --- a/test/response/append.js +++ b/test/response/append.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.append(name, val)', function(){ it('should append multiple headers', function(){ diff --git a/test/response/attachment.js b/test/response/attachment.js index 37a7152..fee4607 100644 --- a/test/response/attachment.js +++ b/test/response/attachment.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); const request = require('supertest'); const koa = require('../..'); diff --git a/test/response/body.js b/test/response/body.js index a1d6171..5ad1e11 100644 --- a/test/response/body.js +++ b/test/response/body.js @@ -1,7 +1,7 @@ 'use strict'; -const response = require('../context').response; +const response = require('../helpers/context').response; const assert = require('assert'); const fs = require('fs'); diff --git a/test/response/etag.js b/test/response/etag.js index 51a91fd..e830d4e 100644 --- a/test/response/etag.js +++ b/test/response/etag.js @@ -1,7 +1,7 @@ 'use strict'; -const response = require('../context').response; +const response = require('../helpers/context').response; describe('res.etag=', function(){ it('should not modify an etag with quotes', function(){ diff --git a/test/response/header.js b/test/response/header.js index 04afe3b..5a20ae4 100644 --- a/test/response/header.js +++ b/test/response/header.js @@ -1,7 +1,7 @@ 'use strict'; -const response = require('../context').response; +const response = require('../helpers/context').response; describe('res.header', function(){ it('should return the response header object', function(){ diff --git a/test/response/headers.js b/test/response/headers.js index 409655a..3a3ba50 100644 --- a/test/response/headers.js +++ b/test/response/headers.js @@ -1,7 +1,7 @@ 'use strict'; -const response = require('../context').response; +const response = require('../helpers/context').response; describe('res.header', function(){ it('should return the response header object', function(){ diff --git a/test/response/inspect.js b/test/response/inspect.js index 088c3b5..1b23cd1 100644 --- a/test/response/inspect.js +++ b/test/response/inspect.js @@ -1,7 +1,7 @@ 'use strict'; -const response = require('../context').response; +const response = require('../helpers/context').response; const assert = require('assert'); describe('res.inspect()', function(){ diff --git a/test/response/is.js b/test/response/is.js index 52de6b1..e0e4db2 100644 --- a/test/response/is.js +++ b/test/response/is.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); const should = require('should'); const assert = require('assert'); diff --git a/test/response/last-modified.js b/test/response/last-modified.js index f2143cf..8a75cf1 100644 --- a/test/response/last-modified.js +++ b/test/response/last-modified.js @@ -1,7 +1,7 @@ 'use strict'; -const response = require('../context').response; +const response = require('../helpers/context').response; describe('res.lastModified', function(){ it('should set the header as a UTCString', function(){ diff --git a/test/response/length.js b/test/response/length.js index c936aff..ead4d22 100644 --- a/test/response/length.js +++ b/test/response/length.js @@ -1,7 +1,7 @@ 'use strict'; -const response = require('../context').response; +const response = require('../helpers/context').response; const should = require('should'); const assert = require('assert'); const fs = require('fs'); diff --git a/test/response/message.js b/test/response/message.js index fdbea1d..778f41a 100644 --- a/test/response/message.js +++ b/test/response/message.js @@ -1,7 +1,7 @@ 'use strict'; -const response = require('../context').response; +const response = require('../helpers/context').response; const Stream = require('stream'); describe('res.message', function(){ diff --git a/test/response/redirect.js b/test/response/redirect.js index 68ed47b..8e79283 100644 --- a/test/response/redirect.js +++ b/test/response/redirect.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.redirect(url)', function(){ it('should redirect to the given url', function(){ diff --git a/test/response/remove.js b/test/response/remove.js index 9f0d37a..0c84526 100644 --- a/test/response/remove.js +++ b/test/response/remove.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.remove(name)', function(){ it('should remove a field', function(){ diff --git a/test/response/set.js b/test/response/set.js index 825a38f..b0443f6 100644 --- a/test/response/set.js +++ b/test/response/set.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.set(name, val)', function(){ it('should set a field value', function(){ diff --git a/test/response/socket.js b/test/response/socket.js index e7b33d3..ff02f2b 100644 --- a/test/response/socket.js +++ b/test/response/socket.js @@ -1,7 +1,7 @@ 'use strict'; -const response = require('../context').response; +const response = require('../helpers/context').response; const Stream = require('stream'); describe('res.socket', function(){ diff --git a/test/response/status.js b/test/response/status.js index 1401375..50dff8b 100644 --- a/test/response/status.js +++ b/test/response/status.js @@ -1,7 +1,7 @@ 'use strict'; -const response = require('../context').response; +const response = require('../helpers/context').response; const request = require('supertest'); const statuses = require('statuses'); const assert = require('assert'); diff --git a/test/response/type.js b/test/response/type.js index e3918b3..37c3fe3 100644 --- a/test/response/type.js +++ b/test/response/type.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); const assert = require('assert'); describe('ctx.type=', function(){ diff --git a/test/response/vary.js b/test/response/vary.js index aeac110..e4dddcc 100644 --- a/test/response/vary.js +++ b/test/response/vary.js @@ -1,7 +1,7 @@ 'use strict'; -const context = require('../context'); +const context = require('../helpers/context'); describe('ctx.vary(field)', function(){ describe('when Vary is not set', function(){ diff --git a/test/response/writeable.js b/test/response/writeable.js index e6a8443..c925d9d 100644 --- a/test/response/writeable.js +++ b/test/response/writeable.js @@ -1,7 +1,7 @@ 'use strict'; -const response = require('../context').response; +const response = require('../helpers/context').response; describe('res.writable', function(){ it('should return the request is writable', function(){