Skip to content
Myr

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 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–5why, one step back
2
3var after = require('after');4var express = require('../')5 , Router = express.Router

chore: replace `methods` dependency with standard library (#6196)Jon Koopsbefore adoptionb11122b

line 6why, one step back
6 , methods = require('../lib/utils').methods

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 7why, one step back
7 , assert = require('node:assert');

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 8why, one step back
8

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

lines 9–10why, one step back
9describe('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 back
11 var router = new Router();

Merge tag '4.16.4'Douglas Christopher Wilsonbefore adoption302a615

line 12why, one step back
12 assert(typeof router === 'function')

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 13why, one step back
13

Merge tag '4.16.4'Douglas Christopher Wilsonbefore adoption302a615

lines 14–16why, one step back
14 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 back
17 });
18

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 19why, one step back
19 it('should support .use of other routers', function (done) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 20–22why, one step back
20 var router = new Router();
21 var another = new Router();22

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 23why, one step back
23 another.get('/bar', function (req, res) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 24–27why, one step back
24 res.end();
25 });26 router.use('/foo', another);27

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 28why, one step back
28 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 back
29 });
30

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 31why, one step back
31 it('should support dynamic routes', function (done) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 32–34why, one step back
32 var router = new Router();
33 var another = new Router();34

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 35why, one step back
35 another.get('/:bar', function (req, res) {

Merge tag '4.17.2'Douglas Christopher Wilsonbefore adoptionc7d528c

line 36why, one step back
36 assert.strictEqual(req.params.bar, 'route')

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 37–40why, one step back
37 res.end();
38 });39 router.use('/:foo', another);40

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 41why, one step back
41 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 back
42 });
43

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 44why, one step back
44 it('should handle blank URL', function (done) {

Fix handling of invalid empty URLsDouglas Christopher Wilsonbefore adoption68290ee

lines 45–47why, one step back
45 var router = new Router();
4647 router.use(function (req, res) {

Merge tag '4.17.2'Douglas Christopher Wilsonbefore adoptionc7d528c

line 48why, one step back
48 throw new Error('should not be called')

Fix handling of invalid empty URLsDouglas Christopher Wilsonbefore adoption68290ee

lines 49–53why, one step back
49 });
5051 router.handle({ url: '', method: 'GET' }, {}, done);52 });53

Merge tag '4.15.0'Douglas Christopher Wilsonbefore adoption501e24e

lines 54–63why, one step back
54 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 })63

Merge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae

lines 64–90why, one step back
64 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 })90

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 91why, one step back
91 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 back
92 this.timeout(5000) // long-running test
93

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 94why, one step back
94 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 back
95 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 });104

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 105why, one step back
105 router.handle({ url: '/', method: 'GET' }, { end: done }, function () { });

Merge tag '4.11.1'Douglas Christopher Wilsonbefore adoption8a5ecd3

lines 106–107why, one step back
106 });
107

Merge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae

lines 108–161why, one step back
108 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 })161

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

lines 162–163why, one step back
162 describe('.handle', function () {
163 it('should dispatch', function (done) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 164–165why, one step back
164 var router = new Router();
165

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 166why, one step back
166 router.route('/foo').get(function (req, res) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 167–170why, one step back
167 res.send('foo');
168 });169170 var res = {

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 171why, one step back
171 send: function (val) {

Merge tag '4.17.2'Douglas Christopher Wilsonbefore adoptionc7d528c

line 172why, one step back
172 assert.strictEqual(val, 'foo')

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 173–175why, one step back
173 done();
174 }175 }

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 176why, one step back
176 router.handle({ url: '/foo', method: 'GET' }, res, function () { });

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 177–179why, one step back
177 })
178 })179

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

lines 180–181why, one step back
180 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 back
182 assert.throws(function () {
183 var router = new Router();184 router.route('/foo').all(null);185 })186 })187

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 188why, one step back
188 it('should throw if a callback is undefined', function () {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 189–194why, one step back
189 assert.throws(function () {
190 var router = new Router();191 router.route('/foo').all(undefined);192 })193 })194

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 195why, one step back
195 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 back
196 assert.throws(function () {
197 var router = new Router();198 router.route('/foo').all('not a function');199 })200 })201

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 202why, one step back
202 it('should not throw if all callbacks are functions', function () {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

line 203why, one step back
203 var router = new Router();

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 204why, one step back
204 router.route('/foo').all(function () { }).all(function () { });

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 205–207why, one step back
205 })
206 })207

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

