Skip to content
Myr

req.baseUrl.js

This file

Path

test/req.baseUrl.js

88 lines · 2.1 KiB · JavaScript

Last changed by

Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b

History of this file

Take it

The walk stopped after 200 commits: lines older than 2a0c35a point at it.

Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b

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

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 2–88why, one step back
2
3var express = require('..')4var request = require('supertest')56describe('req', function(){7 describe('.baseUrl', function(){8 it('should be empty for top-level route', function(done){9 var app = express()1011 app.get('/:a', function(req, res){12 res.end(req.baseUrl)13 })1415 request(app)16 .get('/foo')17 .expect(200, '', done)18 })1920 it('should contain lower path', function(done){21 var app = express()22 var sub = express.Router()2324 sub.get('/:b', function(req, res){25 res.end(req.baseUrl)26 })27 app.use('/:a', sub)2829 request(app)30 .get('/foo/bar')31 .expect(200, '/foo', done);32 })3334 it('should contain full lower path', function(done){35 var app = express()36 var sub1 = express.Router()37 var sub2 = express.Router()38 var sub3 = express.Router()3940 sub3.get('/:d', function(req, res){41 res.end(req.baseUrl)42 })43 sub2.use('/:c', sub3)44 sub1.use('/:b', sub2)45 app.use('/:a', sub1)4647 request(app)48 .get('/foo/bar/baz/zed')49 .expect(200, '/foo/bar/baz', done);50 })5152 it('should travel through routers correctly', function(done){53 var urls = []54 var app = express()55 var sub1 = express.Router()56 var sub2 = express.Router()57 var sub3 = express.Router()5859 sub3.get('/:d', function(req, res, next){60 urls.push('0@' + req.baseUrl)61 next()62 })63 sub2.use('/:c', sub3)64 sub1.use('/', function(req, res, next){65 urls.push('1@' + req.baseUrl)66 next()67 })68 sub1.use('/bar', sub2)69 sub1.use('/bar', function(req, res, next){70 urls.push('2@' + req.baseUrl)71 next()72 })73 app.use(function(req, res, next){74 urls.push('3@' + req.baseUrl)75 next()76 })77 app.use('/:a', sub1)78 app.use(function(req, res, next){79 urls.push('4@' + req.baseUrl)80 res.end(urls.join(','))81 })8283 request(app)84 .get('/foo/bar/baz/zed')85 .expect(200, '3@,1@/foo,0@/foo/bar/baz,2@/foo/bar,4@', done);86 })87 })88})