Comparing version 1.2.0 to 2.0.0
@@ -6,6 +6,6 @@ | ||
var Agent = require('superagent').agent | ||
, methods = require('methods') | ||
, http = require('http') | ||
, Test = require('./test'); | ||
var Agent = require('superagent').agent; | ||
var methods = require('methods'); | ||
var http = require('http'); | ||
var Test = require('./test'); | ||
@@ -26,5 +26,5 @@ /** | ||
function TestAgent(app, options){ | ||
function TestAgent(app, options) { | ||
if (!(this instanceof TestAgent)) return new TestAgent(app, options); | ||
if ('function' == typeof app) app = http.createServer(app); | ||
if (typeof app === 'function') app = http.createServer(app); // eslint-disable-line no-param-reassign | ||
if (options) this._ca = options.ca; | ||
@@ -42,11 +42,11 @@ Agent.call(this); | ||
// override HTTP verb methods | ||
methods.forEach(function(method){ | ||
TestAgent.prototype[method] = function(url, fn){ | ||
methods.forEach(function(method) { | ||
TestAgent.prototype[method] = function(url, fn) { // eslint-disable-line no-unused-vars | ||
var req = new Test(this.app, method.toUpperCase(), url); | ||
req.ca(this._ca); | ||
req.on('response', this.saveCookies.bind(this)); | ||
req.on('redirect', this.saveCookies.bind(this)); | ||
req.on('redirect', this.attachCookies.bind(this, req)); | ||
this.attachCookies(req); | ||
req.on('response', this._saveCookies.bind(this)); | ||
req.on('redirect', this._saveCookies.bind(this)); | ||
req.on('redirect', this._attachCookies.bind(this, req)); | ||
this._attachCookies(req); | ||
@@ -53,0 +53,0 @@ return req; |
@@ -5,8 +5,8 @@ /** | ||
var request = require('superagent') | ||
, util = require('util') | ||
, http = require('http') | ||
, https = require('https') | ||
, assert = require('assert') | ||
, Request = request.Request; | ||
var request = require('superagent'); | ||
var util = require('util'); | ||
var http = require('http'); | ||
var https = require('https'); | ||
var assert = require('assert'); | ||
var Request = request.Request; | ||
@@ -35,3 +35,3 @@ /** | ||
this._asserts = []; | ||
this.url = 'string' == typeof app | ||
this.url = typeof app === 'string' | ||
? app + path | ||
@@ -56,7 +56,10 @@ : this.serverAddress(app, path); | ||
Test.prototype.serverAddress = function(app, path){ | ||
Test.prototype.serverAddress = function(app, path) { | ||
var addr = app.address(); | ||
var port; | ||
var protocol; | ||
if (!addr) this._server = app.listen(0); | ||
var port = app.address().port; | ||
var protocol = app instanceof https.Server ? 'https' : 'http'; | ||
port = app.address().port; | ||
protocol = app instanceof https.Server ? 'https' : 'http'; | ||
return protocol + '://127.0.0.1:' + port + path; | ||
@@ -81,17 +84,18 @@ }; | ||
Test.prototype.expect = function(a, b, c){ | ||
Test.prototype.expect = function(a, b, c) { | ||
// callback | ||
if ('function' == typeof a) { | ||
if (typeof a === 'function') { | ||
this._asserts.push(a); | ||
return this; | ||
} | ||
if ('function' == typeof b) this.end(b); | ||
if ('function' == typeof c) this.end(c); | ||
if (typeof b === 'function') this.end(b); | ||
if (typeof c === 'function') this.end(c); | ||
// status | ||
if ('number' == typeof a) { | ||
if (typeof a === 'number') { | ||
this._asserts.push(this._assertStatus.bind(this, a)); | ||
// body | ||
if ('function' != typeof b && arguments.length > 1) | ||
if (typeof b !== 'function' && arguments.length > 1) { | ||
this._asserts.push(this._assertBody.bind(this, b)); | ||
} | ||
return this; | ||
@@ -101,4 +105,4 @@ } | ||
// header field | ||
if ('string' == typeof b || 'number' == typeof b || b instanceof RegExp) { | ||
this._asserts.push(this._assertHeader.bind(this, {name: ''+a, value: b})); | ||
if (typeof b === 'string' || typeof b === 'number' || b instanceof RegExp) { | ||
this._asserts.push(this._assertHeader.bind(this, { name: '' + a, value: b })); | ||
return this; | ||
@@ -121,3 +125,3 @@ } | ||
Test.prototype.end = function(fn){ | ||
Test.prototype.end = function(fn) { | ||
var self = this; | ||
@@ -127,3 +131,3 @@ var server = this._server; | ||
end.call(this, function(err, res){ | ||
end.call(this, function(err, res) { | ||
if (server && server._handle) return server.close(assert); | ||
@@ -133,3 +137,3 @@ | ||
function assert(){ | ||
function assert() { | ||
self.assert(err, res, fn); | ||
@@ -151,7 +155,8 @@ } | ||
Test.prototype.assert = function(resError, res, fn){ | ||
Test.prototype.assert = function(resError, res, fn) { | ||
var error; | ||
var i; | ||
// asserts | ||
for (var i = 0; i < this._asserts.length && !error; ++i) { | ||
for (i = 0; i < this._asserts.length && !error; ++i) { | ||
error = this._assertFunction(this._asserts[i], res); | ||
@@ -161,5 +166,5 @@ } | ||
// set unexpected superagent error if no other error has occurred. | ||
if (!error && resError instanceof Error && | ||
(!res || resError.status !== res.status)) | ||
if (!error && resError instanceof Error && (!res || resError.status !== res.status)) { | ||
error = resError; | ||
} | ||
@@ -180,9 +185,12 @@ fn.call(this, error || null, res); | ||
var isregexp = body instanceof RegExp; | ||
var a; | ||
var b; | ||
// parsed | ||
if ('object' == typeof body && !isregexp) { | ||
if (typeof body === 'object' && !isregexp) { | ||
try { | ||
assert.deepEqual(body, res.body); | ||
} catch (err) { | ||
var a = util.inspect(body); | ||
var b = util.inspect(res.body); | ||
a = util.inspect(body); | ||
b = util.inspect(res.body); | ||
return error('expected ' + a + ' response body, got ' + b, body, res.body); | ||
@@ -193,4 +201,4 @@ } | ||
if (body !== res.text) { | ||
var a = util.inspect(body); | ||
var b = util.inspect(res.text); | ||
a = util.inspect(body); | ||
b = util.inspect(res.text); | ||
@@ -221,7 +229,15 @@ // regexp | ||
var actual = res.header[field.toLowerCase()]; | ||
if (null == actual) return new Error('expected "' + field + '" header field'); | ||
var fieldExpected = header.value; | ||
if (fieldExpected == actual) return; | ||
if (typeof actual === 'undefined') return new Error('expected "' + field + '" header field'); | ||
// This check handles header values that may be a String or single element Array | ||
if ((actual instanceof Array && actual.toString() === fieldExpected) || | ||
fieldExpected === actual) { | ||
return; | ||
} | ||
if (fieldExpected instanceof RegExp) { | ||
if (!fieldExpected.test(actual)) return new Error('expected "' + field + '" matching ' + fieldExpected + ', got "' + actual + '"'); | ||
if (!fieldExpected.test(actual)) { | ||
return new Error('expected "' + field + '" matching ' + | ||
fieldExpected + ', got "' + actual + '"'); | ||
} | ||
} else { | ||
@@ -242,5 +258,7 @@ return new Error('expected "' + field + '" of "' + fieldExpected + '", got "' + actual + '"'); | ||
Test.prototype._assertStatus = function(status, res) { | ||
var a; | ||
var b; | ||
if (res.status !== status) { | ||
var a = http.STATUS_CODES[status]; | ||
var b = http.STATUS_CODES[res.status]; | ||
a = http.STATUS_CODES[status]; | ||
b = http.STATUS_CODES[res.status]; | ||
return new Error('expected ' + status + ' "' + a + '", got ' + res.status + ' "' + b + '"'); | ||
@@ -262,3 +280,3 @@ } | ||
err = check(res); | ||
} catch(e) { | ||
} catch (e) { | ||
err = e; | ||
@@ -265,0 +283,0 @@ } |
{ | ||
"name": "supertest", | ||
"version": "1.2.0", | ||
"description": "Super-agent driven library for testing HTTP servers", | ||
"version": "2.0.0", | ||
"description": "SuperAgent driven library for testing HTTP servers", | ||
"main": "index.js", | ||
"scripts": { | ||
"pretest": "npm install", | ||
"test": "mocha --require should --reporter spec --check-leaks" | ||
"test": "eslint lib/**/*.js test/**/*.js && mocha --require should --reporter spec --check-leaks" | ||
}, | ||
"dependencies": { | ||
"superagent": "^1.7.2", | ||
"superagent": "^2.0.0", | ||
"methods": "1.x" | ||
}, | ||
"devDependencies": { | ||
"body-parser": "~1.13.2", | ||
"cookie-parser": "~1.3.5", | ||
"express": "~4.12.4", | ||
"mocha": "~2.2.5", | ||
"should": "~7.0.2" | ||
"body-parser": "~1.15.0", | ||
"cookie-parser": "~1.4.1", | ||
"eslint": "^2.8.0", | ||
"eslint-config-airbnb": "^7.0.0", | ||
"express": "~4.14.0", | ||
"mocha": "~2.5.3", | ||
"should": "~10.0.0" | ||
}, | ||
@@ -21,0 +23,0 @@ "engines": { |
@@ -1,4 +0,4 @@ | ||
# SuperTest [![Build Status](https://travis-ci.org/visionmedia/supertest.svg?branch=master)](https://travis-ci.org/visionmedia/supertest) [![npm version](https://badge.fury.io/js/supertest.svg)](https://www.npmjs.com/package/supertest) | ||
# SuperTest [![Build Status](https://travis-ci.org/visionmedia/supertest.svg?branch=master)](https://travis-ci.org/visionmedia/supertest) [![npm version](https://badge.fury.io/js/supertest.svg)](https://www.npmjs.com/package/supertest) [![Dependency Status](https://david-dm.org/visionmedia/supertest.svg)](https://david-dm.org/visionmedia/supertest) | ||
HTTP assertions made easy via [super-agent](http://github.com/visionmedia/superagent). | ||
HTTP assertions made easy via [superagent](http://github.com/visionmedia/superagent). | ||
@@ -8,3 +8,3 @@ ## About | ||
The motivation with this module is to provide a high-level abstraction for testing | ||
HTTP, while still allowing you to drop down to the lower-level API provided by super-agent. | ||
HTTP, while still allowing you to drop down to the lower-level API provided by superagent. | ||
@@ -30,8 +30,8 @@ ## Getting Started | ||
```js | ||
var request = require('supertest') | ||
, express = require('express'); | ||
var request = require('supertest'); | ||
var express = require('express'); | ||
var app = express(); | ||
app.get('/user', function(req, res){ | ||
app.get('/user', function(req, res) { | ||
res.status(200).json({ name: 'tobi' }); | ||
@@ -45,3 +45,3 @@ }); | ||
.expect(200) | ||
.end(function(err, res){ | ||
.end(function(err, res) { | ||
if (err) throw err; | ||
@@ -54,4 +54,4 @@ }); | ||
```js | ||
describe('GET /user', function(){ | ||
it('respond with json', function(done){ | ||
describe('GET /user', function() { | ||
it('respond with json', function(done) { | ||
request(app) | ||
@@ -62,4 +62,4 @@ .get('/user') | ||
.expect(200, done); | ||
}) | ||
}) | ||
}); | ||
}); | ||
``` | ||
@@ -76,9 +76,9 @@ | ||
```js | ||
describe('GET /users', function(){ | ||
it('respond with json', function(done){ | ||
describe('GET /users', function() { | ||
it('respond with json', function(done) { | ||
request(app) | ||
.get('/user') | ||
.get('/users') | ||
.set('Accept', 'application/json') | ||
.expect(200) | ||
.end(function(err, res){ | ||
.end(function(err, res) { | ||
if (err) return done(err); | ||
@@ -95,4 +95,4 @@ done(); | ||
```js | ||
describe('GET /user', function(){ | ||
it('user.name should be an case-insensitive match for "tobi"', function(done){ | ||
describe('GET /user', function() { | ||
it('user.name should be an case-insensitive match for "tobi"', function(done) { | ||
request(app) | ||
@@ -111,3 +111,2 @@ .get('/user') | ||
}); | ||
``` | ||
@@ -145,3 +144,4 @@ | ||
, should = require('should') | ||
, express = require('express'); | ||
, express = require('express') | ||
, cookieParser = require('cookie-parser'); | ||
@@ -151,3 +151,3 @@ | ||
var app = express(); | ||
app.use(express.cookieParser()); | ||
app.use(cookieParser()); | ||
@@ -183,3 +183,3 @@ app.get('/', function(req, res){ | ||
You may use any [super-agent](http://github.com/visionmedia/superagent) methods, | ||
You may use any [superagent](http://github.com/visionmedia/superagent) methods, | ||
including `.write()`, `.pipe()` etc and perform assertions in the `.end()` callback | ||
@@ -207,6 +207,4 @@ for lower-level needs. | ||
Pass a custom assertion function. It'll be given the response object to check. If the response is ok, it should return falsy, most commonly by not returning anything. If the check fails, throw an error or return a truthy value like a string that'll be turned into an error. | ||
Pass a custom assertion function. It'll be given the response object to check. If the check fails, throw an error. | ||
Here the string or error throwing options are both demonstrated: | ||
```js | ||
@@ -219,3 +217,3 @@ request(app) | ||
function hasPreviousAndNextKeys(res) { | ||
if (!('next' in res.body)) return "missing next key"; | ||
if (!('next' in res.body)) throw new Error("missing next key"); | ||
if (!('prev' in res.body)) throw new Error("missing prev key"); | ||
@@ -222,0 +220,0 @@ } |
@@ -0,26 +1,26 @@ | ||
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'); | ||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; | ||
var request = require('..') | ||
, https = require('https') | ||
, fs = require('fs') | ||
, path = require('path') | ||
, should = require('should') | ||
, express = require('express'); | ||
var bodyParser = require('body-parser') | ||
, cookieParser = require('cookie-parser'); | ||
describe('request(url)', function(){ | ||
it('should be supported', function(done){ | ||
describe('request(url)', function() { | ||
it('should be supported', function(done) { | ||
var app = express(); | ||
var s; | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('hello'); | ||
}); | ||
var s = app.listen(function(){ | ||
s = app.listen(function() { | ||
var url = 'http://localhost:' + s.address().port; | ||
request(url) | ||
.get('/') | ||
.expect("hello", done); | ||
.expect('hello', done); | ||
}); | ||
@@ -32,8 +32,9 @@ }); | ||
var app = express(); | ||
var s; | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('hello'); | ||
}); | ||
var s = app.listen(function(){ | ||
s = app.listen(function() { | ||
var url = 'http://localhost:' + s.address().port; | ||
@@ -50,7 +51,7 @@ var test = request(url).get('/'); | ||
describe('request(app)', function(){ | ||
it('should fire up the app on an ephemeral port', function(done){ | ||
describe('request(app)', function() { | ||
it('should fire up the app on an ephemeral port', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('hey'); | ||
@@ -61,3 +62,3 @@ }); | ||
.get('/') | ||
.end(function(err, res){ | ||
.end(function(err, res) { | ||
res.status.should.equal(200); | ||
@@ -69,13 +70,14 @@ res.text.should.equal('hey'); | ||
it('should work with an active server', function(done){ | ||
it('should work with an active server', function(done) { | ||
var app = express(); | ||
var server; | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('hey'); | ||
}); | ||
var 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); | ||
@@ -88,13 +90,13 @@ res.text.should.equal('hey'); | ||
it('should work with remote server', function(done){ | ||
it('should work with remote server', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('hey'); | ||
}); | ||
var server = 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); | ||
@@ -107,9 +109,4 @@ res.text.should.equal('hey'); | ||
it('should work with a https server', function(done){ | ||
it('should work with a https server', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
res.send('hey'); | ||
}); | ||
var fixtures = path.join(__dirname, 'fixtures'); | ||
@@ -121,5 +118,9 @@ var server = https.createServer({ | ||
app.get('/', function(req, res) { | ||
res.send('hey'); | ||
}); | ||
request(server) | ||
.get('/') | ||
.end(function(err, res){ | ||
.end(function(err, res) { | ||
if (err) return done(err); | ||
@@ -132,3 +133,3 @@ res.status.should.equal(200); | ||
it('should work with .send() etc', function(done){ | ||
it('should work with .send() etc', function(done) { | ||
var app = express(); | ||
@@ -138,3 +139,3 @@ | ||
app.post('/', function(req, res){ | ||
app.post('/', function(req, res) { | ||
res.send(req.body.name); | ||
@@ -149,6 +150,6 @@ }); | ||
it('should work when unbuffered', function(done){ | ||
it('should work when unbuffered', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.end('Hello'); | ||
@@ -162,6 +163,6 @@ }); | ||
it('should default redirects to 0', function(done){ | ||
it('should default redirects to 0', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.redirect('/login'); | ||
@@ -175,10 +176,10 @@ }); | ||
it('should handle redirects', function(done){ | ||
it('should handle redirects', function(done) { | ||
var app = express(); | ||
app.get('/login', function (req, res){ | ||
res.end('Login') | ||
app.get('/login', function (req, res) { | ||
res.end('Login'); | ||
}); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.redirect('/login'); | ||
@@ -191,7 +192,7 @@ }); | ||
.end(function (err, res) { | ||
should.exist(res) | ||
res.status.should.be.equal(200) | ||
res.text.should.be.equal('Login') | ||
done() | ||
}) | ||
should.exist(res); | ||
res.status.should.be.equal(200); | ||
res.text.should.be.equal('Login'); | ||
done(); | ||
}); | ||
}); | ||
@@ -202,3 +203,3 @@ | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.destroy(); | ||
@@ -215,15 +216,16 @@ }); | ||
describe('.end(fn)', function(){ | ||
it('should close server', function(done){ | ||
describe('.end(fn)', function() { | ||
it('should close server', function(done) { | ||
var app = express(); | ||
var test; | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('supertest FTW!'); | ||
}); | ||
var test = request(app) | ||
test = request(app) | ||
.get('/') | ||
.end(function(){}); | ||
.end(function() {}); | ||
test._server.on('close', function(){ | ||
test._server.on('close', function() { | ||
done(); | ||
@@ -233,13 +235,14 @@ }); | ||
it('should wait for server to close before invoking fn', function(done){ | ||
it('should wait for server to close before invoking fn', function(done) { | ||
var app = express(); | ||
var closed = false; | ||
var test; | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('supertest FTW!'); | ||
}); | ||
var test = request(app) | ||
test = request(app) | ||
.get('/') | ||
.end(function(){ | ||
.end(function() { | ||
closed.should.be.true; | ||
@@ -249,3 +252,3 @@ done(); | ||
test._server.on('close', function(){ | ||
test._server.on('close', function() { | ||
closed = true; | ||
@@ -255,7 +258,7 @@ }); | ||
it('should support nested requests', function(done){ | ||
it('should support nested requests', function(done) { | ||
var app = express(); | ||
var test = request(app); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('supertest FTW!'); | ||
@@ -266,6 +269,6 @@ }); | ||
.get('/') | ||
.end(function(){ | ||
.end(function() { | ||
test | ||
.get('/') | ||
.end(function(err, res){ | ||
.end(function(err, res) { | ||
(err === null).should.be.true; | ||
@@ -279,6 +282,6 @@ res.status.should.equal(200); | ||
it('should include the response in the error callback', function(done){ | ||
it('should include the response in the error callback', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('whatever'); | ||
@@ -292,3 +295,3 @@ }); | ||
}) | ||
.end(function(err, res){ | ||
.end(function(err, res) { | ||
should.exist(err); | ||
@@ -304,11 +307,12 @@ should.exist(res); | ||
var app = express(); | ||
var test; | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('whatever'); | ||
}); | ||
var test = request(app).get('/'); | ||
test = request(app).get('/'); | ||
test.expect(function() { | ||
throw new Error('Some error'); | ||
}).end(function(err, res){ | ||
}).end(function(err, res) { | ||
should.exist(err); | ||
@@ -322,5 +326,6 @@ this.should.eql(test); | ||
var app = express(); | ||
var server; | ||
app.get('/', function(req, res){ | ||
setTimeout( function () { | ||
app.get('/', function(req, res) { | ||
setTimeout(function () { | ||
res.end(); | ||
@@ -330,4 +335,4 @@ }, 20); | ||
var s = app.listen(function(){ | ||
var url = 'http://localhost:' + s.address().port; | ||
server = app.listen(function() { | ||
var url = 'http://localhost:' + server.address().port; | ||
request(url) | ||
@@ -345,10 +350,11 @@ .get('/') | ||
var app = express(); | ||
var server; | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.end(); | ||
}); | ||
var s = app.listen(function(){ | ||
var url = 'http://localhost:' + s.address().port; | ||
s.close(); | ||
server = app.listen(function() { | ||
var url = 'http://localhost:' + server.address().port; | ||
server.close(); | ||
request(url) | ||
@@ -364,7 +370,7 @@ .get('/') | ||
describe('.expect(status[, fn])', function(){ | ||
it('should assert the response status', function(done){ | ||
describe('.expect(status[, fn])', function() { | ||
it('should assert the response status', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('hey'); | ||
@@ -376,3 +382,3 @@ }); | ||
.expect(404) | ||
.end(function(err, res){ | ||
.end(function(err, res) { | ||
err.message.should.equal('expected 404 "Not Found", got 200 "OK"'); | ||
@@ -395,11 +401,11 @@ done(); | ||
.expect(200) | ||
.end(done) | ||
.end(done); | ||
}); | ||
}); | ||
describe('.expect(status, body[, fn])', function(){ | ||
it('should assert the response body and status', function(done){ | ||
describe('.expect(status, body[, fn])', function() { | ||
it('should assert the response body and status', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('foo'); | ||
@@ -410,10 +416,10 @@ }); | ||
.get('/') | ||
.expect(200, 'foo', done) | ||
.expect(200, 'foo', done); | ||
}); | ||
describe("when the body argument is an empty string", function() { | ||
it("should not quietly pass on failure", function(done) { | ||
describe('when the body argument is an empty string', function() { | ||
it('should not quietly pass on failure', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('foo'); | ||
@@ -425,3 +431,3 @@ }); | ||
.expect(200, '') | ||
.end(function(err, res){ | ||
.end(function(err, res) { | ||
err.message.should.equal('expected \'\' response body, got \'foo\''); | ||
@@ -434,4 +440,4 @@ done(); | ||
describe('.expect(body[, fn])', function(){ | ||
it('should assert the response body', function(done){ | ||
describe('.expect(body[, fn])', function() { | ||
it('should assert the response body', function(done) { | ||
var app = express(); | ||
@@ -441,3 +447,3 @@ | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send({ foo: 'bar' }); | ||
@@ -449,3 +455,3 @@ }); | ||
.expect('hey') | ||
.end(function(err, res){ | ||
.end(function(err, res) { | ||
err.message.should.equal('expected \'hey\' response body, got \'{"foo":"bar"}\''); | ||
@@ -461,3 +467,3 @@ done(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.status(500).send({ message: 'something went wrong' }); | ||
@@ -470,4 +476,4 @@ }); | ||
.expect('hey') | ||
.end(function(err, res){ | ||
err.message.should.equal('expected 200 \"OK"\, got 500 \"Internal Server Error\"'); | ||
.end(function(err, res) { | ||
err.message.should.equal('expected 200 "OK", got 500 "Internal Server Error"'); | ||
done(); | ||
@@ -477,3 +483,3 @@ }); | ||
it('should assert the response text', function(done){ | ||
it('should assert the response text', function(done) { | ||
var app = express(); | ||
@@ -483,3 +489,3 @@ | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send({ foo: 'bar' }); | ||
@@ -493,3 +499,3 @@ }); | ||
it('should assert the parsed response body', function(done){ | ||
it('should assert the parsed response body', function(done) { | ||
var app = express(); | ||
@@ -499,3 +505,3 @@ | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send({ foo: 'bar' }); | ||
@@ -507,3 +513,3 @@ }); | ||
.expect({ foo: 'baz' }) | ||
.end(function(err, res){ | ||
.end(function(err, res) { | ||
err.message.should.equal('expected { foo: \'baz\' } response body, got { foo: \'bar\' }'); | ||
@@ -518,6 +524,6 @@ | ||
it('should support regular expressions', function(done){ | ||
it('should support regular expressions', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('foobar'); | ||
@@ -529,3 +535,3 @@ }); | ||
.expect(/^bar/) | ||
.end(function(err, res){ | ||
.end(function(err, res) { | ||
err.message.should.equal('expected body \'foobar\' to match /^bar/'); | ||
@@ -536,6 +542,6 @@ done(); | ||
it('should assert response body multiple times', function(done){ | ||
it('should assert response body multiple times', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('hey tj'); | ||
@@ -555,6 +561,6 @@ }); | ||
it('should assert response body multiple times with no exception', function(done){ | ||
it('should assert response body multiple times with no exception', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('hey tj'); | ||
@@ -571,7 +577,7 @@ }); | ||
describe('.expect(field, value[, fn])', function(){ | ||
it('should assert the header field presence', function(done){ | ||
describe('.expect(field, value[, fn])', function() { | ||
it('should assert the header field presence', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send({ foo: 'bar' }); | ||
@@ -583,3 +589,3 @@ }); | ||
.expect('Content-Foo', 'bar') | ||
.end(function(err, res){ | ||
.end(function(err, res) { | ||
err.message.should.equal('expected "Content-Foo" header field'); | ||
@@ -590,6 +596,6 @@ done(); | ||
it('should assert the header field value', function(done){ | ||
it('should assert the header field value', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send({ foo: 'bar' }); | ||
@@ -601,4 +607,5 @@ }); | ||
.expect('Content-Type', 'text/html') | ||
.end(function(err, res){ | ||
err.message.should.equal('expected "Content-Type" of "text/html", got "application/json; charset=utf-8"'); | ||
.end(function(err, res) { | ||
err.message.should.equal('expected "Content-Type" of "text/html", ' + | ||
'got "application/json; charset=utf-8"'); | ||
done(); | ||
@@ -608,6 +615,6 @@ }); | ||
it('should assert multiple fields', function(done){ | ||
it('should assert multiple fields', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('hey'); | ||
@@ -623,6 +630,6 @@ }); | ||
it('should support regular expressions', function(done){ | ||
it('should support regular expressions', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('hey'); | ||
@@ -634,4 +641,5 @@ }); | ||
.expect('Content-Type', /^application/) | ||
.end(function(err){ | ||
err.message.should.equal('expected "Content-Type" matching /^application/, got "text/html; charset=utf-8"'); | ||
.end(function(err) { | ||
err.message.should.equal('expected "Content-Type" matching /^application/, ' + | ||
'got "text/html; charset=utf-8"'); | ||
done(); | ||
@@ -641,6 +649,6 @@ }); | ||
it('should support numbers', function(done){ | ||
it('should support numbers', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('hey'); | ||
@@ -652,3 +660,3 @@ }); | ||
.expect('Content-Length', 4) | ||
.end(function(err){ | ||
.end(function(err) { | ||
err.message.should.equal('expected "Content-Length" of "4", got "3"'); | ||
@@ -659,9 +667,9 @@ done(); | ||
describe('handling arbitrary expect functions', function(){ | ||
describe('handling arbitrary expect functions', function() { | ||
var app; | ||
var get; | ||
var app, get; | ||
before(function(){ | ||
before(function() { | ||
app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('hey'); | ||
@@ -671,35 +679,36 @@ }); | ||
beforeEach(function(){ | ||
beforeEach(function() { | ||
get = request(app).get('/'); | ||
}); | ||
it('reports errors',function(done) { | ||
it('reports errors', function(done) { | ||
get | ||
.expect(function(res) { | ||
throw new Error("failed") | ||
throw new Error('failed'); | ||
}) | ||
.end(function(err) { | ||
err.message.should.equal('failed'); | ||
done() | ||
done(); | ||
}); | ||
}); | ||
it('ensures truthy non-errors returned from asserts are not promoted to errors',function(done){ | ||
get | ||
.expect(function(res) { | ||
return "some descriptive error"; | ||
}) | ||
.end(function(err) { | ||
should.not.exist(err); | ||
done() | ||
it('ensures truthy non-errors returned from asserts are not promoted to errors', | ||
function(done) { | ||
get | ||
.expect(function(res) { | ||
return 'some descriptive error'; | ||
}) | ||
.end(function(err) { | ||
should.not.exist(err); | ||
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) { | ||
return new Error("some descriptive error"); | ||
return new Error('some descriptive error'); | ||
}) | ||
.end(function(err) { | ||
err.message.should.equal("some descriptive error"); | ||
err.message.should.equal('some descriptive error'); | ||
(err instanceof Error).should.be.true; | ||
@@ -710,3 +719,3 @@ done(); | ||
it("doesn't create false negatives", function(done){ | ||
it("doesn't create false negatives", function(done) { | ||
get | ||
@@ -717,13 +726,13 @@ .expect(function(res) {}) | ||
it("handles multiple asserts", function(done){ | ||
it('handles multiple asserts', function(done) { | ||
var calls = []; | ||
get | ||
.expect(function(res) { calls[0] = 1 }) | ||
.expect(function(res) { calls[1] = 1 }) | ||
.expect(function(res) { calls[2] = 1 }) | ||
.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) { | ||
return count + calls[i] | ||
},0); | ||
callCount.should.equal(3,"didn't see all assertions run"); | ||
var callCount = [0, 1, 2].reduce(function(count, i) { | ||
return count + calls[i]; | ||
}, 0); | ||
callCount.should.equal(3, "didn't see all assertions run"); | ||
done(); | ||
@@ -733,3 +742,3 @@ }); | ||
it("plays well with normal assertions - no false positives", function(done){ | ||
it('plays well with normal assertions - no false positives', function(done) { | ||
get | ||
@@ -744,3 +753,3 @@ .expect(function(res) {}) | ||
it("plays well with normal assertions - no false negatives", function(done){ | ||
it('plays well with normal assertions - no false negatives', function(done) { | ||
get | ||
@@ -751,11 +760,10 @@ .expect(function(res) {}) | ||
.expect('Content-Type', /text/) | ||
.end(done) | ||
.end(done); | ||
}); | ||
}); | ||
describe('handling multiple assertions per field', function(){ | ||
it('should work', function(done){ | ||
describe('handling multiple assertions per field', function() { | ||
it('should work', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('hey'); | ||
@@ -771,5 +779,5 @@ }); | ||
it('should return an error if the first one fails', function(done){ | ||
it('should return an error if the first one fails', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('hey'); | ||
@@ -782,4 +790,5 @@ }); | ||
.expect('Content-Type', /html/) | ||
.end(function(err){ | ||
err.message.should.equal('expected "Content-Type" matching /bloop/, got "text/html; charset=utf-8"'); | ||
.end(function(err) { | ||
err.message.should.equal('expected "Content-Type" matching /bloop/, ' + | ||
'got "text/html; charset=utf-8"'); | ||
done(); | ||
@@ -789,5 +798,5 @@ }); | ||
it('should return an error if a middle one fails', function(done){ | ||
it('should return an error if a middle one fails', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('hey'); | ||
@@ -801,4 +810,5 @@ }); | ||
.expect('Content-Type', /html/) | ||
.end(function(err){ | ||
err.message.should.equal('expected "Content-Type" matching /bloop/, got "text/html; charset=utf-8"'); | ||
.end(function(err) { | ||
err.message.should.equal('expected "Content-Type" matching /bloop/, ' + | ||
'got "text/html; charset=utf-8"'); | ||
done(); | ||
@@ -808,5 +818,5 @@ }); | ||
it('should return an error if the last one fails', function(done){ | ||
it('should return an error if the last one fails', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.send('hey'); | ||
@@ -820,4 +830,5 @@ }); | ||
.expect('Content-Type', /bloop/) | ||
.end(function(err){ | ||
err.message.should.equal('expected "Content-Type" matching /bloop/, got "text/html; charset=utf-8"'); | ||
.end(function(err) { | ||
err.message.should.equal('expected "Content-Type" matching /bloop/, ' + | ||
'got "text/html; charset=utf-8"'); | ||
done(); | ||
@@ -830,8 +841,9 @@ }); | ||
describe('request.agent(app)', function(){ | ||
describe('request.agent(app)', function() { | ||
var app = express(); | ||
var agent = request.agent(app); | ||
app.use(cookieParser()); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.cookie('cookie', 'hey'); | ||
@@ -841,10 +853,8 @@ res.send(); | ||
app.get('/return', function(req, res){ | ||
app.get('/return', function(req, res) { | ||
if (req.cookies.cookie) res.send(req.cookies.cookie); | ||
else res.send(':(') | ||
else res.send(':('); | ||
}); | ||
var agent = request.agent(app); | ||
it('should save cookies', function(done){ | ||
it('should save cookies', function(done) { | ||
agent | ||
@@ -855,3 +865,3 @@ .get('/') | ||
it('should send cookies', function(done){ | ||
it('should send cookies', function(done) { | ||
agent | ||
@@ -863,53 +873,53 @@ .get('/return') | ||
describe(".<http verb> works as expected", function(){ | ||
it(".delete should work", function (done){ | ||
var app = express(); | ||
app.delete('/', function(req, res){ | ||
res.sendStatus(200); | ||
}); | ||
describe('.<http verb> works as expected', function() { | ||
it('.delete should work', function (done) { | ||
var app = express(); | ||
app.delete('/', function(req, res) { | ||
res.sendStatus(200); | ||
}); | ||
request(app) | ||
request(app) | ||
.delete('/') | ||
.expect(200, done); | ||
}); | ||
it('.del should work', function (done) { | ||
var app = express(); | ||
app.delete('/', function(req, res) { | ||
res.sendStatus(200); | ||
}); | ||
it(".del should work", function (done){ | ||
var app = express(); | ||
app.delete('/', function(req, res){ | ||
res.sendStatus(200); | ||
}); | ||
request(app) | ||
request(app) | ||
.del('/') | ||
.expect(200, done); | ||
}); | ||
it('.get should work', function (done) { | ||
var app = express(); | ||
app.get('/', function(req, res) { | ||
res.sendStatus(200); | ||
}); | ||
it(".get should work", function (done){ | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
res.sendStatus(200); | ||
}); | ||
request(app) | ||
request(app) | ||
.get('/') | ||
.expect(200, done); | ||
}); | ||
it('.post should work', function (done) { | ||
var app = express(); | ||
app.post('/', function(req, res) { | ||
res.sendStatus(200); | ||
}); | ||
it(".post should work", function (done){ | ||
var app = express(); | ||
app.post('/', function(req, res){ | ||
res.sendStatus(200); | ||
}); | ||
request(app) | ||
request(app) | ||
.post('/') | ||
.expect(200, done); | ||
}); | ||
it('.put should work', function (done) { | ||
var app = express(); | ||
app.put('/', function(req, res) { | ||
res.sendStatus(200); | ||
}); | ||
it(".put should work", function (done){ | ||
var app = express(); | ||
app.put('/', function(req, res){ | ||
res.sendStatus(200); | ||
}); | ||
request(app) | ||
request(app) | ||
.put('/') | ||
.expect(200, done); | ||
}); | ||
}); | ||
}); | ||
@@ -924,3 +934,3 @@ | ||
app.get('/', function(req, res) { | ||
res.status(500).json({message: 'something went wrong'}); | ||
res.status(500).json({ message: 'something went wrong' }); | ||
}); | ||
@@ -933,3 +943,4 @@ | ||
.end(function(err, res) { | ||
err.message.should.equal('expected \'hey\' response body, got \'{"message":"something went wrong"}\''); | ||
err.message.should.equal('expected \'hey\' response body, ' + | ||
'got \'{"message":"something went wrong"}\''); | ||
done(); | ||
@@ -945,3 +956,3 @@ }); | ||
app.get('/', function(req, res) { | ||
res.status(500).json({message: 'something went wrong'}); | ||
res.status(500).json({ message: 'something went wrong' }); | ||
}); | ||
@@ -965,3 +976,3 @@ | ||
app.get('/', function(req, res) { | ||
res.status(200).json({hello: 'world'}); | ||
res.status(200).json({ hello: 'world' }); | ||
}); | ||
@@ -974,3 +985,4 @@ | ||
.end(function(err, res) { | ||
err.message.should.equal('expected "content-type" matching /html/, got "application/json; charset=utf-8"'); | ||
err.message.should.equal('expected "content-type" matching /html/, ' + | ||
'got "application/json; charset=utf-8"'); | ||
done(); | ||
@@ -1046,3 +1058,3 @@ }); | ||
app.get('/', function(req, res) { | ||
res.json({somebody: 'some body value'}); | ||
res.json({ somebody: 'some body value' }); | ||
}); | ||
@@ -1057,3 +1069,3 @@ | ||
.expect(/some body value/) // res.text should not be modified. | ||
.expect({somebody: 'nobody'}) | ||
.expect({ somebody: 'nobody' }) | ||
.expect(function(res) { | ||
@@ -1064,3 +1076,3 @@ res.text = 'gone'; | ||
.expect(/gone/) | ||
.expect({somebody: 'nobody'}) // res.body should not be modified | ||
.expect({ somebody: 'nobody' }) // res.body should not be modified | ||
.expect('gone', done); | ||
@@ -1070,7 +1082,6 @@ }); | ||
describe("request.get(url).query(vals) works as expected", function(){ | ||
it("normal single query string value works", function(done) { | ||
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){ | ||
app.get('/', function(req, res) { | ||
res.status(200).send(req.query.val); | ||
@@ -1081,3 +1092,3 @@ }); | ||
.get('/') | ||
.query({val: "Test1"}) | ||
.query({ val: 'Test1' }) | ||
.expect(200, function(err, res) { | ||
@@ -1089,5 +1100,5 @@ res.text.should.be.equal('Test1'); | ||
it("array query string value works", function(done) { | ||
it('array query string value works', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.status(200).send(Array.isArray(req.query.val)); | ||
@@ -1098,3 +1109,3 @@ }); | ||
.get('/') | ||
.query({'val[]': ["Test1", "Test2"]}) | ||
.query({ 'val[]': ['Test1', 'Test2'] }) | ||
.expect(200, function(err, res) { | ||
@@ -1107,5 +1118,5 @@ res.req.path.should.be.equal('/?val%5B%5D=Test1&val%5B%5D=Test2'); | ||
it("array query string value work even with single value", function(done) { | ||
it('array query string value work even with single value', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.status(200).send(Array.isArray(req.query.val)); | ||
@@ -1116,3 +1127,3 @@ }); | ||
.get('/') | ||
.query({'val[]': ["Test1"]}) | ||
.query({ 'val[]': ['Test1'] }) | ||
.expect(200, function(err, res) { | ||
@@ -1125,5 +1136,5 @@ res.req.path.should.be.equal('/?val%5B%5D=Test1'); | ||
it("object query string value works", function(done) { | ||
it('object query string value works', function(done) { | ||
var app = express(); | ||
app.get('/', function(req, res){ | ||
app.get('/', function(req, res) { | ||
res.status(200).send(req.query.val.test); | ||
@@ -1134,3 +1145,3 @@ }); | ||
.get('/') | ||
.query({val: { test: 'Test1' } }) | ||
.query({ val: { test: 'Test1' } }) | ||
.expect(200, function(err, res) { | ||
@@ -1137,0 +1148,0 @@ res.text.should.be.equal('Test1'); |
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
48396
14
1217
7
221
+ Addedcall-bind@1.0.7(transitive)
+ Addedcomponent-emitter@1.3.1(transitive)
+ Addedcookiejar@2.1.4(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedform-data@1.0.0-rc4(transitive)
+ Addedformidable@1.2.6(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedmime@1.6.0(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedqs@6.13.0(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedsuperagent@2.3.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removedcomponent-emitter@1.2.1(transitive)
- Removedcookiejar@2.0.6(transitive)
- Removedextend@3.0.0(transitive)
- Removedform-data@1.0.0-rc3(transitive)
- Removedformidable@1.0.17(transitive)
- Removedisarray@0.0.1(transitive)
- Removedmime@1.3.4(transitive)
- Removedqs@2.3.3(transitive)
- Removedreadable-stream@1.0.27-1(transitive)
- Removedreduce-component@1.0.1(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedsuperagent@1.8.5(transitive)
Updatedsuperagent@^2.0.0