Skip to content
Myr

Route.js

This file

Path

test/Route.js

238 lines · 5.5 KiB · JavaScript

Last changed by

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

History of this file

Take it

The walk stopped after 200 commits: lines older than 269dc53 point at it.

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

line 1why, one step back
1

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

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

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 3–12why, one step back
3var should = require('should');
4var express = require('../')5 , Route = express.Route6 , methods = require('methods')7 , assert = require('assert');89describe('Route', function(){1011 describe('.all', function(){12 it('should add handler', function(done){

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 13why, one step back
13 var req = { method: 'GET', url: '/' };

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 14–16why, one step back
14 var route = new Route('/foo');
1516 route.all(function(req, res, next) {

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 17why, one step back
17 req.called = true;

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 18–20why, one step back
18 next();
19 });20

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

lines 21–25why, one step back
21 route.dispatch(req, {}, function (err) {
22 if (err) return done(err);23 should(req.called).be.ok;24 done();25 });

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 26–28why, one step back
26 })
2728 it('should handle VERBS', function(done) {

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 29why, one step back
29 var count = 0;

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

line 30why, one step back
30 var route = new Route('/foo');

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

lines 31–35why, one step back
31 var cb = after(methods.length, function (err) {
32 if (err) return done(err);33 count.should.equal(methods.length);34 done();35 });

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 36–38why, one step back
36
37 route.all(function(req, res, next) {38 count++;

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 39why, one step back
39 next();

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 40–42why, one step back
40 });
4142 methods.forEach(function testMethod(method) {

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

lines 43–44why, one step back
43 var req = { method: method, url: '/' };
44 route.dispatch(req, {}, cb);

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 45–48why, one step back
45 });
46 })4748 it('should stack', function(done) {

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 49why, one step back
49 var req = { count: 0, method: 'GET', url: '/' };

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 50–52why, one step back
50 var route = new Route('/foo');
5152 route.all(function(req, res, next) {

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 53why, one step back
53 req.count++;

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 54–57why, one step back
54 next();
55 });5657 route.all(function(req, res, next) {

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 58why, one step back
58 req.count++;

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 59–61why, one step back
59 next();
60 });61

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

lines 62–65why, one step back
62 route.dispatch(req, {}, function (err) {
63 if (err) return done(err);64 req.count.should.equal(2);65 done();

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 66–71why, one step back
66 });
67 })68 })6970 describe('.VERB', function(){71 it('should support .get', function(done){

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 72why, one step back
72 var req = { method: 'GET', url: '/' };

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 73–75why, one step back
73 var route = new Route('');
7475 route.get(function(req, res, next) {

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

lines 76–77why, one step back
76 req.called = true;
77 next();

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 78–79why, one step back
78 })
79

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

lines 80–84why, one step back
80 route.dispatch(req, {}, function (err) {
81 if (err) return done(err);82 should(req.called).be.ok;83 done();84 });

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 85–87why, one step back
85 })
8687 it('should limit to just .VERB', function(done){

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 88why, one step back
88 var req = { method: 'POST', url: '/' };

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 89–91why, one step back
89 var route = new Route('');
9091 route.get(function(req, res, next) {

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 92why, one step back
92 throw new Error('not me!');

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 93–95why, one step back
93 })
9495 route.post(function(req, res, next) {

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

lines 96–97why, one step back
96 req.called = true;
97 next();

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 98–99why, one step back
98 })
99

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

lines 100–104why, one step back
100 route.dispatch(req, {}, function (err) {
101 if (err) return done(err);102 should(req.called).be.true;103 done();104 });

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 105–107why, one step back
105 })
106107 it('should allow fallthrough', function(done){

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 108why, one step back
108 var req = { order: '', method: 'GET', url: '/' };

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 109–111why, one step back
109 var route = new Route('');
110111 route.get(function(req, res, next) {

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 112why, one step back
112 req.order += 'a';

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 113–116why, one step back
113 next();
114 })115116 route.all(function(req, res, next) {

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 117why, one step back
117 req.order += 'b';

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 118–121why, one step back
118 next();
119 });120121 route.get(function(req, res, next) {

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

lines 122–123why, one step back
122 req.order += 'c';
123 next();

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 124–125why, one step back
124 })
125

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

lines 126–130why, one step back
126 route.dispatch(req, {}, function (err) {
127 if (err) return done(err);128 req.order.should.equal('abc');129 done();130 });

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 131–135why, one step back
131 })
132 })133134 describe('errors', function(){135 it('should handle errors via arity 4 functions', function(done){

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 136why, one step back
136 var req = { order: '', method: 'GET', url: '/' };

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 137–143why, one step back
137 var route = new Route('');
138139 route.all(function(req, res, next){140 next(new Error('foobar'));141 });142143 route.all(function(req, res, next){

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 144why, one step back
144 req.order += '0';

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 145–148why, one step back
145 next();
146 });147148 route.all(function(err, req, res, next){

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 149why, one step back
149 req.order += 'a';

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 150–152why, one step back
150 next(err);
151 });152

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

lines 153–156why, one step back
153 route.dispatch(req, {}, function (err) {
154 should(err).be.ok;155 should(err.message).equal('foobar');156 req.order.should.equal('a');

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 157–161why, one step back
157 done();
158 });159 })160161 it('should handle throw', function(done) {

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 162why, one step back
162 var req = { order: '', method: 'GET', url: '/' };

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 163–169why, one step back
163 var route = new Route('');
164165 route.all(function(req, res, next){166 throw new Error('foobar');167 });168169 route.all(function(req, res, next){

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 170why, one step back
170 req.order += '0';

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 171–174why, one step back
171 next();
172 });173174 route.all(function(err, req, res, next){

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 175why, one step back
175 req.order += 'a';

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 176–178why, one step back
176 next(err);
177 });178

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

lines 179–182why, one step back
179 route.dispatch(req, {}, function (err) {
180 should(err).be.ok;181 should(err.message).equal('foobar');182 req.order.should.equal('a');

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 183–187why, one step back
183 done();
184 });185 });186187 it('should handle throwing inside error handlers', function(done) {

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 188why, one step back
188 var req = { method: 'GET', url: '/' };

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 189–199why, one step back
189 var route = new Route('');
190191 route.get(function(req, res, next){192 throw new Error('boom!');193 });194195 route.get(function(err, req, res, next){196 throw new Error('oops');197 });198199 route.get(function(err, req, res, next){

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

lines 200–201why, one step back
200 req.message = err.message;
201 next();

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 202–203why, one step back
202 });
203

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

lines 204–208why, one step back
204 route.dispatch(req, {}, function (err) {
205 if (err) return done(err);206 should(req.message).equal('oops');207 done();208 });

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 209–211why, one step back
209 });
210211 it('should handle throw in .all', function(done) {

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 212why, one step back
212 var req = { method: 'GET', url: '/' };

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 213–218why, one step back
213 var route = new Route('');
214215 route.all(function(req, res, next){216 throw new Error('boom!');217 });218

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 219why, one step back
219 route.dispatch(req, {}, function(err){

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 220–226why, one step back
220 should(err).be.ok;
221 err.message.should.equal('boom!');222 done();223 });224 });225226 it('should handle single error handler', function(done) {

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 227why, one step back
227 var req = { method: 'GET', url: '/' };

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 228–234why, one step back
228 var route = new Route('');
229230 route.all(function(err, req, res, next){231 // this should not execute232 true.should.be.false;233 });234

tests: change Route tests to use callbackDouglas Christopher Wilsonbefore adoptiond0b6b3d

line 235why, one step back
235 route.dispatch(req, {}, done);

Invoke router.param() only when route matchesDouglas Christopher Wilsonbefore adoption269dc53

lines 236–238why, one step back
236 });
237 })238})