Skip to content
Permalink
Browse files

build: supertest@3.3.0

  • Loading branch information...
dougwilson committed Sep 25, 2018
1 parent f07f368 commit 451ee5d9c17b8abd6859b939a5edfa083a61127d
Showing with 79 additions and 14 deletions.
  1. +6 −0 .travis.yml
  2. +6 −0 appveyor.yml
  3. +1 −1 package.json
  4. +2 −6 test/app.router.js
  5. +12 −1 test/res.download.js
  6. +13 −2 test/res.redirect.js
  7. +22 −2 test/res.send.js
  8. +17 −2 test/res.sendFile.js
@@ -39,6 +39,12 @@ before_install:
if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 6 ]]; then
npm install --silent --save-dev mocha@3.5.3
fi
- |
# supertest for http calls
# - use 2.0.0 for Node.js < 4
if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 4 ]]; then
npm install --silent --save-dev supertest@2.0.0
fi
# Update Node.js modules
- |
# Prune and rebuild node_modules
@@ -32,6 +32,12 @@ install:
if ($env:nodejs_version.split(".")[0] -lt 6) {
npm install --silent --save-dev mocha@3.5.3
}
- ps: |
# supertest for http calls
# - use 2.0.0 for Node.js < 4
if ($env:nodejs_version.split(".")[0] -lt 4) {
npm install --silent --save-dev supertest@2.0.0
}
# Update Node.js modules
- ps: |
# Prune & rebuild node_modules
@@ -74,7 +74,7 @@
"multiparty": "4.2.1",
"pbkdf2-password": "1.2.1",
"should": "13.2.3",
"supertest": "2.0.0",
"supertest": "3.3.0",
"connect-redis": "~2.4.1",
"vhost": "~3.0.2"
},
@@ -41,16 +41,12 @@ describe('app.router', function(){
var app = express();

app[method]('/foo', function(req, res){
if (method === 'head') {
res.end();
} else {
res.end(method);
}
res.send(method)
});

request(app)
[method]('/foo')
.expect(method === 'head' ? '' : method, done)
.expect(200, done)
})

it('should reject numbers for app.' + method, function(){
@@ -1,6 +1,7 @@

var after = require('after');
var assert = require('assert');
var Buffer = require('safe-buffer').Buffer
var express = require('..');
var request = require('supertest');

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

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

function shouldHaveBody (buf) {
return function (res) {
var body = !Buffer.isBuffer(res.body)
? Buffer.from(res.text)
: res.body
assert.ok(body, 'response has body')
assert.strictEqual(body.toString('hex'), buf.toString('hex'))
}
}

function shouldNotHaveHeader(header) {
return function (res) {
assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header);
@@ -1,4 +1,5 @@

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

request(app)
.head('/')
.expect(302)
.expect('Location', 'http://google.com')
.expect(302, '', done)
.expect(shouldNotHaveBody())
.end(done)
})
})

@@ -197,10 +200,18 @@ describe('res', function(){
request(app)
.get('/')
.set('Accept', 'application/octet-stream')
.expect(302)
.expect('location', 'http://google.com')
.expect('content-length', '0')
.expect(utils.shouldNotHaveHeader('Content-Type'))
.expect(302, '', done)
.expect(shouldNotHaveBody())
.end(done)
})
})
})

function shouldNotHaveBody () {
return function (res) {
assert.ok(res.text === '' || res.text === undefined)
}
}
@@ -188,8 +188,10 @@ describe('res', function(){

request(app)
.get('/')
.expect(200)
.expect('Content-Type', 'application/octet-stream')
.expect(200, 'hello', done);
.expect(shouldHaveBody(Buffer.from('hello')))
.end(done)
})

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

request(app)
.head('/')
.expect('', done);
.expect(200)
.expect(shouldNotHaveBody())
.end(done)
})
})

@@ -573,3 +577,19 @@ describe('res', function(){
})
})
})

function shouldHaveBody (buf) {
return function (res) {
var body = !Buffer.isBuffer(res.body)
? Buffer.from(res.text)
: res.body
assert.ok(body, 'response has body')
assert.strictEqual(body.toString('hex'), buf.toString('hex'))
}
}

function shouldNotHaveBody () {
return function (res) {
assert.ok(res.text === '' || res.text === undefined)
}
}
@@ -1,5 +1,6 @@

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

request(app)
.get('/')
.expect(200, 'tobi', done);
.expect(200)
.expect(shouldHaveBody(Buffer.from('tobi')))
.end(done)
});
});

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

request(app)
.get('/')
.expect(200, 'tobi', done);
.expect(200)
.expect(shouldHaveBody(Buffer.from('tobi')))
.end(done)
})

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

return app;
}

function shouldHaveBody (buf) {
return function (res) {
var body = !Buffer.isBuffer(res.body)
? Buffer.from(res.text)
: res.body
assert.ok(body, 'response has body')
assert.strictEqual(body.toString('hex'), buf.toString('hex'))
}
}

0 comments on commit 451ee5d

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.