Skip to content

Commit 8a0f829

Browse files
committed
tests: use assert instead of should
1 parent 933f1e7 commit 8a0f829

File tree

2 files changed

+46
-64
lines changed

2 files changed

+46
-64
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
"devDependencies": {
2020
"istanbul": "0.3.2",
2121
"mocha": "~2.0.1",
22-
"supertest": "~0.15.0",
23-
"should": "~4.0.1"
22+
"supertest": "~0.15.0"
2423
},
2524
"files": [
2625
"LICENSE",

test/test.js

Lines changed: 45 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
var assert = require('assert')
12
var bytes = require('bytes');
23
var crypto = require('crypto');
34
var http = require('http');
45
var request = require('supertest');
5-
var should = require('should');
66

77
var compress = require('..');
88

@@ -28,11 +28,8 @@ describe('compress()', function(){
2828
request(server)
2929
.head('/')
3030
.set('Accept-Encoding', 'gzip')
31-
.end(function (err, res) {
32-
if (err) return done(err)
33-
res.headers.should.not.have.property('content-encoding')
34-
done()
35-
})
31+
.expect(shouldNotHaveHeader('Content-Encoding'))
32+
.expect(200, done)
3633
})
3734

3835
it('should skip unknown accept-encoding', function(done){
@@ -44,11 +41,8 @@ describe('compress()', function(){
4441
request(server)
4542
.get('/')
4643
.set('Accept-Encoding', 'bogus')
47-
.end(function (err, res) {
48-
if (err) return done(err)
49-
res.headers.should.not.have.property('content-encoding')
50-
done()
51-
})
44+
.expect(shouldNotHaveHeader('Content-Encoding'))
45+
.expect(200, done)
5246
})
5347

5448
it('should skip if content-encoding already set', function(done){
@@ -87,11 +81,8 @@ describe('compress()', function(){
8781
request(server)
8882
.get('/')
8983
.expect('Vary', 'Accept-Encoding')
90-
.end(function (err, res) {
91-
if (err) return done(err)
92-
res.headers.should.not.have.property('content-encoding')
93-
done()
94-
})
84+
.expect(shouldNotHaveHeader('Content-Encoding'))
85+
.expect(200, done)
9586
})
9687

9788
it('should not set Vary if Content-Type does not pass filter', function(done){
@@ -102,11 +93,8 @@ describe('compress()', function(){
10293

10394
request(server)
10495
.get('/')
105-
.end(function (err, res) {
106-
if (err) return done(err)
107-
res.headers.should.not.have.property('vary')
108-
done()
109-
})
96+
.expect(shouldNotHaveHeader('Vary'))
97+
.expect(200, done)
11098
})
11199

112100
it('should set Vary for HEAD request', function(done){
@@ -142,11 +130,8 @@ describe('compress()', function(){
142130
request(server)
143131
.get('/')
144132
.expect('Content-Encoding', 'gzip')
145-
.end(function (err, res) {
146-
if (err) return done(err)
147-
res.headers.should.not.have.property('content-length')
148-
done()
149-
})
133+
.expect(shouldNotHaveHeader('Content-Length'))
134+
.expect(200, done)
150135
})
151136

152137
it('should allow writing after close', function(done){
@@ -189,7 +174,7 @@ describe('compress()', function(){
189174

190175
function complete(){
191176
if (--wait !== 0) return
192-
drained.should.be.true
177+
assert.ok(drained)
193178
done()
194179
}
195180

@@ -213,7 +198,7 @@ describe('compress()', function(){
213198
.request()
214199
.on('response', function (res) {
215200
client = res
216-
res.headers['content-encoding'].should.equal('gzip')
201+
assert.equal(res.headers['content-encoding'], 'gzip')
217202
res.pause()
218203
res.on('end', complete)
219204
pressure()
@@ -244,7 +229,7 @@ describe('compress()', function(){
244229

245230
function complete(){
246231
if (--wait !== 0) return
247-
drained.should.be.true
232+
assert.ok(drained)
248233
done()
249234
}
250235

@@ -268,7 +253,7 @@ describe('compress()', function(){
268253
.request()
269254
.on('response', function (res) {
270255
client = res
271-
res.headers.should.not.have.property('content-encoding')
256+
shouldNotHaveHeader('Content-Encoding')(res)
272257
res.pause()
273258
res.on('end', complete)
274259
pressure()
@@ -290,12 +275,9 @@ describe('compress()', function(){
290275
.get('/')
291276
.set('Accept-Encoding', 'gzip')
292277
.expect('Transfer-Encoding', 'chunked')
293-
.expect('Content-Encoding', 'gzip', function (err, res) {
294-
if (err) return done(err)
295-
should(res.text).equal(buf.toString())
296-
res.text.length.should.equal(len)
297-
done()
298-
})
278+
.expect('Content-Encoding', 'gzip')
279+
.expect(shouldHaveBodyLength(len))
280+
.expect(200, buf.toString(), done)
299281
})
300282

301283
it('should transfer large bodies with multiple writes', function (done) {
@@ -315,11 +297,9 @@ describe('compress()', function(){
315297
.get('/')
316298
.set('Accept-Encoding', 'gzip')
317299
.expect('Transfer-Encoding', 'chunked')
318-
.expect('Content-Encoding', 'gzip', function (err, res) {
319-
if (err) return done(err)
320-
res.text.length.should.equal(len * 4)
321-
done()
322-
})
300+
.expect('Content-Encoding', 'gzip')
301+
.expect(shouldHaveBodyLength(len * 4))
302+
.expect(200, done)
323303
})
324304

325305
describe('threshold', function(){
@@ -333,11 +313,8 @@ describe('compress()', function(){
333313
request(server)
334314
.get('/')
335315
.set('Accept-Encoding', 'gzip')
336-
.end(function(err, res){
337-
if (err) return done(err)
338-
res.headers.should.not.have.property('content-encoding')
339-
done()
340-
})
316+
.expect(shouldNotHaveHeader('Content-Encoding'))
317+
.expect(200, done)
341318
})
342319

343320
it('should compress responses above the threshold size', function(done){
@@ -381,11 +358,8 @@ describe('compress()', function(){
381358
request(server)
382359
.get('/')
383360
.set('Accept-Encoding', 'gzip')
384-
.end(function(err, res){
385-
if (err) return done(err)
386-
res.headers.should.not.have.property('content-encoding')
387-
done()
388-
})
361+
.expect(shouldNotHaveHeader('Content-Encoding'))
362+
.expect(200, done)
389363
})
390364

391365
it('should compress when streaming and content-length is larger than threshold', function(done){
@@ -415,11 +389,8 @@ describe('compress()', function(){
415389
request(server)
416390
.get('/')
417391
.set('Accept-Encoding', 'gzip')
418-
.expect(200, '....', function (err, res) {
419-
if (err) return done(err)
420-
res.headers.should.not.have.property('content-encoding')
421-
done()
422-
})
392+
.expect(shouldNotHaveHeader('Content-Encoding'))
393+
.expect(200, '....', done)
423394
})
424395
})
425396

@@ -461,10 +432,10 @@ describe('compress()', function(){
461432
.set('Accept-Encoding', 'gzip')
462433
.request()
463434
.on('response', function (res) {
464-
res.headers['content-encoding'].should.equal('gzip')
435+
assert.equal(res.headers['content-encoding'], 'gzip')
465436
res.on('data', write)
466437
res.on('end', function(){
467-
chunks.should.equal(2)
438+
assert.equal(chunks, 2)
468439
done()
469440
})
470441
})
@@ -493,10 +464,10 @@ describe('compress()', function(){
493464
.set('Accept-Encoding', 'gzip')
494465
.request()
495466
.on('response', function (res) {
496-
res.headers['content-encoding'].should.equal('gzip')
467+
assert.equal(res.headers['content-encoding'], 'gzip')
497468
res.on('data', write)
498469
res.on('end', function(){
499-
chunks.should.equal(20)
470+
assert.equal(chunks, 20)
500471
done()
501472
})
502473
})
@@ -525,10 +496,10 @@ describe('compress()', function(){
525496
.set('Accept-Encoding', 'deflate')
526497
.request()
527498
.on('response', function (res) {
528-
res.headers['content-encoding'].should.equal('deflate')
499+
assert.equal(res.headers['content-encoding'], 'deflate')
529500
res.on('data', write)
530501
res.on('end', function(){
531-
chunks.should.equal(20)
502+
assert.equal(chunks, 20)
532503
done()
533504
})
534505
})
@@ -551,3 +522,15 @@ function createServer(opts, fn) {
551522
})
552523
})
553524
}
525+
526+
function shouldHaveBodyLength(length) {
527+
return function (res) {
528+
assert.equal(res.text.length, length, 'should have body length of ' + length)
529+
}
530+
}
531+
532+
function shouldNotHaveHeader(header) {
533+
return function (res) {
534+
assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header)
535+
}
536+
}

0 commit comments

Comments
 (0)