Skip to content
Myr

app.request.js

This file

Path

test/app.request.js

143 lines · 2.9 KiB · JavaScript

Last changed by

tests: use strict modeDouglas Christopher Wilsonbefore adoptiona659137

History of this file

Take it

The walk stopped after 200 commits: lines older than 76bf96e point at it.

tests: use strict modeDouglas Christopher Wilsonbefore adoptiona659137

line 1why, one step back
1'use strict'

deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e

line 2why, one step back
2

tests: add more tests for app.request & app.responseDouglas Christopher Wilsonbefore adoption00ad5be

line 3why, one step back
3var after = require('after')

deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e

lines 4–22why, one step back
4var express = require('../')
5 , request = require('supertest');67describe('app', function(){8 describe('.request', function(){9 it('should extend the request prototype', function(done){10 var app = express();1112 app.request.querystring = function(){13 return require('url').parse(this.url).query;14 };1516 app.use(function(req, res){17 res.end(req.querystring());18 });1920 request(app)21 .get('/foo?name=tobi')22 .expect('name=tobi', done);

tests: add more tests for app.request & app.responseDouglas Christopher Wilsonbefore adoption00ad5be

lines 23–140why, one step back
23 })
2425 it('should only extend for the referenced app', function (done) {26 var app1 = express()27 var app2 = express()28 var cb = after(2, done)2930 app1.request.foobar = function () {31 return 'tobi'32 }3334 app1.get('/', function (req, res) {35 res.send(req.foobar())36 })3738 app2.get('/', function (req, res) {39 res.send(req.foobar())40 })4142 request(app1)43 .get('/')44 .expect(200, 'tobi', cb)4546 request(app2)47 .get('/')48 .expect(500, /(?:not a function|has no method)/, cb)49 })5051 it('should inherit to sub apps', function (done) {52 var app1 = express()53 var app2 = express()54 var cb = after(2, done)5556 app1.request.foobar = function () {57 return 'tobi'58 }5960 app1.use('/sub', app2)6162 app1.get('/', function (req, res) {63 res.send(req.foobar())64 })6566 app2.get('/', function (req, res) {67 res.send(req.foobar())68 })6970 request(app1)71 .get('/')72 .expect(200, 'tobi', cb)7374 request(app1)75 .get('/sub')76 .expect(200, 'tobi', cb)77 })7879 it('should allow sub app to override', function (done) {80 var app1 = express()81 var app2 = express()82 var cb = after(2, done)8384 app1.request.foobar = function () {85 return 'tobi'86 }8788 app2.request.foobar = function () {89 return 'loki'90 }9192 app1.use('/sub', app2)9394 app1.get('/', function (req, res) {95 res.send(req.foobar())96 })9798 app2.get('/', function (req, res) {99 res.send(req.foobar())100 })101102 request(app1)103 .get('/')104 .expect(200, 'tobi', cb)105106 request(app1)107 .get('/sub')108 .expect(200, 'loki', cb)109 })110111 it('should not pollute parent app', function (done) {112 var app1 = express()113 var app2 = express()114 var cb = after(2, done)115116 app1.request.foobar = function () {117 return 'tobi'118 }119120 app2.request.foobar = function () {121 return 'loki'122 }123124 app1.use('/sub', app2)125126 app1.get('/sub/foo', function (req, res) {127 res.send(req.foobar())128 })129130 app2.get('/', function (req, res) {131 res.send(req.foobar())132 })133134 request(app1)135 .get('/sub')136 .expect(200, 'loki', cb)137138 request(app1)139 .get('/sub/foo')140 .expect(200, 'tobi', cb)

deps: finalhandler@1.1.1Douglas Christopher Wilsonbefore adoption76bf96e

lines 141–143why, one step back
141 })
142 })143})