Skip to content
Myr

res.jsonp.js

This file

Path

test/res.jsonp.js

333 lines · 8.9 KiB · JavaScript

Last changed by

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

History of this file

Take it

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

Merge pull request #1836 from fluxusfrequency/patch-1Roman Shtylmanbefore adoption2939075

lines 1–2why, one step back
1
2var express = require('../')

remove unnecessary test/support/httpJonathan Ongbefore adoption643397e

line 3why, one step back
3 , request = require('supertest')

Merge pull request #1836 from fluxusfrequency/patch-1Roman Shtylmanbefore adoption2939075

lines 4–39why, one step back
4 , assert = require('assert');
56describe('res', function(){7 describe('.jsonp(object)', function(){8 it('should respond with jsonp', function(done){9 var app = express();1011 app.use(function(req, res){12 res.jsonp({ count: 1 });13 });1415 request(app)16 .get('/?callback=something')17 .end(function(err, res){18 res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');19 res.text.should.equal('typeof something === \'function\' && something({"count":1});');20 done();21 })22 })2324 it('should use first callback parameter with jsonp', function(done){25 var app = express();2627 app.use(function(req, res){28 res.jsonp({ count: 1 });29 });3031 request(app)32 .get('/?callback=something&callback=somethingelse')33 .end(function(err, res){34 res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');35 res.text.should.equal('typeof something === \'function\' && something({"count":1});');36 done();37 })38 })39

Merge branch '4.1.x'Douglas Christopher Wilsonbefore adoption0bbbc84

lines 40–48why, one step back
40 it('should ignore object callback parameter with jsonp', function(done){
41 var app = express();4243 app.use(function(req, res){44 res.jsonp({ count: 1 });45 });4647 request(app)48 .get('/?callback[a]=something')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 49–50why, one step back
49 .expect('Content-Type', 'application/json; charset=utf-8')
50 .expect(200, '{"count":1}', done)

Merge branch '4.1.x'Douglas Christopher Wilsonbefore adoption0bbbc84

lines 51–52why, one step back
51 })
52

Merge pull request #1836 from fluxusfrequency/patch-1Roman Shtylmanbefore adoption2939075

lines 53–118why, one step back
53 it('should allow renaming callback', function(done){
54 var app = express();5556 app.set('jsonp callback name', 'clb');5758 app.use(function(req, res){59 res.jsonp({ count: 1 });60 });6162 request(app)63 .get('/?clb=something')64 .end(function(err, res){65 res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');66 res.text.should.equal('typeof something === \'function\' && something({"count":1});');67 done();68 })69 })7071 it('should allow []', function(done){72 var app = express();7374 app.use(function(req, res){75 res.jsonp({ count: 1 });76 });7778 request(app)79 .get('/?callback=callbacks[123]')80 .end(function(err, res){81 res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');82 res.text.should.equal('typeof callbacks[123] === \'function\' && callbacks[123]({"count":1});');83 done();84 })85 })8687 it('should disallow arbitrary js', function(done){88 var app = express();8990 app.use(function(req, res){91 res.jsonp({});92 });9394 request(app)95 .get('/?callback=foo;bar()')96 .end(function(err, res){97 res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');98 res.text.should.equal('typeof foobar === \'function\' && foobar({});');99 done();100 })101 })102103 it('should escape utf whitespace', function(done){104 var app = express();105106 app.use(function(req, res){107 res.jsonp({ str: '\u2028 \u2029 woot' });108 });109110 request(app)111 .get('/?callback=foo')112 .end(function(err, res){113 res.headers.should.have.property('content-type', 'text/javascript; charset=utf-8');114 res.text.should.equal('typeof foo === \'function\' && foo({"str":"\\u2028 \\u2029 woot"});');115 done();116 });117 });118

tests: fixup new json testsDouglas Christopher Wilsonbefore adoptione4302b2

