Comparing version 3.2.0 to 3.3.0
@@ -0,21 +1,27 @@ | ||
3.3.0 / 2018-09-06 | ||
=================== | ||
* PR-509 - Fix #486, bug in _assertBody, switch to `deepStrictEqual` (thanks @mikelax) | ||
* PR-510 - Refactor test files to use const/let (thanks @rimiti) | ||
3.2.0 / 2018-09-05 | ||
=================== | ||
* PR-507 - Ignore coverage folder (thanks @rimiti) | ||
* PR-506 - Fix Coveralls timeouts on Travis (thanks @rimiti) | ||
* PR-505 - Use node 10 instead of node 9 (thanks @rimiti) | ||
* PR-504 - Coverage + Coveralls integration (thanks @rimiti) | ||
* PR-503 - Dependencies updated (thanks @rimiti) | ||
* PR-495 - Fix example in README.md (thanks @Otto-AA) | ||
* PR-507 - Ignore coverage folder (thanks @rimiti) | ||
* PR-506 - Fix Coveralls timeouts on Travis (thanks @rimiti) | ||
* PR-505 - Use node 10 instead of node 9 (thanks @rimiti) | ||
* PR-504 - Coverage + Coveralls integration (thanks @rimiti) | ||
* PR-503 - Dependencies updated (thanks @rimiti) | ||
* PR-495 - Fix example in README.md (thanks @Otto-AA) | ||
3.1.0 / 2018-04-24 | ||
=================== | ||
* PR-473 - Remove unused dependency in Readme (thanks @pedro-otero) | ||
* PR-472 - Update travis node versions (thanks @rimiti) | ||
* PR-470 - Upgrade the superagent node module to resolve security vulnerabilities & fix the __proto__ property deprecation (thanks @levioza) | ||
* PR-446 - Fix bug, always pass on errors if no response (thanks @bkeepers) | ||
* PR-418 - Add post() examples to the README (thanks @kevinburke) | ||
* PR-297 - Add a .host() method to set a host other than 127.0.0.1 (thanks @mikec) | ||
* PR-275 - Removed ambiguously misappropriated cultural references from readme (thanks @reallistic) | ||
* PR-473 - Remove unused dependency in Readme (thanks @pedro-otero) | ||
* PR-472 - Update travis node versions (thanks @rimiti) | ||
* PR-470 - Upgrade the superagent node module to resolve security vulnerabilities & fix the __proto__ property deprecation (thanks @levioza) | ||
* PR-446 - Fix bug, always pass on errors if no response (thanks @bkeepers) | ||
* PR-418 - Add post() examples to the README (thanks @kevinburke) | ||
* PR-297 - Add a .host() method to set a host other than 127.0.0.1 (thanks @mikec) | ||
* PR-275 - Removed ambiguously misappropriated cultural references from readme (thanks @reallistic) | ||
@@ -25,5 +31,5 @@ 3.0.0 / 2017-01-29 | ||
* PR-373 - Allow TestAgent pass a cert and key to request (thanks @toefraz) | ||
* PR-392 - Update readme with promise example (thanks @ajouve) | ||
* PR-400 - Update to superagent 3 (thanks @alphashuro) | ||
* PR-373 - Allow TestAgent pass a cert and key to request (thanks @toefraz) | ||
* PR-392 - Update readme with promise example (thanks @ajouve) | ||
* PR-400 - Update to superagent 3 (thanks @alphashuro) | ||
@@ -30,0 +36,0 @@ 2.0.1 / 2016-10-19 |
@@ -201,3 +201,3 @@ /** | ||
try { | ||
assert.deepEqual(body, res.body); | ||
assert.deepStrictEqual(body, res.body); | ||
} catch (err) { | ||
@@ -204,0 +204,0 @@ a = util.inspect(body); |
{ | ||
"name": "supertest", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"description": "SuperAgent driven library for testing HTTP servers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,24 +0,24 @@ | ||
var request = require('..'); | ||
var https = require('https'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var should = require('should'); | ||
var express = require('express'); | ||
var bodyParser = require('body-parser'); | ||
var cookieParser = require('cookie-parser'); | ||
var nock = require('nock'); | ||
const request = require('..'); | ||
const https = require('https'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const should = require('should'); | ||
const express = require('express'); | ||
const bodyParser = require('body-parser'); | ||
const cookieParser = require('cookie-parser'); | ||
const nock = require('nock'); | ||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; | ||
describe('request(url)', function() { | ||
it('should be supported', function(done) { | ||
var app = express(); | ||
var s; | ||
describe('request(url)', function () { | ||
it('should be supported', function (done) { | ||
const app = express(); | ||
let s; | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('hello'); | ||
}); | ||
s = app.listen(function() { | ||
var url = 'http://localhost:' + s.address().port; | ||
s = app.listen(function () { | ||
const url = 'http://localhost:' + s.address().port; | ||
request(url) | ||
@@ -30,15 +30,15 @@ .get('/') | ||
describe('.end(cb)', function() { | ||
it('should set `this` to the test object when calling cb', function(done) { | ||
var app = express(); | ||
var s; | ||
describe('.end(cb)', function () { | ||
it('should set `this` to the test object when calling cb', function (done) { | ||
const app = express(); | ||
let s; | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('hello'); | ||
}); | ||
s = app.listen(function() { | ||
var url = 'http://localhost:' + s.address().port; | ||
var test = request(url).get('/'); | ||
test.end(function(err, res) { | ||
s = app.listen(function () { | ||
const url = 'http://localhost:' + s.address().port; | ||
const test = request(url).get('/'); | ||
test.end(function (err, res) { | ||
this.should.eql(test); | ||
@@ -52,7 +52,7 @@ done(); | ||
describe('request(app)', function() { | ||
it('should fire up the app on an ephemeral port', function(done) { | ||
var app = express(); | ||
describe('request(app)', function () { | ||
it('should fire up the app on an ephemeral port', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('hey'); | ||
@@ -63,3 +63,3 @@ }); | ||
.get('/') | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
res.status.should.equal(200); | ||
@@ -71,14 +71,14 @@ res.text.should.equal('hey'); | ||
it('should work with an active server', function(done) { | ||
var app = express(); | ||
var server; | ||
it('should work with an active server', function (done) { | ||
const app = express(); | ||
let server; | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('hey'); | ||
}); | ||
server = app.listen(4000, function() { | ||
server = app.listen(4000, function () { | ||
request(server) | ||
.get('/') | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
res.status.should.equal(200); | ||
@@ -91,13 +91,13 @@ res.text.should.equal('hey'); | ||
it('should work with remote server', function(done) { | ||
var app = express(); | ||
it('should work with remote server', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('hey'); | ||
}); | ||
app.listen(4001, function() { | ||
app.listen(4001, function () { | ||
request('http://localhost:4001') | ||
.get('/') | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
res.status.should.equal(200); | ||
@@ -110,6 +110,6 @@ res.text.should.equal('hey'); | ||
it('should work with a https server', function(done) { | ||
var app = express(); | ||
var fixtures = path.join(__dirname, 'fixtures'); | ||
var server = https.createServer({ | ||
it('should work with a https server', function (done) { | ||
const app = express(); | ||
const fixtures = path.join(__dirname, 'fixtures'); | ||
const server = https.createServer({ | ||
key: fs.readFileSync(path.join(fixtures, 'test_key.pem')), | ||
@@ -119,3 +119,3 @@ cert: fs.readFileSync(path.join(fixtures, 'test_cert.pem')) | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('hey'); | ||
@@ -126,3 +126,3 @@ }); | ||
.get('/') | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
if (err) return done(err); | ||
@@ -135,8 +135,8 @@ res.status.should.equal(200); | ||
it('should work with .send() etc', function(done) { | ||
var app = express(); | ||
it('should work with .send() etc', function (done) { | ||
const app = express(); | ||
app.use(bodyParser.json()); | ||
app.post('/', function(req, res) { | ||
app.post('/', function (req, res) { | ||
res.send(req.body.name); | ||
@@ -151,6 +151,6 @@ }); | ||
it('should work when unbuffered', function(done) { | ||
var app = express(); | ||
it('should work when unbuffered', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.end('Hello'); | ||
@@ -164,6 +164,6 @@ }); | ||
it('should default redirects to 0', function(done) { | ||
var app = express(); | ||
it('should default redirects to 0', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.redirect('/login'); | ||
@@ -177,4 +177,4 @@ }); | ||
it('should handle redirects', function(done) { | ||
var app = express(); | ||
it('should handle redirects', function (done) { | ||
const app = express(); | ||
@@ -185,3 +185,3 @@ app.get('/login', function (req, res) { | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.redirect('/login'); | ||
@@ -201,6 +201,6 @@ }); | ||
it('should handle socket errors', function(done) { | ||
var app = express(); | ||
it('should handle socket errors', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.destroy(); | ||
@@ -211,3 +211,3 @@ }); | ||
.get('/') | ||
.end(function(err) { | ||
.end(function (err) { | ||
should.exist(err); | ||
@@ -218,8 +218,8 @@ done(); | ||
describe('.end(fn)', function() { | ||
it('should close server', function(done) { | ||
var app = express(); | ||
var test; | ||
describe('.end(fn)', function () { | ||
it('should close server', function (done) { | ||
const app = express(); | ||
let test; | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('supertest FTW!'); | ||
@@ -230,5 +230,6 @@ }); | ||
.get('/') | ||
.end(function() {}); | ||
.end(function () { | ||
}); | ||
test._server.on('close', function() { | ||
test._server.on('close', function () { | ||
done(); | ||
@@ -238,8 +239,8 @@ }); | ||
it('should wait for server to close before invoking fn', function(done) { | ||
var app = express(); | ||
var closed = false; | ||
var test; | ||
it('should wait for server to close before invoking fn', function (done) { | ||
const app = express(); | ||
let closed = false; | ||
let test; | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('supertest FTW!'); | ||
@@ -250,3 +251,3 @@ }); | ||
.get('/') | ||
.end(function() { | ||
.end(function () { | ||
closed.should.be.true; | ||
@@ -256,3 +257,3 @@ done(); | ||
test._server.on('close', function() { | ||
test._server.on('close', function () { | ||
closed = true; | ||
@@ -262,7 +263,7 @@ }); | ||
it('should support nested requests', function(done) { | ||
var app = express(); | ||
var test = request(app); | ||
it('should support nested requests', function (done) { | ||
const app = express(); | ||
const test = request(app); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('supertest FTW!'); | ||
@@ -273,6 +274,6 @@ }); | ||
.get('/') | ||
.end(function() { | ||
.end(function () { | ||
test | ||
.get('/') | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
(err === null).should.be.true; | ||
@@ -286,6 +287,6 @@ res.status.should.equal(200); | ||
it('should include the response in the error callback', function(done) { | ||
var app = express(); | ||
it('should include the response in the error callback', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('whatever'); | ||
@@ -296,6 +297,6 @@ }); | ||
.get('/') | ||
.expect(function() { | ||
.expect(function () { | ||
throw new Error('Some error'); | ||
}) | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
should.exist(err); | ||
@@ -309,7 +310,7 @@ should.exist(res); | ||
it('should set `this` to the test object when calling the error callback', function(done) { | ||
var app = express(); | ||
var test; | ||
it('should set `this` to the test object when calling the error callback', function (done) { | ||
const app = express(); | ||
let test; | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('whatever'); | ||
@@ -319,5 +320,5 @@ }); | ||
test = request(app).get('/'); | ||
test.expect(function() { | ||
test.expect(function () { | ||
throw new Error('Some error'); | ||
}).end(function(err, res) { | ||
}).end(function (err, res) { | ||
should.exist(err); | ||
@@ -330,6 +331,6 @@ this.should.eql(test); | ||
it('should handle an undefined Response', function (done) { | ||
var app = express(); | ||
var server; | ||
const app = express(); | ||
let server; | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
setTimeout(function () { | ||
@@ -340,4 +341,4 @@ res.end(); | ||
server = app.listen(function() { | ||
var url = 'http://localhost:' + server.address().port; | ||
server = app.listen(function () { | ||
const url = 'http://localhost:' + server.address().port; | ||
request(url) | ||
@@ -354,11 +355,11 @@ .get('/') | ||
it('should handle error returned when server goes down', function (done) { | ||
var app = express(); | ||
var server; | ||
const app = express(); | ||
let server; | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.end(); | ||
}); | ||
server = app.listen(function() { | ||
var url = 'http://localhost:' + server.address().port; | ||
server = app.listen(function () { | ||
const url = 'http://localhost:' + server.address().port; | ||
server.close(); | ||
@@ -375,7 +376,7 @@ request(url) | ||
describe('.expect(status[, fn])', function() { | ||
it('should assert the response status', function(done) { | ||
var app = express(); | ||
describe('.expect(status[, fn])', function () { | ||
it('should assert the response status', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('hey'); | ||
@@ -387,3 +388,3 @@ }); | ||
.expect(404) | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
err.message.should.equal('expected 404 "Not Found", got 200 "OK"'); | ||
@@ -397,3 +398,3 @@ done(); | ||
it('should handle connection error', function (done) { | ||
var req = request.agent('http://localhost:1234'); | ||
const req = request.agent('http://localhost:1234'); | ||
@@ -412,3 +413,3 @@ req | ||
it('should assert only status', function (done) { | ||
var app = express(); | ||
const app = express(); | ||
@@ -426,7 +427,7 @@ app.get('/', function (req, res) { | ||
describe('.expect(status, body[, fn])', function() { | ||
it('should assert the response body and status', function(done) { | ||
var app = express(); | ||
describe('.expect(status, body[, fn])', function () { | ||
it('should assert the response body and status', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('foo'); | ||
@@ -440,7 +441,7 @@ }); | ||
describe('when the body argument is an empty string', function() { | ||
it('should not quietly pass on failure', function(done) { | ||
var app = express(); | ||
describe('when the body argument is an empty string', function () { | ||
it('should not quietly pass on failure', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('foo'); | ||
@@ -452,3 +453,3 @@ }); | ||
.expect(200, '') | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
err.message.should.equal('expected \'\' response body, got \'foo\''); | ||
@@ -461,9 +462,9 @@ done(); | ||
describe('.expect(body[, fn])', function() { | ||
it('should assert the response body', function(done) { | ||
var app = express(); | ||
describe('.expect(body[, fn])', function () { | ||
it('should assert the response body', function (done) { | ||
const app = express(); | ||
app.set('json spaces', 0); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send({ foo: 'bar' }); | ||
@@ -475,3 +476,3 @@ }); | ||
.expect('hey') | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
err.message.should.equal('expected \'hey\' response body, got \'{"foo":"bar"}\''); | ||
@@ -483,7 +484,7 @@ done(); | ||
it('should assert the status before the body', function (done) { | ||
var app = express(); | ||
const app = express(); | ||
app.set('json spaces', 0); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.status(500).send({ message: 'something went wrong' }); | ||
@@ -496,3 +497,3 @@ }); | ||
.expect('hey') | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
err.message.should.equal('expected 200 "OK", got 500 "Internal Server Error"'); | ||
@@ -503,8 +504,8 @@ done(); | ||
it('should assert the response text', function(done) { | ||
var app = express(); | ||
it('should assert the response text', function (done) { | ||
const app = express(); | ||
app.set('json spaces', 0); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send({ foo: 'bar' }); | ||
@@ -518,8 +519,8 @@ }); | ||
it('should assert the parsed response body', function(done) { | ||
var app = express(); | ||
it('should assert the parsed response body', function (done) { | ||
const app = express(); | ||
app.set('json spaces', 0); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send({ foo: 'bar' }); | ||
@@ -531,3 +532,3 @@ }); | ||
.expect({ foo: 'baz' }) | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
err.message.should.equal('expected { foo: \'baz\' } response body, got { foo: \'bar\' }'); | ||
@@ -542,6 +543,37 @@ | ||
it('should support regular expressions', function(done) { | ||
var app = express(); | ||
it('should test response object types', function (done) { | ||
const app = express(); | ||
app.get('/', function (req, res) { | ||
res.status(200).json({ stringValue: 'foo', numberValue: 3 }); | ||
}); | ||
app.get('/', function(req, res) { | ||
request(app) | ||
.get('/') | ||
.expect({ stringValue: 'foo', numberValue: 3 }, done); | ||
}); | ||
it('should deep test response object types', function (done) { | ||
const app = express(); | ||
app.get('/', function (req, res) { | ||
res.status(200) | ||
.json({ stringValue: 'foo', numberValue: 3, nestedObject: { innerString: '5' } }); | ||
}); | ||
request(app) | ||
.get('/') | ||
.expect({ stringValue: 'foo', numberValue: 3, nestedObject: { innerString: 5 } }) | ||
.end(function (err, res) { | ||
err.message.should.equal('expected { stringValue: \'foo\',\n numberValue: 3,\n nestedObject: { innerString: 5 } } response body, got { stringValue: \'foo\',\n numberValue: 3,\n nestedObject: { innerString: \'5\' } }'); // eslint-disable-line max-len | ||
request(app) | ||
.get('/') | ||
.expect({ stringValue: 'foo', numberValue: 3, nestedObject: { innerString: '5' } }) | ||
.end(done); | ||
}); | ||
}); | ||
it('should support regular expressions', function (done) { | ||
const app = express(); | ||
app.get('/', function (req, res) { | ||
res.send('foobar'); | ||
@@ -553,3 +585,3 @@ }); | ||
.expect(/^bar/) | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
err.message.should.equal('expected body \'foobar\' to match /^bar/'); | ||
@@ -560,6 +592,6 @@ done(); | ||
it('should assert response body multiple times', function(done) { | ||
var app = express(); | ||
it('should assert response body multiple times', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('hey tj'); | ||
@@ -579,6 +611,6 @@ }); | ||
it('should assert response body multiple times with no exception', function(done) { | ||
var app = express(); | ||
it('should assert response body multiple times with no exception', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('hey tj'); | ||
@@ -595,7 +627,7 @@ }); | ||
describe('.expect(field, value[, fn])', function() { | ||
it('should assert the header field presence', function(done) { | ||
var app = express(); | ||
describe('.expect(field, value[, fn])', function () { | ||
it('should assert the header field presence', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send({ foo: 'bar' }); | ||
@@ -607,3 +639,3 @@ }); | ||
.expect('Content-Foo', 'bar') | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
err.message.should.equal('expected "Content-Foo" header field'); | ||
@@ -614,6 +646,6 @@ done(); | ||
it('should assert the header field value', function(done) { | ||
var app = express(); | ||
it('should assert the header field value', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send({ foo: 'bar' }); | ||
@@ -625,5 +657,5 @@ }); | ||
.expect('Content-Type', 'text/html') | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
err.message.should.equal('expected "Content-Type" of "text/html", ' | ||
+ 'got "application/json; charset=utf-8"'); | ||
+ 'got "application/json; charset=utf-8"'); | ||
done(); | ||
@@ -633,6 +665,6 @@ }); | ||
it('should assert multiple fields', function(done) { | ||
var app = express(); | ||
it('should assert multiple fields', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('hey'); | ||
@@ -648,6 +680,6 @@ }); | ||
it('should support regular expressions', function(done) { | ||
var app = express(); | ||
it('should support regular expressions', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('hey'); | ||
@@ -659,5 +691,5 @@ }); | ||
.expect('Content-Type', /^application/) | ||
.end(function(err) { | ||
.end(function (err) { | ||
err.message.should.equal('expected "Content-Type" matching /^application/, ' | ||
+ 'got "text/html; charset=utf-8"'); | ||
+ 'got "text/html; charset=utf-8"'); | ||
done(); | ||
@@ -667,6 +699,6 @@ }); | ||
it('should support numbers', function(done) { | ||
var app = express(); | ||
it('should support numbers', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('hey'); | ||
@@ -678,3 +710,3 @@ }); | ||
.expect('Content-Length', 4) | ||
.end(function(err) { | ||
.end(function (err) { | ||
err.message.should.equal('expected "Content-Length" of "4", got "3"'); | ||
@@ -685,9 +717,9 @@ done(); | ||
describe('handling arbitrary expect functions', function() { | ||
var app; | ||
var get; | ||
describe('handling arbitrary expect functions', function () { | ||
let app; | ||
let get; | ||
before(function() { | ||
before(function () { | ||
app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send('hey'); | ||
@@ -697,12 +729,12 @@ }); | ||
beforeEach(function() { | ||
beforeEach(function () { | ||
get = request(app).get('/'); | ||
}); | ||
it('reports errors', function(done) { | ||
it('reports errors', function (done) { | ||
get | ||
.expect(function(res) { | ||
.expect(function (res) { | ||
throw new Error('failed'); | ||
}) | ||
.end(function(err) { | ||
.end(function (err) { | ||
err.message.should.equal('failed'); | ||
@@ -715,8 +747,8 @@ done(); | ||
'ensures truthy non-errors returned from asserts are not promoted to errors', | ||
function(done) { | ||
function (done) { | ||
get | ||
.expect(function(res) { | ||
.expect(function (res) { | ||
return 'some descriptive error'; | ||
}) | ||
.end(function(err) { | ||
.end(function (err) { | ||
should.not.exist(err); | ||
@@ -728,8 +760,8 @@ done(); | ||
it('ensures truthy errors returned from asserts are throw to end', function(done) { | ||
it('ensures truthy errors returned from asserts are throw to end', function (done) { | ||
get | ||
.expect(function(res) { | ||
.expect(function (res) { | ||
return new Error('some descriptive error'); | ||
}) | ||
.end(function(err) { | ||
.end(function (err) { | ||
err.message.should.equal('some descriptive error'); | ||
@@ -741,16 +773,23 @@ (err instanceof Error).should.be.true; | ||
it("doesn't create false negatives", function(done) { | ||
it("doesn't create false negatives", function (done) { | ||
get | ||
.expect(function(res) {}) | ||
.expect(function (res) { | ||
}) | ||
.end(done); | ||
}); | ||
it('handles multiple asserts', function(done) { | ||
var calls = []; | ||
it('handles multiple asserts', function (done) { | ||
const calls = []; | ||
get | ||
.expect(function(res) { calls[0] = 1; }) | ||
.expect(function(res) { calls[1] = 1; }) | ||
.expect(function(res) { calls[2] = 1; }) | ||
.end(function() { | ||
var callCount = [0, 1, 2].reduce(function(count, i) { | ||
.expect(function (res) { | ||
calls[0] = 1; | ||
}) | ||
.expect(function (res) { | ||
calls[1] = 1; | ||
}) | ||
.expect(function (res) { | ||
calls[2] = 1; | ||
}) | ||
.end(function () { | ||
const callCount = [0, 1, 2].reduce(function (count, i) { | ||
return count + calls[i]; | ||
@@ -763,7 +802,8 @@ }, 0); | ||
it('plays well with normal assertions - no false positives', function(done) { | ||
it('plays well with normal assertions - no false positives', function (done) { | ||
get | ||
.expect(function(res) {}) | ||
.expect(function (res) { | ||
}) | ||
.expect('Content-Type', /json/) | ||
.end(function(err) { | ||
.end(function (err) { | ||
err.message.should.match(/Content-Type/); | ||
@@ -774,7 +814,9 @@ done(); | ||
it('plays well with normal assertions - no false negatives', function(done) { | ||
it('plays well with normal assertions - no false negatives', function (done) { | ||
get | ||
.expect(function(res) {}) | ||
.expect(function (res) { | ||
}) | ||
.expect('Content-Type', /html/) | ||
.expect(function(res) {}) | ||
.expect(function (res) { | ||
}) | ||
.expect('Content-Type', /text/) | ||
@@ -785,6 +827,6 @@ .end(done); | ||
describe('handling multiple assertions per field', function() { | ||
it('should work', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res) { | ||
describe('handling multiple assertions per field', function () { | ||
it('should work', function (done) { | ||
const app = express(); | ||
app.get('/', function (req, res) { | ||
res.send('hey'); | ||
@@ -800,5 +842,5 @@ }); | ||
it('should return an error if the first one fails', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res) { | ||
it('should return an error if the first one fails', function (done) { | ||
const app = express(); | ||
app.get('/', function (req, res) { | ||
res.send('hey'); | ||
@@ -811,5 +853,5 @@ }); | ||
.expect('Content-Type', /html/) | ||
.end(function(err) { | ||
.end(function (err) { | ||
err.message.should.equal('expected "Content-Type" matching /bloop/, ' | ||
+ 'got "text/html; charset=utf-8"'); | ||
+ 'got "text/html; charset=utf-8"'); | ||
done(); | ||
@@ -819,5 +861,5 @@ }); | ||
it('should return an error if a middle one fails', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res) { | ||
it('should return an error if a middle one fails', function (done) { | ||
const app = express(); | ||
app.get('/', function (req, res) { | ||
res.send('hey'); | ||
@@ -831,5 +873,5 @@ }); | ||
.expect('Content-Type', /html/) | ||
.end(function(err) { | ||
.end(function (err) { | ||
err.message.should.equal('expected "Content-Type" matching /bloop/, ' | ||
+ 'got "text/html; charset=utf-8"'); | ||
+ 'got "text/html; charset=utf-8"'); | ||
done(); | ||
@@ -839,5 +881,5 @@ }); | ||
it('should return an error if the last one fails', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res) { | ||
it('should return an error if the last one fails', function (done) { | ||
const app = express(); | ||
app.get('/', function (req, res) { | ||
res.send('hey'); | ||
@@ -851,5 +893,5 @@ }); | ||
.expect('Content-Type', /bloop/) | ||
.end(function(err) { | ||
.end(function (err) { | ||
err.message.should.equal('expected "Content-Type" matching /bloop/, ' | ||
+ 'got "text/html; charset=utf-8"'); | ||
+ 'got "text/html; charset=utf-8"'); | ||
done(); | ||
@@ -862,9 +904,9 @@ }); | ||
describe('request.agent(app)', function() { | ||
var app = express(); | ||
var agent = request.agent(app); | ||
describe('request.agent(app)', function () { | ||
const app = express(); | ||
const agent = request.agent(app); | ||
app.use(cookieParser()); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.cookie('cookie', 'hey'); | ||
@@ -874,3 +916,3 @@ res.send(); | ||
app.get('/return', function(req, res) { | ||
app.get('/return', function (req, res) { | ||
if (req.cookies.cookie) res.send(req.cookies.cookie); | ||
@@ -880,3 +922,3 @@ else res.send(':('); | ||
it('should save cookies', function(done) { | ||
it('should save cookies', function (done) { | ||
agent | ||
@@ -887,3 +929,3 @@ .get('/') | ||
it('should send cookies', function(done) { | ||
it('should send cookies', function (done) { | ||
agent | ||
@@ -895,8 +937,8 @@ .get('/return') | ||
describe('agent.host(host)', function() { | ||
it('should set request hostname', function(done) { | ||
var app = express(); | ||
var agent = request.agent(app); | ||
describe('agent.host(host)', function () { | ||
it('should set request hostname', function (done) { | ||
const app = express(); | ||
const agent = request.agent(app); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.send(); | ||
@@ -908,3 +950,3 @@ }); | ||
.get('/') | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
err.hostname.should.equal('something.test'); | ||
@@ -916,6 +958,6 @@ done(); | ||
describe('.<http verb> works as expected', function() { | ||
describe('.<http verb> works as expected', function () { | ||
it('.delete should work', function (done) { | ||
var app = express(); | ||
app.delete('/', function(req, res) { | ||
const app = express(); | ||
app.delete('/', function (req, res) { | ||
res.sendStatus(200); | ||
@@ -929,4 +971,4 @@ }); | ||
it('.del should work', function (done) { | ||
var app = express(); | ||
app.delete('/', function(req, res) { | ||
const app = express(); | ||
app.delete('/', function (req, res) { | ||
res.sendStatus(200); | ||
@@ -940,4 +982,4 @@ }); | ||
it('.get should work', function (done) { | ||
var app = express(); | ||
app.get('/', function(req, res) { | ||
const app = express(); | ||
app.get('/', function (req, res) { | ||
res.sendStatus(200); | ||
@@ -951,4 +993,4 @@ }); | ||
it('.post should work', function (done) { | ||
var app = express(); | ||
app.post('/', function(req, res) { | ||
const app = express(); | ||
app.post('/', function (req, res) { | ||
res.sendStatus(200); | ||
@@ -962,4 +1004,4 @@ }); | ||
it('.put should work', function (done) { | ||
var app = express(); | ||
app.put('/', function(req, res) { | ||
const app = express(); | ||
app.put('/', function (req, res) { | ||
res.sendStatus(200); | ||
@@ -973,4 +1015,4 @@ }); | ||
it('.head should work', function (done) { | ||
var app = express(); | ||
app.head('/', function(req, res) { | ||
const app = express(); | ||
app.head('/', function (req, res) { | ||
res.statusCode = 200; | ||
@@ -995,9 +1037,9 @@ res.set('Content-Encoding', 'gzip'); | ||
describe('assert ordering by call order', function() { | ||
it('should assert the body before status', function(done) { | ||
var app = express(); | ||
describe('assert ordering by call order', function () { | ||
it('should assert the body before status', function (done) { | ||
const app = express(); | ||
app.set('json spaces', 0); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.status(500).json({ message: 'something went wrong' }); | ||
@@ -1010,3 +1052,3 @@ }); | ||
.expect(200) | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
err.message.should.equal('expected \'hey\' response body, ' | ||
@@ -1018,8 +1060,8 @@ + 'got \'{"message":"something went wrong"}\''); | ||
it('should assert the status before body', function(done) { | ||
var app = express(); | ||
it('should assert the status before body', function (done) { | ||
const app = express(); | ||
app.set('json spaces', 0); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.status(500).json({ message: 'something went wrong' }); | ||
@@ -1032,3 +1074,3 @@ }); | ||
.expect('hey') | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
err.message.should.equal('expected 200 "OK", got 500 "Internal Server Error"'); | ||
@@ -1039,8 +1081,8 @@ done(); | ||
it('should assert the fields before body and status', function(done) { | ||
var app = express(); | ||
it('should assert the fields before body and status', function (done) { | ||
const app = express(); | ||
app.set('json spaces', 0); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.status(200).json({ hello: 'world' }); | ||
@@ -1053,3 +1095,3 @@ }); | ||
.expect('hello') | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
err.message.should.equal('expected "content-type" matching /html/, ' | ||
@@ -1061,6 +1103,6 @@ + 'got "application/json; charset=utf-8"'); | ||
it('should call the expect function in order', function(done) { | ||
var app = express(); | ||
it('should call the expect function in order', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.status(200).json({}); | ||
@@ -1071,10 +1113,10 @@ }); | ||
.get('/') | ||
.expect(function(res) { | ||
.expect(function (res) { | ||
res.body.first = 1; | ||
}) | ||
.expect(function(res) { | ||
.expect(function (res) { | ||
(res.body.first === 1).should.be.true; | ||
res.body.second = 2; | ||
}) | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
if (err) return done(err); | ||
@@ -1087,6 +1129,6 @@ (res.body.first === 1).should.be.true; | ||
it('should call expect(fn) and expect(status, fn) in order', function(done) { | ||
var app = express(); | ||
it('should call expect(fn) and expect(status, fn) in order', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.status(200).json({}); | ||
@@ -1097,6 +1139,6 @@ }); | ||
.get('/') | ||
.expect(function(res) { | ||
.expect(function (res) { | ||
res.body.first = 1; | ||
}) | ||
.expect(200, function(err, res) { | ||
.expect(200, function (err, res) { | ||
(err === null).should.be.true; | ||
@@ -1108,6 +1150,6 @@ (res.body.first === 1).should.be.true; | ||
it('should call expect(fn) and expect(header,value) in order', function(done) { | ||
var app = express(); | ||
it('should call expect(fn) and expect(header,value) in order', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res | ||
@@ -1121,3 +1163,3 @@ .set('X-Some-Header', 'Some value') | ||
.expect('X-Some-Header', 'Some value') | ||
.expect(function(res) { | ||
.expect(function (res) { | ||
res.headers['x-some-header'] = ''; | ||
@@ -1129,6 +1171,6 @@ }) | ||
it('should call expect(fn) and expect(body) in order', function(done) { | ||
var app = express(); | ||
it('should call expect(fn) and expect(body) in order', function (done) { | ||
const app = express(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.json({ somebody: 'some body value' }); | ||
@@ -1140,3 +1182,3 @@ }); | ||
.expect(/some body value/) | ||
.expect(function(res) { | ||
.expect(function (res) { | ||
res.body.somebody = 'nobody'; | ||
@@ -1146,3 +1188,3 @@ }) | ||
.expect({ somebody: 'nobody' }) | ||
.expect(function(res) { | ||
.expect(function (res) { | ||
res.text = 'gone'; | ||
@@ -1157,6 +1199,6 @@ }) | ||
describe('request.get(url).query(vals) works as expected', function() { | ||
it('normal single query string value works', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res) { | ||
describe('request.get(url).query(vals) works as expected', function () { | ||
it('normal single query string value works', function (done) { | ||
const app = express(); | ||
app.get('/', function (req, res) { | ||
res.status(200).send(req.query.val); | ||
@@ -1168,3 +1210,3 @@ }); | ||
.query({ val: 'Test1' }) | ||
.expect(200, function(err, res) { | ||
.expect(200, function (err, res) { | ||
res.text.should.be.equal('Test1'); | ||
@@ -1175,5 +1217,5 @@ done(); | ||
it('array query string value works', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res) { | ||
it('array query string value works', function (done) { | ||
const app = express(); | ||
app.get('/', function (req, res) { | ||
res.status(200).send(Array.isArray(req.query.val)); | ||
@@ -1185,3 +1227,3 @@ }); | ||
.query({ 'val[]': ['Test1', 'Test2'] }) | ||
.expect(200, function(err, res) { | ||
.expect(200, function (err, res) { | ||
res.req.path.should.be.equal('/?val%5B%5D=Test1&val%5B%5D=Test2'); | ||
@@ -1193,5 +1235,5 @@ res.text.should.be.equal('true'); | ||
it('array query string value work even with single value', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res) { | ||
it('array query string value work even with single value', function (done) { | ||
const app = express(); | ||
app.get('/', function (req, res) { | ||
res.status(200).send(Array.isArray(req.query.val)); | ||
@@ -1203,3 +1245,3 @@ }); | ||
.query({ 'val[]': ['Test1'] }) | ||
.expect(200, function(err, res) { | ||
.expect(200, function (err, res) { | ||
res.req.path.should.be.equal('/?val%5B%5D=Test1'); | ||
@@ -1211,5 +1253,5 @@ res.text.should.be.equal('true'); | ||
it('object query string value works', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res) { | ||
it('object query string value works', function (done) { | ||
const app = express(); | ||
app.get('/', function (req, res) { | ||
res.status(200).send(req.query.val.test); | ||
@@ -1221,3 +1263,3 @@ }); | ||
.query({ val: { test: 'Test1' } }) | ||
.expect(200, function(err, res) { | ||
.expect(200, function (err, res) { | ||
res.text.should.be.equal('Test1'); | ||
@@ -1228,8 +1270,8 @@ done(); | ||
it('handles unknown errors', function(done) { | ||
var app = express(); | ||
it('handles unknown errors', function (done) { | ||
const app = express(); | ||
nock.disableNetConnect(); | ||
app.get('/', function(req, res) { | ||
app.get('/', function (req, res) { | ||
res.status(200).send('OK'); | ||
@@ -1240,7 +1282,7 @@ }); | ||
.get('/') | ||
// This expect should never get called, but exposes this issue with other | ||
// errors being obscured by the response assertions | ||
// https://github.com/visionmedia/supertest/issues/352 | ||
// This expect should never get called, but exposes this issue with other | ||
// errors being obscured by the response assertions | ||
// https://github.com/visionmedia/supertest/issues/352 | ||
.expect(200) | ||
.end(function(err, res) { | ||
.end(function (err, res) { | ||
err.should.be.an.instanceof(Error); | ||
@@ -1247,0 +1289,0 @@ err.message.should.match(/Nock: Not allow net connect/); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
57211
14
1352
5