Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

supertest

Package Overview
Dependencies
Maintainers
5
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

supertest - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

11

History.md

@@ -0,1 +1,12 @@

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

@@ -2,0 +13,0 @@ ===================

10

lib/agent.js

@@ -41,8 +41,14 @@

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);

@@ -49,0 +55,0 @@ req.cert(this._cert);

22

lib/test.js

@@ -28,3 +28,3 @@ /**

function Test(app, method, path) {
function Test(app, method, path, host) {
Request.call(this, method.toUpperCase(), path);

@@ -37,3 +37,3 @@ this.redirects(0);

? app + path
: this.serverAddress(app, path);
: this.serverAddress(app, path, host);
}

@@ -45,3 +45,3 @@

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

@@ -57,3 +57,3 @@ /**

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

@@ -66,3 +66,3 @@ var 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;
};

@@ -167,7 +167,9 @@

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;
}
}

@@ -174,0 +176,0 @@

{
"name": "supertest",
"version": "3.0.0",
"version": "3.1.0",
"description": "SuperAgent driven library for testing HTTP servers",

@@ -11,4 +11,4 @@ "main": "index.js",

"dependencies": {
"superagent": "^3.0.0",
"methods": "~1.1.2"
"methods": "~1.1.2",
"superagent": "3.8.2"
},

@@ -25,2 +25,3 @@ "devDependencies": {

"mocha": "~3.2.0",
"nock": "^9.1.0",
"should": "~11.2.0"

@@ -27,0 +28,0 @@ },

@@ -35,3 +35,3 @@ # 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/status.svg)](https://david-dm.org/visionmedia/supertest)

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

@@ -72,6 +72,7 @@

```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')

@@ -91,3 +92,3 @@ .expect(200)

describe('GET /users', function() {
it('respond with json', function() {
it('responds with json', function() {
return request(app)

@@ -108,6 +109,7 @@ .get('/users')

```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')

@@ -120,3 +122,3 @@ .expect(function(res) {

id: 'some fixed id',
name: 'TOBI'
name: 'john'
}, done);

@@ -133,3 +135,3 @@ });

.field('name', 'my awesome avatar')
.attach('avatar', 'test/fixtures/homeboy.jpg')
.attach('avatar', 'test/fixtures/avatar.jpg')
...

@@ -136,0 +138,0 @@ ```

@@ -9,2 +9,3 @@ var request = require('..');

var cookieParser = require('cookie-parser');
var nock = require('nock');

@@ -138,4 +139,4 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

.post('/')
.send({ name: 'tobi' })
.expect('tobi', done);
.send({ name: 'john' })
.expect('john', done);
});

@@ -820,2 +821,21 @@

describe('agent.host(host)', function() {
it('should set request hostname', function(done) {
var app = express();
var agent = request.agent(app);
app.get('/', function(req, res) {
res.send();
});
agent
.host('something.test')
.get('/')
.end(function(err, res) {
err.hostname.should.equal('something.test');
done();
});
});
});
describe('.<http verb> works as expected', function() {

@@ -1103,2 +1123,26 @@ it('.delete should work', function (done) {

});
it('handles unknown errors', function(done) {
var app = express();
nock.disableNetConnect();
app.get('/', function(req, res) {
res.status(200).send('OK');
});
request(app)
.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
.expect(200)
.end(function(err, res) {
err.should.be.an.instanceof(Error);
err.message.should.match(/Nock: Not allow net connect/);
done();
});
nock.restore();
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc