Skip to content
Myr

tests: add more etag tests

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

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 766b3ae · Browse files · 5 files+62 added−40 removed
This commit

State

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

Diff stats

5 files+62 added−40 removed

  • tests:+62 added−40 removed

5 files+62 added−40 removed

modified:test/req.fresh.js+6 added-5 removed
modified:test/req.stale.js+6 added-5 removed
modified:test/res.send.js+30 added-15 removed
285 unmodified lines
286 })287288 it('should always check regardless of length', function(done){289 var app = express();290 var etag = '"asdf"';291292 app.use(function(req, res, next){292 res.set('ETag', 'asdf');293 res.set('ETag', etag);294 res.send('hey');295 });296297 request(app)298 .get('/')298 .set('If-None-Match', 'asdf')299 .set('If-None-Match', etag)300 .expect(304, done);301 })302303 it('should respond with 304 Not Modified when fresh', function(done){
11 unmodified lines
315 })316317 it('should not perform freshness check unless 2xx or 304', function(done){318 var app = express();319 var etag = '"asdf"';320321 app.use(function(req, res, next){322 res.status(500);321 res.set('ETag', 'asdf');323 res.set('ETag', etag);324 res.send('hey');325 });326327 request(app)328 .get('/')327 .set('If-None-Match', 'asdf')329 .set('If-None-Match', etag)330 .expect('hey')331 .expect(500, done);332 })333
10 unmodified lines
344 })345346 describe('"etag" setting', function(){347 describe('when enabled', function(){346 it('should send ETag even when content-length < 1024', function(done){348 it('should send ETag', function(done){349 var app = express();350351 app.use(function(req, res){352 res.send('kajdslfkasdf');353 });354355 app.enable('etag');356357 request(app)358 .get('/')355 .end(function(err, res){356 res.headers.should.have.property('etag');357 done();358 });359 .expect('etag', 'W/"c-1525560792"', done)360 })361361 it('should send ETag', function(done){362 it('should send ETag for long response', function(done){363 var app = express();364365 app.use(function(req, res){366 var str = Array(1024 * 2).join('-');367 res.send(str);368 });369370 app.enable('etag');371372 request(app)373 .get('/')374 .expect('etag', 'W/"7ff-2796319984"', done)375 });376377 it('should not override ETag when manually set', function(done){378 var app = express();379380 app.use(function(req, res){381 res.set('etag', '"asdf"');382 res.send(200);383 });384385 app.enable('etag');386387 request(app)388 .get('/')389 .expect('etag', '"asdf"', done)390 });391 });392393 describe('when disabled', function(){394 it('should send no ETag', function(done){
19 unmodified lines
414415 app.disable('etag');416417 app.use(function(req, res){400 res.set('etag', 1);418 res.set('etag', '"asdf"');419 res.send(200);420 });421422 request(app)423 .get('/')406 .end(function(err, res){407 res.headers.should.have.property('etag');408 done();409 });424 .expect('etag', '"asdf"', done)425 });426 });427 })428})
modified:test/res.set.js+7 added-6 removed
modified:test/utils.js+13 added-9 removed
12var utils = require('../lib/utils')3 , assert = require('assert');45describe('utils.etag(body)', function(){67 var str = 'Hello CRC';8 var strUTF8 = '<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body><p>自動販売</p></body></html>';95describe('utils.etag(body, encoding)', function(){6 it('should support strings', function(){11 utils.etag(str).should.eql('W/"9-2260508953"');7 utils.etag('express!')8 .should.eql('W/"8-3098196679"')9 })1011 it('should support utf8 strings', function(){15 utils.etag(strUTF8, 'utf8').should.eql('W/"4d-1395090196"');12 utils.etag('express❤', 'utf8')13 .should.eql('W/"a-1751845617"')14 })1516 it('should support buffer', function(){19 utils.etag(new Buffer(strUTF8, 'utf8')).should.eql('W/"4d-1395090196"');20 utils.etag(new Buffer(str)).should.eql('W/"9-2260508953"');17 var buf = new Buffer('express!')18 utils.etag(buf)19 .should.eql('W/"8-3098196679"');20 })2122 it('should support empty string', function(){23 var buf = new Buffer('express!')24 utils.etag('')25 .should.eql('W/"0-0"');26 })27})2829describe('utils.isAbsolute()', function(){30 it('should support windows', function(){
201 unmodified lines