lines 119–128why, one step back
119 it('should not override previous Content-Types with no callback', function(done){
120 var app = express();121122 app.get('/', function(req, res){123 res.type('application/vnd.example+json');124 res.jsonp({ hello: 'world' });125 });126127 request(app)128 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

line 129why, one step back
129 .expect('Content-Type', 'application/vnd.example+json; charset=utf-8')

tests: fixup new json testsDouglas Christopher Wilsonbefore adoptione4302b2

lines 130–146why, one step back
130 .expect(200, '{"hello":"world"}', done);
131 })132133 it('should override previous Content-Types with callback', function(done){134 var app = express();135136 app.get('/', function(req, res){137 res.type('application/vnd.example+json');138 res.jsonp({ hello: 'world' });139 });140141 request(app)142 .get('/?callback=cb')143 .expect('Content-Type', 'text/javascript; charset=utf-8')144 .expect(200, /cb\(\{"hello":"world"\}\);$/, done);145 })146

Merge pull request #1836 from fluxusfrequency/patch-1Roman Shtylmanbefore adoption2939075

lines 147–156why, one step back
147 describe('when given primitives', function(){
148 it('should respond with json', function(done){149 var app = express();150151 app.use(function(req, res){152 res.jsonp(null);153 });154155 request(app)156 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 157–158why, one step back
157 .expect('Content-Type', 'application/json; charset=utf-8')
158 .expect(200, 'null', done)

Merge pull request #1836 from fluxusfrequency/patch-1Roman Shtylmanbefore adoption2939075

lines 159–171why, one step back
159 })
160 })161162 describe('when given an array', function(){163 it('should respond with json', function(done){164 var app = express();165166 app.use(function(req, res){167 res.jsonp(['foo', 'bar', 'baz']);168 });169170 request(app)171 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 172–173why, one step back
172 .expect('Content-Type', 'application/json; charset=utf-8')
173 .expect(200, '["foo","bar","baz"]', done)

Merge pull request #1836 from fluxusfrequency/patch-1Roman Shtylmanbefore adoption2939075

lines 174–186why, one step back
174 })
175 })176177 describe('when given an object', function(){178 it('should respond with json', function(done){179 var app = express();180181 app.use(function(req, res){182 res.jsonp({ name: 'tobi' });183 });184185 request(app)186 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 187–188why, one step back
187 .expect('Content-Type', 'application/json; charset=utf-8')
188 .expect(200, '{"name":"tobi"}', done)

Merge pull request #1836 from fluxusfrequency/patch-1Roman Shtylmanbefore adoption2939075

lines 189–191why, one step back
189 })
190 })191

Merge tag '3.6.0'Douglas Christopher Wilsonbefore adoption35c5060

lines 192–201why, one step back
192 describe('when given primitives', function(){
193 it('should respond with json for null', function(done){194 var app = express();195196 app.use(function(req, res){197 res.jsonp(null);198 });199200 request(app)201 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 202–203why, one step back
202 .expect('Content-Type', 'application/json; charset=utf-8')
203 .expect(200, 'null', done)

Merge tag '3.6.0'Douglas Christopher Wilsonbefore adoption35c5060

lines 204–214why, one step back
204 })
205206 it('should respond with json for Number', function(done){207 var app = express();208209 app.use(function(req, res){210 res.jsonp(300);211 });212213 request(app)214 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 215–216why, one step back
215 .expect('Content-Type', 'application/json; charset=utf-8')
216 .expect(200, '300', done)

Merge tag '3.6.0'Douglas Christopher Wilsonbefore adoption35c5060

lines 217–227why, one step back
217 })
218219 it('should respond with json for String', function(done){220 var app = express();221222 app.use(function(req, res){223 res.jsonp('str');224 });225226 request(app)227 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 228–229why, one step back
228 .expect('Content-Type', 'application/json; charset=utf-8')
229 .expect(200, '"str"', done)

Merge tag '3.6.0'Douglas Christopher Wilsonbefore adoption35c5060

lines 230–232why, one step back
230 })
231 })232

Merge pull request #1836 from fluxusfrequency/patch-1Roman Shtylmanbefore adoption2939075

