Skip to content
Myr

app.options.js

This file

Path

test/app.options.js

115 lines · 2.7 KiB · JavaScript

Last changed by

Fix OPTIONS responses to include the HEAD method properlyDouglas Christopher Wilsonbefore adoption935f05b

History of this file

Take it

The walk stopped after 200 commits: lines older than 6bc7574 point at it.

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 1–14why, one step back
1
2var express = require('../')3 , request = require('supertest');45describe('OPTIONS', function(){6 it('should default to the routes defined', function(done){7 var app = express();89 app.del('/', function(){});10 app.get('/users', function(req, res){});11 app.put('/users', function(req, res){});1213 request(app)14 .options('/users')

Fix OPTIONS responses to include the HEAD method properlyDouglas Christopher Wilsonbefore adoption935f05b

lines 15–16why, one step back
15 .expect('Allow', 'GET,HEAD,PUT')
16 .expect(200, 'GET,HEAD,PUT', done);

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 17–18why, one step back
17 })
18

Fix Allow header for OPTIONS to not contain duplicate methodsDouglas Christopher Wilsonbefore adoption12626ae

lines 19–28why, one step back
19 it('should only include each method once', function(done){
20 var app = express();2122 app.del('/', function(){});23 app.get('/users', function(req, res){});24 app.put('/users', function(req, res){});25 app.get('/users', function(req, res){});2627 request(app)28 .options('/users')

Fix OPTIONS responses to include the HEAD method properlyDouglas Christopher Wilsonbefore adoption935f05b

lines 29–30why, one step back
29 .expect('Allow', 'GET,HEAD,PUT')
30 .expect(200, 'GET,HEAD,PUT', done);

Fix Allow header for OPTIONS to not contain duplicate methodsDouglas Christopher Wilsonbefore adoption12626ae

lines 31–32why, one step back
31 })
32

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 33–46why, one step back
33 it('should not be affected by app.all', function(done){
34 var app = express();3536 app.get('/', function(){});37 app.get('/users', function(req, res){});38 app.put('/users', function(req, res){});39 app.all('/users', function(req, res, next){40 res.setHeader('x-hit', '1');41 next();42 });4344 request(app)45 .options('/users')46 .expect('x-hit', '1')

Fix OPTIONS responses to include the HEAD method properlyDouglas Christopher Wilsonbefore adoption935f05b

lines 47–48why, one step back
47 .expect('Allow', 'GET,HEAD,PUT')
48 .expect(200, 'GET,HEAD,PUT', done);

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 49–70why, one step back
49 })
5051 it('should not respond if the path is not defined', function(done){52 var app = express();5354 app.get('/users', function(req, res){});5556 request(app)57 .options('/other')58 .expect(404, done);59 })6061 it('should forward requests down the middleware chain', function(done){62 var app = express();63 var router = new express.Router();6465 router.get('/users', function(req, res){});66 app.use(router);67 app.get('/other', function(req, res){});6869 request(app)70 .options('/other')

Fix OPTIONS responses to include the HEAD method properlyDouglas Christopher Wilsonbefore adoption935f05b

lines 71–72why, one step back
71 .expect('Allow', 'GET,HEAD')
72 .expect(200, 'GET,HEAD', done);

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

line 73why, one step back
73 })

Fix crash from error within OPTIONS response handlerDouglas Christopher Wilsonbefore adoptiondab9222

lines 74–95why, one step back
74
75 describe('when error occurs in respone handler', function () {76 it('should pass error to callback', function (done) {77 var app = express();78 var router = express.Router();7980 router.get('/users', function(req, res){});8182 app.use(function (req, res, next) {83 res.writeHead(200);84 next();85 });86 app.use(router);87 app.use(function (err, req, res, next) {88 res.end('true');89 });9091 request(app)92 .options('/users')93 .expect(200, 'true', done)94 })95 })

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 96–115why, one step back
96})
9798describe('app.options()', function(){99 it('should override the default behavior', function(done){100 var app = express();101102 app.options('/users', function(req, res){103 res.set('Allow', 'GET');104 res.send('GET');105 });106107 app.get('/users', function(req, res){});108 app.put('/users', function(req, res){});109110 request(app)111 .options('/users')112 .expect('GET')113 .expect('Allow', 'GET', done);114 })115})