lines 208–209why, one step back
208 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 back
210 var router = new Router();
211

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 212why, one step back
212 router.get('/foo', function (req, res, next) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 213–215why, one step back
213 next(new Error('foo'));
214 });215

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 216why, one step back
216 router.get('/bar', function (req, res, next) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 217–219why, one step back
217 next(new Error('bar'));
218 });219

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 220why, one step back
220 router.use(function (req, res, next) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 221–223why, one step back
221 assert(false);
222 });223

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 224why, one step back
224 router.use(function (err, req, res, next) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 225–231why, one step back
225 assert.equal(err.message, 'foo');
226 done();227 });228229 router.handle({ url: '/foo', method: 'GET' }, {}, done);230 });231

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 232why, one step back
232 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 back
233 var router = new Router();
234

Merge tag '4.19.0' into 5.xWes Toddbefore adoptione9f9aae

line 235why, one step back
235 router.get('/foo/:id', function () {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 236–238why, one step back
236 throw new Error('foo');
237 });238

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 239why, one step back
239 router.use(function (req, res, next) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 240–242why, one step back
240 assert(false);
241 });242

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 243why, one step back
243 router.use(function (err, req, res, next) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 244–247why, one step back
244 assert.equal(err.message, 'foo');
245 done();246 });247

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 248why, one step back
248 router.handle({ url: '/foo/2', method: 'GET' }, {}, function () { });

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 249–250why, one step back
249 });
250

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 251why, one step back
251 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 back
252 var router = new Router();
253

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

lines 254–255why, one step back
254 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 back
256 req.user = val;
257 next();258 });259 });260

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 261why, one step back
261 router.use('/:user', function (req, res, next) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 262–264why, one step back
262 throw new Error('oh no!');
263 });264

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 265why, one step back
265 router.use(function (err, req, res, next) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 266–269why, one step back
266 assert.equal(err.message, 'oh no!');
267 done();268 });269

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 270why, one step back
270 router.handle({ url: '/bob', method: 'GET' }, {}, function () { });

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 271–272why, one step back
271 });
272

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 273why, one step back
273 it('should handle throwing inside error handlers', function (done) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 274–275why, one step back
274 var router = new Router();
275

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 276why, one step back
276 router.use(function (req, res, next) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 277–279why, one step back
277 throw new Error('boom!');
278 });279

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 280why, one step back
280 router.use(function (err, req, res, next) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 281–283why, one step back
281 throw new Error('oops');
282 });283

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 284why, one step back
284 router.use(function (err, req, res, next) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 285–327why, one step back
285 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 });327

Fix handling of URLs containing :// in the pathAria Stewartbefore adoptioneabd456

lines 328–344why, one step back
328 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 });344

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 345–414why, one step back
345 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 })414

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

lines 415–416why, one step back
415 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 back
417 var router = new Router();
418419 var count = 0;

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 420why, one step back
420 router.all('/foo', function () { count++; });

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 421–424why, one step back
421
422 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 back
425 router.handle({ url: url, method: method }, {}, function () { });

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 426–432why, one step back
426 });
427428 assert.equal(count, methods.length);429 done();430 })431 })432

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 433why, one step back
433 describe('.use', function () {

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

lines 434–436why, one step back
434 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 back
437 })
438

Merge tag '4.16.2'Douglas Christopher Wilsonbefore adoption62e12fe

lines 439–456why, one step back
439 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 back
457 })
458459 it('should be called for any URL', function (done) {460 var cb = after(4, done)461 var router = new Router()462

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 463why, one step back
463 function no() {

Merge tag '4.15.0'Douglas Christopher Wilsonbefore adoption501e24e

lines 464–474why, one step back
464 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 back
475 })

Fix router.use to accept array of middleware without pathDouglas Christopher Wilsonbefore adoption7289171

line 476why, one step back
476

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 477why, one step back
477 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 back
478 var count = 0;
479 var router = new Router();480

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 481why, one step back
481 function fn1(req, res, next) {

Fix router.use to accept array of middleware without pathDouglas Christopher Wilsonbefore adoption7289171

lines 482–485why, one step back
482 assert.equal(++count, 1);
483 next();484 }485

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 486why, one step back
486 function fn2(req, res, next) {

Fix router.use to accept array of middleware without pathDouglas Christopher Wilsonbefore adoption7289171

lines 487–490why, one step back
487 assert.equal(++count, 2);
488 next();489 }490

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 491why, one step back
491 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 back
492 assert.equal(++count, 3);
493 done();494 });495

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 496why, one step back
496 router.handle({ url: '/foo', method: 'GET' }, {}, function () { });

