Router.js
This file
Path
test/Router.js
636 lines · 17.0 KiB · JavaScript
Last changed by
fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
History of this fileTake 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 back1'use strict'Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 2–5why, one step back23var after = require('after');4var express = require('../')5 , Router = express.Routerchore: replace `methods` dependency with standard library (#6196)Jon Koopsbefore adoptionb11122b
line 6why, one step back6 , methods = require('../lib/utils').methodsfix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 7why, one step back7 , assert = require('node:assert');Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
line 8why, one step back8fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
lines 9–10why, one step back9describe('Router', function () {10 it('should return a function with router methods', function () {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
line 11why, one step back11 var router = new Router();Merge tag '4.16.4'Douglas Christopher Wilsonbefore adoption302a615
line 12why, one step back12 assert(typeof router === 'function')Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
line 13why, one step back13Merge tag '4.16.4'Douglas Christopher Wilsonbefore adoption302a615
lines 14–16why, one step back14 assert(typeof router.get === 'function')15 assert(typeof router.handle === 'function')16 assert(typeof router.use === 'function')Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 17–18why, one step back17 });18fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 19why, one step back19 it('should support .use of other routers', function (done) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 20–22why, one step back20 var router = new Router();21 var another = new Router();22fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 23why, one step back23 another.get('/bar', function (req, res) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 24–27why, one step back24 res.end();25 });26 router.use('/foo', another);27fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 28why, one step back28 router.handle({ url: '/foo/bar', method: 'GET' }, { end: done }, function () { });Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 29–30why, one step back29 });30fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 31why, one step back31 it('should support dynamic routes', function (done) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 32–34why, one step back32 var router = new Router();33 var another = new Router();34fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 35why, one step back35 another.get('/:bar', function (req, res) {Merge tag '4.17.2'Douglas Christopher Wilsonbefore adoptionc7d528c
line 36why, one step back36 assert.strictEqual(req.params.bar, 'route')Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 37–40why, one step back37 res.end();38 });39 router.use('/:foo', another);40fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 41why, one step back41 router.handle({ url: '/test/route', method: 'GET' }, { end: done }, function () { });Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 42–43why, one step back42 });43fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 44why, one step back44 it('should handle blank URL', function (done) {Fix handling of invalid empty URLsDouglas Christopher Wilsonbefore adoption68290ee
lines 45–47why, one step back45 var router = new Router();4647 router.use(function (req, res) {Merge tag '4.17.2'Douglas Christopher Wilsonbefore adoptionc7d528c
line 48why, one step back48 throw new Error('should not be called')Fix handling of invalid empty URLsDouglas Christopher Wilsonbefore adoption68290ee
lines 49–53why, one step back49 });5051 router.handle({ url: '', method: 'GET' }, {}, done);52 });53Merge tag '4.15.0'Douglas Christopher Wilsonbefore adoption501e24e
lines 54–63why, one step back54 it('should handle missing URL', function (done) {55 var router = new Router()5657 router.use(function (req, res) {58 throw new Error('should not be called')59 })6061 router.handle({ method: 'GET' }, {}, done)62 })63Merge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae
lines 64–90why, one step back64 it('handle missing method', function (done) {65 var all = false66 var router = new Router()67 var route = router.route('/foo')68 var use = false6970 route.post(function (req, res, next) { next(new Error('should not run')) })71 route.all(function (req, res, next) {72 all = true73 next()74 })75 route.get(function (req, res, next) { next(new Error('should not run')) })7677 router.get('/foo', function (req, res, next) { next(new Error('should not run')) })78 router.use(function (req, res, next) {79 use = true80 next()81 })8283 router.handle({ url: '/foo' }, {}, function (err) {84 if (err) return done(err)85 assert.ok(all)86 assert.ok(use)87 done()88 })89 })90fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 91why, one step back91 it('should not stack overflow with many registered routes', function (done) {Merge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae
lines 92–93why, one step back92 this.timeout(5000) // long-running test93fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 94why, one step back94 var handler = function (req, res) { res.end(new Error('wrong handler')) };Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3
lines 95–104why, one step back95 var router = new Router();9697 for (var i = 0; i < 6000; i++) {98 router.get('/thing' + i, handler)99 }100101 router.get('/', function (req, res) {102 res.end();103 });104fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 105why, one step back105 router.handle({ url: '/', method: 'GET' }, { end: done }, function () { });Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3
lines 106–107why, one step back106 });107Merge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae
lines 108–161why, one step back108 it('should not stack overflow with a large sync route stack', function (done) {109 this.timeout(5000) // long-running test110111 var router = new Router()112113 router.get('/foo', function (req, res, next) {114 req.counter = 0115 next()116 })117118 for (var i = 0; i < 6000; i++) {119 router.get('/foo', function (req, res, next) {120 req.counter++121 next()122 })123 }124125 router.get('/foo', function (req, res) {126 assert.strictEqual(req.counter, 6000)127 res.end()128 })129130 router.handle({ url: '/foo', method: 'GET' }, { end: done }, function (err) {131 assert(!err, err);132 });133 })134135 it('should not stack overflow with a large sync middleware stack', function (done) {136 this.timeout(5000) // long-running test137138 var router = new Router()139140 router.use(function (req, res, next) {141 req.counter = 0142 next()143 })144145 for (var i = 0; i < 6000; i++) {146 router.use(function (req, res, next) {147 req.counter++148 next()149 })150 }151152 router.use(function (req, res) {153 assert.strictEqual(req.counter, 6000)154 res.end()155 })156157 router.handle({ url: '/', method: 'GET' }, { end: done }, function (err) {158 assert(!err, err);159 })160 })161fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
lines 162–163why, one step back162 describe('.handle', function () {163 it('should dispatch', function (done) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 164–165why, one step back164 var router = new Router();165fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 166why, one step back166 router.route('/foo').get(function (req, res) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 167–170why, one step back167 res.send('foo');168 });169170 var res = {fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 171why, one step back171 send: function (val) {Merge tag '4.17.2'Douglas Christopher Wilsonbefore adoptionc7d528c
line 172why, one step back172 assert.strictEqual(val, 'foo')Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 173–175why, one step back173 done();174 }175 }fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 176why, one step back176 router.handle({ url: '/foo', method: 'GET' }, res, function () { });Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 177–179why, one step back177 })178 })179fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
lines 180–181why, one step back180 describe('.multiple callbacks', function () {181 it('should throw if a callback is null', function () {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 182–187why, one step back182 assert.throws(function () {183 var router = new Router();184 router.route('/foo').all(null);185 })186 })187fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 188why, one step back188 it('should throw if a callback is undefined', function () {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 189–194why, one step back189 assert.throws(function () {190 var router = new Router();191 router.route('/foo').all(undefined);192 })193 })194fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 195why, one step back195 it('should throw if a callback is not a function', function () {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 196–201why, one step back196 assert.throws(function () {197 var router = new Router();198 router.route('/foo').all('not a function');199 })200 })201fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 202why, one step back202 it('should not throw if all callbacks are functions', function () {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
line 203why, one step back203 var router = new Router();fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 204why, one step back204 router.route('/foo').all(function () { }).all(function () { });Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 205–207why, one step back205 })206 })207fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
lines 208–209why, one step back208 describe('error', function () {209 it('should skip non error middleware', function (done) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 210–211why, one step back210 var router = new Router();211fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 212why, one step back212 router.get('/foo', function (req, res, next) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 213–215why, one step back213 next(new Error('foo'));214 });215fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 216why, one step back216 router.get('/bar', function (req, res, next) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 217–219why, one step back217 next(new Error('bar'));218 });219fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 220why, one step back220 router.use(function (req, res, next) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 221–223why, one step back221 assert(false);222 });223fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 224why, one step back224 router.use(function (err, req, res, next) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 225–231why, one step back225 assert.equal(err.message, 'foo');226 done();227 });228229 router.handle({ url: '/foo', method: 'GET' }, {}, done);230 });231fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 232why, one step back232 it('should handle throwing inside routes with params', function (done) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 233–234why, one step back233 var router = new Router();234Merge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae
line 235why, one step back235 router.get('/foo/:id', function () {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 236–238why, one step back236 throw new Error('foo');237 });238fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 239why, one step back239 router.use(function (req, res, next) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 240–242why, one step back240 assert(false);241 });242fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 243why, one step back243 router.use(function (err, req, res, next) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 244–247why, one step back244 assert.equal(err.message, 'foo');245 done();246 });247fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 248why, one step back248 router.handle({ url: '/foo/2', method: 'GET' }, {}, function () { });Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 249–250why, one step back249 });250fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 251why, one step back251 it('should handle throwing in handler after async param', function (done) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 252–253why, one step back252 var router = new Router();253fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
lines 254–255why, one step back254 router.param('user', function (req, res, next, val) {255 process.nextTick(function () {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 256–260why, one step back256 req.user = val;257 next();258 });259 });260fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 261why, one step back261 router.use('/:user', function (req, res, next) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 262–264why, one step back262 throw new Error('oh no!');263 });264fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 265why, one step back265 router.use(function (err, req, res, next) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 266–269why, one step back266 assert.equal(err.message, 'oh no!');267 done();268 });269fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 270why, one step back270 router.handle({ url: '/bob', method: 'GET' }, {}, function () { });Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 271–272why, one step back271 });272fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 273why, one step back273 it('should handle throwing inside error handlers', function (done) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 274–275why, one step back274 var router = new Router();275fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 276why, one step back276 router.use(function (req, res, next) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 277–279why, one step back277 throw new Error('boom!');278 });279fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 280why, one step back280 router.use(function (err, req, res, next) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 281–283why, one step back281 throw new Error('oops');282 });283fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 284why, one step back284 router.use(function (err, req, res, next) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 285–327why, one step back285 assert.equal(err.message, 'oops');286 done();287 });288289 router.handle({ url: '/', method: 'GET' }, {}, done);290 });291 })292293 describe('FQDN', function () {294 it('should not obscure FQDNs', function (done) {295 var request = { hit: 0, url: 'http://example.com/foo', method: 'GET' };296 var router = new Router();297298 router.use(function (req, res, next) {299 assert.equal(req.hit++, 0);300 assert.equal(req.url, 'http://example.com/foo');301 next();302 });303304 router.handle(request, {}, function (err) {305 if (err) return done(err);306 assert.equal(request.hit, 1);307 done();308 });309 });310311 it('should ignore FQDN in search', function (done) {312 var request = { hit: 0, url: '/proxy?url=http://example.com/blog/post/1', method: 'GET' };313 var router = new Router();314315 router.use('/proxy', function (req, res, next) {316 assert.equal(req.hit++, 0);317 assert.equal(req.url, '/?url=http://example.com/blog/post/1');318 next();319 });320321 router.handle(request, {}, function (err) {322 if (err) return done(err);323 assert.equal(request.hit, 1);324 done();325 });326 });327Fix handling of URLs containing :// in the pathAria Stewartbefore adoptioneabd456
lines 328–344why, one step back328 it('should ignore FQDN in path', function (done) {329 var request = { hit: 0, url: '/proxy/http://example.com/blog/post/1', method: 'GET' };330 var router = new Router();331332 router.use('/proxy', function (req, res, next) {333 assert.equal(req.hit++, 0);334 assert.equal(req.url, '/http://example.com/blog/post/1');335 next();336 });337338 router.handle(request, {}, function (err) {339 if (err) return done(err);340 assert.equal(request.hit, 1);341 done();342 });343 });344Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 345–414why, one step back345 it('should adjust FQDN req.url', function (done) {346 var request = { hit: 0, url: 'http://example.com/blog/post/1', method: 'GET' };347 var router = new Router();348349 router.use('/blog', function (req, res, next) {350 assert.equal(req.hit++, 0);351 assert.equal(req.url, 'http://example.com/post/1');352 next();353 });354355 router.handle(request, {}, function (err) {356 if (err) return done(err);357 assert.equal(request.hit, 1);358 done();359 });360 });361362 it('should adjust FQDN req.url with multiple handlers', function (done) {363 var request = { hit: 0, url: 'http://example.com/blog/post/1', method: 'GET' };364 var router = new Router();365366 router.use(function (req, res, next) {367 assert.equal(req.hit++, 0);368 assert.equal(req.url, 'http://example.com/blog/post/1');369 next();370 });371372 router.use('/blog', function (req, res, next) {373 assert.equal(req.hit++, 1);374 assert.equal(req.url, 'http://example.com/post/1');375 next();376 });377378 router.handle(request, {}, function (err) {379 if (err) return done(err);380 assert.equal(request.hit, 2);381 done();382 });383 });384385 it('should adjust FQDN req.url with multiple routed handlers', function (done) {386 var request = { hit: 0, url: 'http://example.com/blog/post/1', method: 'GET' };387 var router = new Router();388389 router.use('/blog', function (req, res, next) {390 assert.equal(req.hit++, 0);391 assert.equal(req.url, 'http://example.com/post/1');392 next();393 });394395 router.use('/blog', function (req, res, next) {396 assert.equal(req.hit++, 1);397 assert.equal(req.url, 'http://example.com/post/1');398 next();399 });400401 router.use(function (req, res, next) {402 assert.equal(req.hit++, 2);403 assert.equal(req.url, 'http://example.com/blog/post/1');404 next();405 });406407 router.handle(request, {}, function (err) {408 if (err) return done(err);409 assert.equal(request.hit, 3);410 done();411 });412 });413 })414fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
lines 415–416why, one step back415 describe('.all', function () {416 it('should support using .all to capture all http verbs', function (done) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 417–419why, one step back417 var router = new Router();418419 var count = 0;fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 420why, one step back420 router.all('/foo', function () { count++; });Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 421–424why, one step back421422 var url = '/foo?bar=baz';423424 methods.forEach(function testMethod(method) {fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 425why, one step back425 router.handle({ url: url, method: method }, {}, function () { });Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 426–432why, one step back426 });427428 assert.equal(count, methods.length);429 done();430 })431 })432fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 433why, one step back433 describe('.use', function () {Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe
lines 434–436why, one step back434 it('should require middleware', function () {435 var router = new Router()436 assert.throws(function () { router.use('/') }, /argument handler is required/)Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 437–438why, one step back437 })438Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe
lines 439–456why, one step back439 it('should reject string as middleware', function () {440 var router = new Router()441 assert.throws(function () { router.use('/', 'foo') }, /argument handler must be a function/)442 })443444 it('should reject number as middleware', function () {445 var router = new Router()446 assert.throws(function () { router.use('/', 42) }, /argument handler must be a function/)447 })448449 it('should reject null as middleware', function () {450 var router = new Router()451 assert.throws(function () { router.use('/', null) }, /argument handler must be a function/)452 })453454 it('should reject Date as middleware', function () {455 var router = new Router()456 assert.throws(function () { router.use('/', new Date()) }, /argument handler must be a function/)Merge tag '4.15.0'Douglas Christopher Wilsonbefore adoption501e24e
lines 457–462why, one step back457 })458459 it('should be called for any URL', function (done) {460 var cb = after(4, done)461 var router = new Router()462fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 463why, one step back463 function no() {Merge tag '4.15.0'Douglas Christopher Wilsonbefore adoption501e24e
lines 464–474why, one step back464 throw new Error('should not be called')465 }466467 router.use(function (req, res) {468 res.end()469 })470471 router.handle({ url: '/', method: 'GET' }, { end: cb }, no)472 router.handle({ url: '/foo', method: 'GET' }, { end: cb }, no)473 router.handle({ url: 'foo', method: 'GET' }, { end: cb }, no)474 router.handle({ url: '*', method: 'GET' }, { end: cb }, no)Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
line 475why, one step back475 })Fix router.use to accept array of middleware without pathDouglas Christopher Wilsonbefore adoption7289171
line 476why, one step back476fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 477why, one step back477 it('should accept array of middleware', function (done) {Fix router.use to accept array of middleware without pathDouglas Christopher Wilsonbefore adoption7289171
lines 478–480why, one step back478 var count = 0;479 var router = new Router();480fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 481why, one step back481 function fn1(req, res, next) {Fix router.use to accept array of middleware without pathDouglas Christopher Wilsonbefore adoption7289171
lines 482–485why, one step back482 assert.equal(++count, 1);483 next();484 }485fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 486why, one step back486 function fn2(req, res, next) {Fix router.use to accept array of middleware without pathDouglas Christopher Wilsonbefore adoption7289171
lines 487–490why, one step back487 assert.equal(++count, 2);488 next();489 }490fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 491why, one step back491 router.use([fn1, fn2], function (req, res) {Fix router.use to accept array of middleware without pathDouglas Christopher Wilsonbefore adoption7289171
lines 492–495why, one step back492 assert.equal(++count, 3);493 done();494 });495fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 496why, one step back496 router.handle({ url: '/foo', method: 'GET' }, {}, function () { });Fix router.use to accept array of middleware without pathDouglas Christopher Wilsonbefore adoption7289171
line 497why, one step back497 })Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 498–499why, one step back498 })499fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 500why, one step back500 describe('.param', function () {Remove app.param(fn) signatureDouglas Christopher Wilsonbefore adoption1e2951a
lines 501–510why, one step back501 it('should require function', function () {502 var router = new Router();503 assert.throws(router.param.bind(router, 'id'), /argument fn is required/);504 });505506 it('should reject non-function', function () {507 var router = new Router();508 assert.throws(router.param.bind(router, 'id', 42), /argument fn must be a function/);509 });510fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 511why, one step back511 it('should call param function when routing VERBS', function (done) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 512–513why, one step back512 var router = new Router();513fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 514why, one step back514 router.param('id', function (req, res, next, id) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 515–518why, one step back515 assert.equal(id, '123');516 next();517 });518fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 519why, one step back519 router.get('/foo/:id/bar', function (req, res, next) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 520–526why, one step back520 assert.equal(req.params.id, '123');521 next();522 });523524 router.handle({ url: '/foo/123/bar', method: 'get' }, {}, done);525 });526fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 527why, one step back527 it('should call param function when routing middleware', function (done) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 528–529why, one step back528 var router = new Router();529fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 530why, one step back530 router.param('id', function (req, res, next, id) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 531–534why, one step back531 assert.equal(id, '123');532 next();533 });534fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 535why, one step back535 router.use('/foo/:id/bar', function (req, res, next) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 536–543why, one step back536 assert.equal(req.params.id, '123');537 assert.equal(req.url, '/baz');538 next();539 });540541 router.handle({ url: '/foo/123/bar/baz', method: 'get' }, {}, done);542 });543fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 544why, one step back544 it('should only call once per request', function (done) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 545–549why, one step back545 var count = 0;546 var req = { url: '/foo/bob/bar', method: 'get' };547 var router = new Router();548 var sub = new Router();549fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 550why, one step back550 sub.get('/bar', function (req, res, next) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 551–553why, one step back551 next();552 });553fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 554why, one step back554 router.param('user', function (req, res, next, user) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 555–562why, one step back555 count++;556 req.user = user;557 next();558 });559560 router.use('/foo/:user/', new Router());561 router.use('/foo/:user/', sub);562fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 563why, one step back563 router.handle(req, {}, function (err) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 564–570why, one step back564 if (err) return done(err);565 assert.equal(count, 1);566 assert.equal(req.user, 'bob');567 done();568 });569 });570fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 571why, one step back571 it('should call when values differ', function (done) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 572–576why, one step back572 var count = 0;573 var req = { url: '/foo/bob/bar', method: 'get' };574 var router = new Router();575 var sub = new Router();576fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 577why, one step back577 sub.get('/bar', function (req, res, next) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 578–580why, one step back578 next();579 });580fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 581why, one step back581 router.param('user', function (req, res, next, user) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 582–589why, one step back582 count++;583 req.user = user;584 next();585 });586587 router.use('/foo/:user/', new Router());588 router.use('/:user/bob/', sub);589fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 590why, one step back590 router.handle(req, {}, function (err) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 591–598why, one step back591 if (err) return done(err);592 assert.equal(count, 2);593 assert.equal(req.user, 'foo');594 done();595 });596 });597 });598fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
lines 599–600why, one step back599 describe('parallel requests', function () {600 it('should not mix requests', function (done) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 601–604why, one step back601 var req1 = { url: '/foo/50/bar', method: 'get' };602 var req2 = { url: '/foo/10/bar', method: 'get' };603 var router = new Router();604 var sub = new Router();Merge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae
line 605why, one step back605 var cb = after(2, done)Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 606–607why, one step back606607fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 608why, one step back608 sub.get('/bar', function (req, res, next) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 609–611why, one step back609 next();610 });611fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 612why, one step back612 router.param('ms', function (req, res, next, ms) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 613–620why, one step back613 ms = parseInt(ms, 10);614 req.ms = ms;615 setTimeout(next, ms);616 });617618 router.use('/foo/:ms/', new Router());619 router.use('/foo/:ms/', sub);620fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 621why, one step back621 router.handle(req1, {}, function (err) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 622–624why, one step back622 assert.ifError(err);623 assert.equal(req1.ms, 50);624 assert.equal(req1.originalUrl, '/foo/50/bar');Merge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae
line 625why, one step back625 cb()Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 626–627why, one step back626 });627fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359
line 628why, one step back628 router.handle(req2, {}, function (err) {Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 629–631why, one step back629 assert.ifError(err);630 assert.equal(req2.ms, 10);631 assert.equal(req2.originalUrl, '/foo/10/bar');Merge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae
line 632why, one step back632 cb()Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 633–636why, one step back633 });634 });635 });636})