lines 233–248why, one step back
233 describe('"json replacer" setting', function(){
234 it('should be passed to JSON.stringify()', function(done){235 var app = express();236237 app.set('json replacer', function(key, val){238 return '_' == key[0]239 ? undefined240 : val;241 });242243 app.use(function(req, res){244 res.jsonp({ name: 'tobi', _id: 12345 });245 });246247 request(app)248 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 249–250why, one step back
249 .expect('Content-Type', 'application/json; charset=utf-8')
250 .expect(200, '{"name":"tobi"}', done)

Merge pull request #1836 from fluxusfrequency/patch-1Roman Shtylmanbefore adoption2939075

lines 251–254why, one step back
251 })
252 })253254 describe('"json spaces" setting', function(){

Merge pull request #1899 from visionmedia/remove-configureRoman Shtylmanbefore adoptionac2cbef

line 255why, one step back
255 it('should be undefined by default', function(){

Merge pull request #1836 from fluxusfrequency/patch-1Roman Shtylmanbefore adoption2939075

lines 256–270why, one step back
256 var app = express();
257 assert(undefined === app.get('json spaces'));258 })259260 it('should be passed to JSON.stringify()', function(done){261 var app = express();262263 app.set('json spaces', 2);264265 app.use(function(req, res){266 res.jsonp({ name: 'tobi', age: 2 });267 });268269 request(app)270 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 271–272why, one step back
271 .expect('Content-Type', 'application/json; charset=utf-8')
272 .expect(200, '{\n "name": "tobi",\n "age": 2\n}', done)

Merge pull request #1836 from fluxusfrequency/patch-1Roman Shtylmanbefore adoption2939075

lines 273–276why, one step back
273 })
274 })275 })276

Merge branch '4.1.x'Douglas Christopher Wilsonbefore adoption0bbbc84

line 277why, one step back
277 describe('.jsonp(status, object)', function(){

Merge pull request #1836 from fluxusfrequency/patch-1Roman Shtylmanbefore adoption2939075

lines 278–286why, one step back
278 it('should respond with json and set the .statusCode', function(done){
279 var app = express();280281 app.use(function(req, res){282 res.jsonp(201, { id: 1 });283 });284285 request(app)286 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 287–288why, one step back
287 .expect('Content-Type', 'application/json; charset=utf-8')
288 .expect(201, '{"id":1}', done)

Merge pull request #1836 from fluxusfrequency/patch-1Roman Shtylmanbefore adoption2939075

lines 289–291why, one step back
289 })
290 })291

Merge branch '4.1.x'Douglas Christopher Wilsonbefore adoption0bbbc84

line 292why, one step back
292 describe('.jsonp(object, status)', function(){

Merge pull request #1836 from fluxusfrequency/patch-1Roman Shtylmanbefore adoption2939075

lines 293–301why, one step back
293 it('should respond with json and set the .statusCode for backwards compat', function(done){
294 var app = express();295296 app.use(function(req, res){297 res.jsonp({ id: 1 }, 201);298 });299300 request(app)301 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 302–303why, one step back
302 .expect('Content-Type', 'application/json; charset=utf-8')
303 .expect(201, '{"id":1}', done)

Merge tag '3.6.0'Douglas Christopher Wilsonbefore adoption35c5060

lines 304–314why, one step back
304 })
305306 it('should use status as second number for backwards compat', function(done){307 var app = express();308309 app.use(function(req, res){310 res.jsonp(200, 201);311 });312313 request(app)314 .get('/')

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 315–316why, one step back
315 .expect('Content-Type', 'application/json; charset=utf-8')
316 .expect(201, '200', done)

Keep previous Content-Type for res.jsonpAlberto Lealbefore adoptionbe997fd

line 317why, one step back
317 })

Merge tag '3.8.0'Douglas Christopher Wilsonbefore adoptiondb4a061

lines 318–331why, one step back
318 })
319320 it('should not override previous Content-Types', function(done){321 var app = express();322323 app.get('/', function(req, res){324 res.type('application/vnd.example+json');325 res.jsonp({ hello: 'world' });326 });327328 request(app)329 .get('/')330 .expect('content-type', 'application/vnd.example+json; charset=utf-8')331 .expect(200, '{"hello":"world"}', done)

Keep previous Content-Type for res.jsonpAlberto Lealbefore adoptionbe997fd

line 332why, one step back
332 })

Merge pull request #1836 from fluxusfrequency/patch-1Roman Shtylmanbefore adoption2939075

line 333why, one step back
333})