Fix router.use to accept array of middleware without pathDouglas Christopher Wilsonbefore adoption7289171

line 497why, one step back
497 })

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 498–499why, one step back
498 })
499

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 500why, one step back
500 describe('.param', function () {

Remove app.param(fn) signatureDouglas Christopher Wilsonbefore adoption1e2951a

lines 501–510why, one step back
501 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 });510

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 511why, one step back
511 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 back
512 var router = new Router();
513

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 514why, one step back
514 router.param('id', function (req, res, next, id) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 515–518why, one step back
515 assert.equal(id, '123');
516 next();517 });518

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 519why, one step back
519 router.get('/foo/:id/bar', function (req, res, next) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 520–526why, one step back
520 assert.equal(req.params.id, '123');
521 next();522 });523524 router.handle({ url: '/foo/123/bar', method: 'get' }, {}, done);525 });526

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 527why, one step back
527 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 back
528 var router = new Router();
529

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 530why, one step back
530 router.param('id', function (req, res, next, id) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 531–534why, one step back
531 assert.equal(id, '123');
532 next();533 });534

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 535why, one step back
535 router.use('/foo/:id/bar', function (req, res, next) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 536–543why, one step back
536 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 });543

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 544why, one step back
544 it('should only call once per request', function (done) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 545–549why, one step back
545 var count = 0;
546 var req = { url: '/foo/bob/bar', method: 'get' };547 var router = new Router();548 var sub = new Router();549

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 550why, one step back
550 sub.get('/bar', function (req, res, next) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 551–553why, one step back
551 next();
552 });553

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 554why, one step back
554 router.param('user', function (req, res, next, user) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 555–562why, one step back
555 count++;
556 req.user = user;557 next();558 });559560 router.use('/foo/:user/', new Router());561 router.use('/foo/:user/', sub);562

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 563why, one step back
563 router.handle(req, {}, function (err) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 564–570why, one step back
564 if (err) return done(err);
565 assert.equal(count, 1);566 assert.equal(req.user, 'bob');567 done();568 });569 });570

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 571why, one step back
571 it('should call when values differ', function (done) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 572–576why, one step back
572 var count = 0;
573 var req = { url: '/foo/bob/bar', method: 'get' };574 var router = new Router();575 var sub = new Router();576

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 577why, one step back
577 sub.get('/bar', function (req, res, next) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 578–580why, one step back
578 next();
579 });580

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 581why, one step back
581 router.param('user', function (req, res, next, user) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 582–589why, one step back
582 count++;
583 req.user = user;584 next();585 });586587 router.use('/foo/:user/', new Router());588 router.use('/:user/bob/', sub);589

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 590why, one step back
590 router.handle(req, {}, function (err) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 591–598why, one step back
591 if (err) return done(err);
592 assert.equal(count, 2);593 assert.equal(req.user, 'foo');594 done();595 });596 });597 });598

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

lines 599–600why, one step back
599 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 back
601 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 back
605 var cb = after(2, done)

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 606–607why, one step back
606
607

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 608why, one step back
608 sub.get('/bar', function (req, res, next) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 609–611why, one step back
609 next();
610 });611

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 612why, one step back
612 router.param('ms', function (req, res, next, ms) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 613–620why, one step back
613 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);620

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 621why, one step back
621 router.handle(req1, {}, function (err) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 622–624why, one step back
622 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 back
625 cb()

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 626–627why, one step back
626 });
627

fix(refactor): prefix built-in node module importsSzymon Łągiewkabefore adoption4111359

line 628why, one step back
628 router.handle(req2, {}, function (err) {

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 629–631why, one step back
629 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 back
632 cb()

Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a

lines 633–636why, one step back
633 });
634 });635 });636})