mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 12:19:51 +01:00
build: supertest@3.3.0
This commit is contained in:
parent
f07f368fba
commit
451ee5d9c1
|
|
@ -39,6 +39,12 @@ before_install:
|
||||||
if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 6 ]]; then
|
if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 6 ]]; then
|
||||||
npm install --silent --save-dev mocha@3.5.3
|
npm install --silent --save-dev mocha@3.5.3
|
||||||
fi
|
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
|
# Update Node.js modules
|
||||||
- |
|
- |
|
||||||
# Prune and rebuild node_modules
|
# Prune and rebuild node_modules
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,12 @@ install:
|
||||||
if ($env:nodejs_version.split(".")[0] -lt 6) {
|
if ($env:nodejs_version.split(".")[0] -lt 6) {
|
||||||
npm install --silent --save-dev mocha@3.5.3
|
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
|
# Update Node.js modules
|
||||||
- ps: |
|
- ps: |
|
||||||
# Prune & rebuild node_modules
|
# Prune & rebuild node_modules
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@
|
||||||
"multiparty": "4.2.1",
|
"multiparty": "4.2.1",
|
||||||
"pbkdf2-password": "1.2.1",
|
"pbkdf2-password": "1.2.1",
|
||||||
"should": "13.2.3",
|
"should": "13.2.3",
|
||||||
"supertest": "2.0.0",
|
"supertest": "3.3.0",
|
||||||
"connect-redis": "~2.4.1",
|
"connect-redis": "~2.4.1",
|
||||||
"vhost": "~3.0.2"
|
"vhost": "~3.0.2"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -41,16 +41,12 @@ describe('app.router', function(){
|
||||||
var app = express();
|
var app = express();
|
||||||
|
|
||||||
app[method]('/foo', function(req, res){
|
app[method]('/foo', function(req, res){
|
||||||
if (method === 'head') {
|
res.send(method)
|
||||||
res.end();
|
|
||||||
} else {
|
|
||||||
res.end(method);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
request(app)
|
request(app)
|
||||||
[method]('/foo')
|
[method]('/foo')
|
||||||
.expect(method === 'head' ? '' : method, done)
|
.expect(200, done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should reject numbers for app.' + method, function(){
|
it('should reject numbers for app.' + method, function(){
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
var after = require('after');
|
var after = require('after');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
var Buffer = require('safe-buffer').Buffer
|
||||||
var express = require('..');
|
var express = require('..');
|
||||||
var request = require('supertest');
|
var request = require('supertest');
|
||||||
|
|
||||||
|
|
@ -104,7 +105,7 @@ describe('res', function(){
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.expect('Content-Disposition', 'attachment; filename="document"')
|
.expect('Content-Disposition', 'attachment; filename="document"')
|
||||||
.expect('Cache-Control', 'public, max-age=14400')
|
.expect('Cache-Control', 'public, max-age=14400')
|
||||||
.expect('tobi')
|
.expect(shouldHaveBody(Buffer.from('tobi')))
|
||||||
.end(done)
|
.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) {
|
function shouldNotHaveHeader(header) {
|
||||||
return function (res) {
|
return function (res) {
|
||||||
assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header);
|
assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
|
|
||||||
|
var assert = require('assert')
|
||||||
var express = require('..');
|
var express = require('..');
|
||||||
var request = require('supertest');
|
var request = require('supertest');
|
||||||
var utils = require('./support/utils');
|
var utils = require('./support/utils');
|
||||||
|
|
@ -85,8 +86,10 @@ describe('res', function(){
|
||||||
|
|
||||||
request(app)
|
request(app)
|
||||||
.head('/')
|
.head('/')
|
||||||
|
.expect(302)
|
||||||
.expect('Location', 'http://google.com')
|
.expect('Location', 'http://google.com')
|
||||||
.expect(302, '', done)
|
.expect(shouldNotHaveBody())
|
||||||
|
.end(done)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -197,10 +200,18 @@ describe('res', function(){
|
||||||
request(app)
|
request(app)
|
||||||
.get('/')
|
.get('/')
|
||||||
.set('Accept', 'application/octet-stream')
|
.set('Accept', 'application/octet-stream')
|
||||||
|
.expect(302)
|
||||||
.expect('location', 'http://google.com')
|
.expect('location', 'http://google.com')
|
||||||
.expect('content-length', '0')
|
.expect('content-length', '0')
|
||||||
.expect(utils.shouldNotHaveHeader('Content-Type'))
|
.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)
|
request(app)
|
||||||
.get('/')
|
.get('/')
|
||||||
|
.expect(200)
|
||||||
.expect('Content-Type', 'application/octet-stream')
|
.expect('Content-Type', 'application/octet-stream')
|
||||||
.expect(200, 'hello', done);
|
.expect(shouldHaveBody(Buffer.from('hello')))
|
||||||
|
.end(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should set ETag', function (done) {
|
it('should set ETag', function (done) {
|
||||||
|
|
@ -257,7 +259,9 @@ describe('res', function(){
|
||||||
|
|
||||||
request(app)
|
request(app)
|
||||||
.head('/')
|
.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 after = require('after');
|
||||||
|
var Buffer = require('safe-buffer').Buffer
|
||||||
var express = require('../')
|
var express = require('../')
|
||||||
, request = require('supertest')
|
, request = require('supertest')
|
||||||
, assert = require('assert');
|
, assert = require('assert');
|
||||||
|
|
@ -155,7 +156,9 @@ describe('res', function(){
|
||||||
|
|
||||||
request(app)
|
request(app)
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect(200, 'tobi', done);
|
.expect(200)
|
||||||
|
.expect(shouldHaveBody(Buffer.from('tobi')))
|
||||||
|
.end(done)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -548,7 +551,9 @@ describe('res', function(){
|
||||||
|
|
||||||
request(app)
|
request(app)
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect(200, 'tobi', done);
|
.expect(200)
|
||||||
|
.expect(shouldHaveBody(Buffer.from('tobi')))
|
||||||
|
.end(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should accept headers option', function(done){
|
it('should accept headers option', function(done){
|
||||||
|
|
@ -801,3 +806,13 @@ function createApp(path, options, fn) {
|
||||||
|
|
||||||
return app;
|
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'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user