Skip to content
Myr

refactor

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent c6d7352 · Browse files · 1 file+34 added−52 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+34 added−52 removed

  • tests:+34 added−52 removed

1 file+34 added−52 removed

modified:test/res.redirect.js+34 added-52 removed
168 unmodified lines
169 })170 })171 })172173 describe('responses redirected to dotted relative paths', function () {174175 /* The requisite test fixtures are repetitive. */176 var makeApp = function (depth, parent) {173 describe('responses redirected to relative paths', function(){174 function create(depth, parent) {175 var app = express();176177 if (parent) {178 parent.use('/depth' + depth, app);179 }180183 app.get('/', function (req, res) {181 app.get('/', function(req, res){182 res.redirect('./index');183 });184187 app.get('/index', function (req, res) {188 res.json({depth : depth, content : 'index'});185 app.get('/index', function(req, res){186 res.json({ depth: depth, content: 'index' });187 });188189 return app;190 }191194 var root = makeApp(0);195 var depth1 = makeApp(1, root);196 var depth2 = makeApp(2, depth1);197 var depth3 = makeApp(3, depth2);192 var root = create(0);193 var depth1 = create(1, root);194 var depth2 = create(2, depth1);195 var depth3 = create(3, depth2);196199 /* Special cases for alias paths. */197 root.use('/depth2', depth2);198 root.use('/depth3', depth3);199203 /*204 * The resulting structure resembles the following.205 *206 * / -> root207 *208 * /depth1 -> depth1209 * /depth1/depth2 -> depth2210 * /depth1/depth2/depth3 -> depth3211 *212 * /depth2 -> depth2213 * /depth3 -> depth3214 */215216 it('should not contain redundant leading slashes in the location header', function (done) {200 it('should not contain redundant leading slashes in the location header', function(done){201 request(root)218 .get('/')219 .end(function (err, res) {220 res.headers.location.search(/^\/{2}/).should.equal(-1);221 done();222 })202 .get('/')203 .end(function(err, res){204 res.headers.location.search(/^\/{2}/).should.equal(-1);205 done();206 })207 })208209 it('should preserve context when redirecting nested applications at any depth', function(done){210 request(root)227 .get('/depth1')228 .end(function(err, res) {229 res.headers.should.have.property('location', '/depth1/./index');230 });211 .get('/depth1')212 .end(function(err, res){213 res.headers.should.have.property('location', '/depth1/./index');214232 request(root)215 request(root)216 .get('/depth1/depth2')234 .end(function(err, res) {217 .end(function(err, res){218 res.headers.should.have.property('location', '/depth1/depth2/./index');236 })219238 request(root)239 .get('/depth1/depth2/depth3')240 .end(function(err, res) {241 res.headers.should.have.property('location', '/depth1/depth2/depth3/./index');242 done();220 request(root)221 .get('/depth1/depth2/depth3')222 .end(function(err, res){223 res.headers.should.have.property('location', '/depth1/depth2/depth3/./index');224 done();225 })226 })227 });228 })229246 it('should redirect correctly for nested applications that have been remounted', function (done) {230 it('should redirect correctly for nested applications that have been remounted', function(done){231 request(root)248 .get('/depth2')249 .end(function (err, res) {250 res.headers.should.have.property('location', '/depth2/./index');251 })252253 request(root)232 .get('/depth2')233 .end(function(err, res){234 res.headers.should.have.property('location', '/depth2/./index');235 request(root)236 .get('/depth3')255 .end(function (err, res) {237 .end(function(err, res){238 res.headers.should.have.property('location', '/depth3/./index');239 done();240 })241 })242 })260243 })244})