Skip to content

Commit 451ee5d

Browse files
committed
1 parent f07f368 commit 451ee5d

File tree

8 files changed

+79
-14
lines changed

8 files changed

+79
-14
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ before_install:
3939
if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 6 ]]; then
4040
npm install --silent --save-dev [email protected]
4141
fi
42+
- |
43+
# supertest for http calls
44+
# - use 2.0.0 for Node.js < 4
45+
if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 4 ]]; then
46+
npm install --silent --save-dev [email protected]
47+
fi
4248
# Update Node.js modules
4349
- |
4450
# Prune and rebuild node_modules

appveyor.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ install:
3232
if ($env:nodejs_version.split(".")[0] -lt 6) {
3333
npm install --silent --save-dev [email protected]
3434
}
35+
- ps: |
36+
# supertest for http calls
37+
# - use 2.0.0 for Node.js < 4
38+
if ($env:nodejs_version.split(".")[0] -lt 4) {
39+
npm install --silent --save-dev [email protected]
40+
}
3541
# Update Node.js modules
3642
- ps: |
3743
# Prune & rebuild node_modules

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"multiparty": "4.2.1",
7575
"pbkdf2-password": "1.2.1",
7676
"should": "13.2.3",
77-
"supertest": "2.0.0",
77+
"supertest": "3.3.0",
7878
"connect-redis": "~2.4.1",
7979
"vhost": "~3.0.2"
8080
},

test/app.router.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,12 @@ describe('app.router', function(){
4141
var app = express();
4242

4343
app[method]('/foo', function(req, res){
44-
if (method === 'head') {
45-
res.end();
46-
} else {
47-
res.end(method);
48-
}
44+
res.send(method)
4945
});
5046

5147
request(app)
5248
[method]('/foo')
53-
.expect(method === 'head' ? '' : method, done)
49+
.expect(200, done)
5450
})
5551

5652
it('should reject numbers for app.' + method, function(){

test/res.download.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
var after = require('after');
33
var assert = require('assert');
4+
var Buffer = require('safe-buffer').Buffer
45
var express = require('..');
56
var request = require('supertest');
67

@@ -104,7 +105,7 @@ describe('res', function(){
104105
.expect(200)
105106
.expect('Content-Disposition', 'attachment; filename="document"')
106107
.expect('Cache-Control', 'public, max-age=14400')
107-
.expect('tobi')
108+
.expect(shouldHaveBody(Buffer.from('tobi')))
108109
.end(done)
109110
})
110111

@@ -185,6 +186,16 @@ describe('res', function(){
185186
})
186187
})
187188

189+
function shouldHaveBody (buf) {
190+
return function (res) {
191+
var body = !Buffer.isBuffer(res.body)
192+
? Buffer.from(res.text)
193+
: res.body
194+
assert.ok(body, 'response has body')
195+
assert.strictEqual(body.toString('hex'), buf.toString('hex'))
196+
}
197+
}
198+
188199
function shouldNotHaveHeader(header) {
189200
return function (res) {
190201
assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header);

test/res.redirect.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
var assert = require('assert')
23
var express = require('..');
34
var request = require('supertest');
45
var utils = require('./support/utils');
@@ -85,8 +86,10 @@ describe('res', function(){
8586

8687
request(app)
8788
.head('/')
89+
.expect(302)
8890
.expect('Location', 'http://google.com')
89-
.expect(302, '', done)
91+
.expect(shouldNotHaveBody())
92+
.end(done)
9093
})
9194
})
9295

@@ -197,10 +200,18 @@ describe('res', function(){
197200
request(app)
198201
.get('/')
199202
.set('Accept', 'application/octet-stream')
203+
.expect(302)
200204
.expect('location', 'http://google.com')
201205
.expect('content-length', '0')
202206
.expect(utils.shouldNotHaveHeader('Content-Type'))
203-
.expect(302, '', done)
207+
.expect(shouldNotHaveBody())
208+
.end(done)
204209
})
205210
})
206211
})
212+
213+
function shouldNotHaveBody () {
214+
return function (res) {
215+
assert.ok(res.text === '' || res.text === undefined)
216+
}
217+
}

test/res.send.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,10 @@ describe('res', function(){
188188

189189
request(app)
190190
.get('/')
191+
.expect(200)
191192
.expect('Content-Type', 'application/octet-stream')
192-
.expect(200, 'hello', done);
193+
.expect(shouldHaveBody(Buffer.from('hello')))
194+
.end(done)
193195
})
194196

195197
it('should set ETag', function (done) {
@@ -257,7 +259,9 @@ describe('res', function(){
257259

258260
request(app)
259261
.head('/')
260-
.expect('', done);
262+
.expect(200)
263+
.expect(shouldNotHaveBody())
264+
.end(done)
261265
})
262266
})
263267

@@ -573,3 +577,19 @@ describe('res', function(){
573577
})
574578
})
575579
})
580+
581+
function shouldHaveBody (buf) {
582+
return function (res) {
583+
var body = !Buffer.isBuffer(res.body)
584+
? Buffer.from(res.text)
585+
: res.body
586+
assert.ok(body, 'response has body')
587+
assert.strictEqual(body.toString('hex'), buf.toString('hex'))
588+
}
589+
}
590+
591+
function shouldNotHaveBody () {
592+
return function (res) {
593+
assert.ok(res.text === '' || res.text === undefined)
594+
}
595+
}

test/res.sendFile.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
var after = require('after');
3+
var Buffer = require('safe-buffer').Buffer
34
var express = require('../')
45
, request = require('supertest')
56
, assert = require('assert');
@@ -155,7 +156,9 @@ describe('res', function(){
155156

156157
request(app)
157158
.get('/')
158-
.expect(200, 'tobi', done);
159+
.expect(200)
160+
.expect(shouldHaveBody(Buffer.from('tobi')))
161+
.end(done)
159162
});
160163
});
161164

@@ -548,7 +551,9 @@ describe('res', function(){
548551

549552
request(app)
550553
.get('/')
551-
.expect(200, 'tobi', done);
554+
.expect(200)
555+
.expect(shouldHaveBody(Buffer.from('tobi')))
556+
.end(done)
552557
})
553558

554559
it('should accept headers option', function(done){
@@ -801,3 +806,13 @@ function createApp(path, options, fn) {
801806

802807
return app;
803808
}
809+
810+
function shouldHaveBody (buf) {
811+
return function (res) {
812+
var body = !Buffer.isBuffer(res.body)
813+
? Buffer.from(res.text)
814+
: res.body
815+
assert.ok(body, 'response has body')
816+
assert.strictEqual(body.toString('hex'), buf.toString('hex'))
817+
}
818+
}

0 commit comments

Comments
 (0)