Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v3.1.0 #474

Merged
merged 20 commits into from
May 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ba31e14
Removed ambiguously misappropriated cultural references from readme
reallistic Aug 31, 2015
8df9c43
Add post() examples to the README
kevinburke May 23, 2017
11a10ea
Add a .host() method to set a host other than 127.0.0.1
mikec Nov 15, 2015
389c831
Always pass on errors if no response
bkeepers Nov 17, 2017
0ebb06e
Upgrade the superagent node module to resolve security vulnerabilitie…
fadi-william Apr 14, 2018
73d93b9
chore(.travis.yml) node versions updated
rimiti Apr 19, 2018
39bb1e2
Remove unused dependency in Readme.MD snippet
pedro-otero Apr 20, 2018
fec7fbe
Merge pull request #473 from pedro-otero/patch-1
rimiti Apr 23, 2018
d10b48f
Merge pull request #472 from visionmedia/update-travis-node-versions
rimiti Apr 23, 2018
9c9c0ea
Merge pull request #297 from mikec/master
rimiti Apr 23, 2018
a28f04c
Merge pull request #446 from bkeepers/unknown-errors
rimiti Apr 23, 2018
9e5f30a
Merge pull request #418 from kevinburke/add-example
rimiti Apr 23, 2018
a412bb5
Merge pull request #470 from levioza/master
rimiti Apr 23, 2018
67dea2c
Merge remote-tracking branch 'upstream/master'
reallistic Apr 23, 2018
687f625
Merge branch 'PR-275' into release-v3.1.0
rimiti Apr 24, 2018
c3dc820
chore(package.json) version bumped
rimiti Apr 24, 2018
33a1a6e
chore(package-lock.json) locker file include
rimiti Apr 24, 2018
a5009bd
doc(History.md) changelog updated
rimiti Apr 24, 2018
177e827
chore(.travis.yml) node v4 remove
rimiti May 2, 2018
09342cd
Merge pull request #475 from visionmedia/update-travis-node-versions
rimiti May 2, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- "6"
- "5"
- "4"
- 6
- 8
- 9
11 changes: 11 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
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)

3.0.0 / 2017-01-29
===================

Expand Down
22 changes: 12 additions & 10 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const express = require('express');
const app = express();

app.get('/user', function(req, res) {
res.status(200).json({ name: 'tobi' });
res.status(200).json({ name: 'john' });
});

request(app)
Expand Down Expand Up @@ -68,10 +68,11 @@ you do not add a status code expect (i.e. `.expect(302)`).
order to fail the test case, you will need to rethrow or pass `err` to `done()`, as follows:

```js
describe('GET /users', function() {
it('respond with json', function(done) {
describe('POST /users', function() {
it('responds with json', function(done) {
request(app)
.get('/users')
.post('/users')
.send({name: 'john'})
.set('Accept', 'application/json')
.expect(200)
.end(function(err, res) {
Expand All @@ -86,7 +87,7 @@ You can also use promises

```js
describe('GET /users', function() {
it('respond with json', function() {
it('responds with json', function() {
return request(app)
.get('/users')
.set('Accept', 'application/json')
Expand All @@ -102,18 +103,19 @@ describe('GET /users', function() {
to modify the response body or headers before executing an assertion.

```js
describe('GET /user', function() {
it('user.name should be an case-insensitive match for "tobi"', function(done) {
describe('POST /user', function() {
it('user.name should be an case-insensitive match for "john"', function(done) {
request(app)
.get('/user')
.post('/user')
.send('name=john') // x-www-form-urlencoded upload
.set('Accept', 'application/json')
.expect(function(res) {
res.body.id = 'some fixed id';
res.body.name = res.body.name.toUpperCase();
})
.expect(200, {
id: 'some fixed id',
name: 'TOBI'
name: 'john'
}, done);
});
});
Expand All @@ -125,7 +127,7 @@ Anything you can do with superagent, you can do with supertest - for example mul
request(app)
.post('/')
.field('name', 'my awesome avatar')
.attach('avatar', 'test/fixtures/homeboy.jpg')
.attach('avatar', 'test/fixtures/avatar.jpg')
...
```

Expand Down
10 changes: 8 additions & 2 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ function TestAgent(app, options) {
* Inherits from `Agent.prototype`.
*/

TestAgent.prototype.__proto__ = Agent.prototype;
Object.setPrototypeOf(TestAgent.prototype, Agent.prototype);

// set a host name
TestAgent.prototype.host = function(host) {
this._host = host;
return this;
};

// override HTTP verb methods
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);
var req = new Test(this.app, method.toUpperCase(), url, this._host);
req.ca(this._ca);
req.cert(this._cert);
req.key(this._key);
Expand Down
22 changes: 12 additions & 10 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ module.exports = Test;
* @api public
*/

function Test(app, method, path) {
function Test(app, method, path, host) {
Request.call(this, method.toUpperCase(), path);
this.redirects(0);
this.buffer();
this.app = app;
this._asserts = [];
this.url = typeof app === 'string'
? app + path
: this.serverAddress(app, path);
: this.serverAddress(app, path, host);
}

/**
* Inherits from `Request.prototype`.
*/

Test.prototype.__proto__ = Request.prototype;
Object.setPrototypeOf(Test.prototype, Request.prototype);

/**
* Returns a URL, extracted from a server.
Expand All @@ -51,15 +51,15 @@ Test.prototype.__proto__ = Request.prototype;
* @api private
*/

Test.prototype.serverAddress = function(app, path) {
Test.prototype.serverAddress = function(app, path, host) {
var addr = app.address();
var port;
var protocol;

if (!addr) this._server = app.listen(0);
port = app.address().port;
protocol = app instanceof https.Server ? 'https' : 'http';
return protocol + '://127.0.0.1:' + port + path;
return protocol + '://' + (host || '127.0.0.1') + ':' + port + path;
};

/**
Expand Down Expand Up @@ -159,11 +159,13 @@ Test.prototype.assert = function(resError, res, fn) {
ETIMEDOUT: 'Operation timed out'
};

if (!res && resError && (resError instanceof Error) && (resError.syscall === 'connect')
&& (Object.getOwnPropertyNames(sysErrors).indexOf(resError.code) >= 0)) {
error = new Error(resError.code + ': ' + sysErrors[resError.code]);
fn.call(this, error, null);
return;
if (!res && resError) {
if (resError instanceof Error && resError.syscall === 'connect'
&& Object.getOwnPropertyNames(sysErrors).indexOf(resError.code) >= 0) {
error = new Error(resError.code + ': ' + sysErrors[resError.code]);
} else {
error = resError;
}
}

// asserts
Expand Down
Loading