req.range.js
This file
Path
test/req.range.js
104 lines · 2.3 KiB · JavaScript
Last changed by
tests: use strict modeDouglas Christopher Wilsonbefore adoptiona659137
History of this fileTake it
The walk stopped after 200 commits: lines older than b02d3a1 point at it.
tests: use strict modeDouglas Christopher Wilsonbefore adoptiona659137
line 1why, one step back1'use strict'docs: add link to contributing guideJames Georgebefore adoptionb02d3a1
lines 2–104why, one step back23var express = require('..');4var request = require('supertest')56describe('req', function(){7 describe('.range(size)', function(){8 it('should return parsed ranges', function (done) {9 var app = express()1011 app.use(function (req, res) {12 res.json(req.range(120))13 })1415 request(app)16 .get('/')17 .set('Range', 'bytes=0-50,51-100')18 .expect(200, '[{"start":0,"end":50},{"start":51,"end":100}]', done)19 })2021 it('should cap to the given size', function (done) {22 var app = express()2324 app.use(function (req, res) {25 res.json(req.range(75))26 })2728 request(app)29 .get('/')30 .set('Range', 'bytes=0-100')31 .expect(200, '[{"start":0,"end":74}]', done)32 })3334 it('should cap to the given size when open-ended', function (done) {35 var app = express()3637 app.use(function (req, res) {38 res.json(req.range(75))39 })4041 request(app)42 .get('/')43 .set('Range', 'bytes=0-')44 .expect(200, '[{"start":0,"end":74}]', done)45 })4647 it('should have a .type', function (done) {48 var app = express()4950 app.use(function (req, res) {51 res.json(req.range(120).type)52 })5354 request(app)55 .get('/')56 .set('Range', 'bytes=0-100')57 .expect(200, '"bytes"', done)58 })5960 it('should accept any type', function (done) {61 var app = express()6263 app.use(function (req, res) {64 res.json(req.range(120).type)65 })6667 request(app)68 .get('/')69 .set('Range', 'users=0-2')70 .expect(200, '"users"', done)71 })7273 it('should return undefined if no range', function (done) {74 var app = express()7576 app.use(function (req, res) {77 res.send(String(req.range(120)))78 })7980 request(app)81 .get('/')82 .expect(200, 'undefined', done)83 })84 })8586 describe('.range(size, options)', function(){87 describe('with "combine: true" option', function(){88 it('should return combined ranges', function (done) {89 var app = express()9091 app.use(function (req, res) {92 res.json(req.range(120, {93 combine: true94 }))95 })9697 request(app)98 .get('/')99 .set('Range', 'bytes=0-50,51-100')100 .expect(200, '[{"start":0,"end":100}]', done)101 })102 })103 })104})