Socket
Socket
Sign inDemoInstall

supertest

Package Overview
Dependencies
38
Maintainers
7
Versions
69
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.2.4 to 6.3.0

25

index.js

@@ -8,2 +8,8 @@ 'use strict';

const http = require('http');
let http2;
try {
http2 = require('http2'); // eslint-disable-line global-require
} catch (_) {
// eslint-disable-line no-empty
}
const Test = require('./lib/test.js');

@@ -20,7 +26,16 @@ const agent = require('./lib/agent.js');

*/
module.exports = function(app) {
module.exports = function(app, options = {}) {
const obj = {};
if (typeof app === 'function') {
app = http.createServer(app); // eslint-disable-line no-param-reassign
if (options.http2) {
if (!http2) {
throw new Error(
'supertest: this version of Node.js does not support http2'
);
}
app = http2.createServer(app); // eslint-disable-line no-param-reassign
} else {
app = http.createServer(app); // eslint-disable-line no-param-reassign
}
}

@@ -30,3 +45,7 @@

obj[method] = function(url) {
return new Test(app, method, url);
var test = new Test(app, method, url);
if (options.http2) {
test.http2();
}
return test;
};

@@ -33,0 +52,0 @@ });

40

lib/agent.js

@@ -10,2 +10,8 @@ 'use strict';

const http = require('http');
let http2;
try {
http2 = require('http2'); // eslint-disable-line global-require
} catch (_) {
// eslint-disable-line no-empty
}
const Test = require('./test.js');

@@ -21,11 +27,20 @@

function TestAgent(app, options) {
function TestAgent(app, options = {}) {
if (!(this instanceof TestAgent)) return new TestAgent(app, options);
if (typeof app === 'function') app = http.createServer(app); // eslint-disable-line no-param-reassign
if (options) {
this._ca = options.ca;
this._key = options.key;
this._cert = options.cert;
Agent.call(this, options);
this._options = options;
if (typeof app === 'function') {
if (options.http2) {
if (!http2) {
throw new Error(
'supertest: this version of Node.js does not support http2'
);
}
app = http2.createServer(app); // eslint-disable-line no-param-reassign
} else {
app = http.createServer(app); // eslint-disable-line no-param-reassign
}
}
Agent.call(this);
this.app = app;

@@ -49,6 +64,7 @@ }

TestAgent.prototype[method] = function(url, fn) { // eslint-disable-line no-unused-vars
const req = new Test(this.app, method.toUpperCase(), url, this._host);
req.ca(this._ca);
req.cert(this._cert);
req.key(this._key);
const req = new Test(this.app, method.toUpperCase(), url);
if (this._options.http2) {
req.http2();
}
if (this._host) {

@@ -61,4 +77,4 @@ req.set('host', this._host);

req.on('redirect', this._attachCookies.bind(this, req));
this._setDefaults(req);
this._attachCookies(req);
this._setDefaults(req);

@@ -65,0 +81,0 @@ return req;

@@ -9,3 +9,3 @@ 'use strict';

const { STATUS_CODES } = require('http');
const { Server } = require('https');
const { Server } = require('tls');
const { deepStrictEqual } = require('assert');

@@ -307,3 +307,8 @@ const { Request } = require('superagent');

let badStack;
const err = assertFn(res);
let err;
try {
err = assertFn(res);
} catch (e) {
err = e;
}
if (err instanceof Error && err.stack) {

@@ -310,0 +315,0 @@ badStack = err.stack.replace(err.message, '').split('\n').slice(1);

{
"name": "supertest",
"version": "6.2.4",
"description": "SuperAgent driven library for testing HTTP servers",
"main": "index.js",
"version": "6.3.0",
"author": "TJ Holowaychuk",
"contributors": [
"Dimitri DO BAIRRO <dimitri.dobairro@dimsolution.com>"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/visionmedia/supertest.git"
},
"engines": {
"node": ">=6.4.0"
},
"keywords": [
"superagent",
"request",
"tdd",
"bdd",
"http",
"test",
"testing"
],
"scripts": {
"lint": "eslint lib/**/*.js test/**/*.js index.js",
"lint:fix": "eslint --fix lib/**/*.js test/**/*.js index.js",
"pretest": "npm run lint",
"test": "nyc --reporter=html --reporter=text mocha --exit --require should --reporter spec --check-leaks",
"coverage": "nyc report --reporter=text-lcov | coveralls"
},
"contributors": [],
"dependencies": {

@@ -41,3 +14,2 @@ "methods": "^1.1.2",

"cookie-parser": "^1.4.6",
"coveralls": "^3.1.1",
"eslint": "^8.18.0",

@@ -50,4 +22,34 @@ "eslint-config-airbnb-base": "^15.0.0",

"nyc": "^15.1.0",
"proxyquire": "^2.1.3",
"should": "^13.2.3"
},
"engines": {
"node": ">=6.4.0"
},
"files": [
"index.js",
"lib"
],
"keywords": [
"bdd",
"http",
"request",
"superagent",
"tdd",
"test",
"testing"
],
"license": "MIT",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/visionmedia/supertest.git"
},
"scripts": {
"coverage": "nyc report --reporter=text-lcov > coverage.lcov",
"lint": "eslint lib/**/*.js test/**/*.js index.js",
"lint:fix": "eslint --fix lib/**/*.js test/**/*.js index.js",
"pretest": "npm run lint --if-present",
"test": "nyc --reporter=html --reporter=text mocha --exit --require should --reporter spec --check-leaks"
}
}
# SuperTest
[![Coveralls][coverage-badge]][coverage]
[![code coverage][coverage-badge]][coverage]
[![Build Status][travis-badge]][travis]

@@ -56,2 +56,33 @@ [![Dependencies][dependencies-badge]][dependencies]

To enable http2 protocol, simply append an options to `request` or `request.agent`:
```js
const request = require('supertest');
const express = require('express');
const app = express();
app.get('/user', function(req, res) {
res.status(200).json({ name: 'john' });
});
request(app, { http2: true })
.get('/user')
.expect('Content-Type', /json/)
.expect('Content-Length', '15')
.expect(200)
.end(function(err, res) {
if (err) throw err;
});
request.agent(app, { http2: true })
.get('/user')
.expect('Content-Type', /json/)
.expect('Content-Length', '15')
.expect(200)
.end(function(err, res) {
if (err) throw err;
});
```
Here's an example with mocha, note how you can pass `done` straight to any of the `.expect()` calls:

@@ -115,3 +146,3 @@

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

@@ -124,5 +155,3 @@ .get('/users')

assert(response.body.email, 'foo@bar.com')
done();
})
.catch(err => done(err))
});

@@ -304,4 +333,4 @@ });

[coverage-badge]: https://coveralls.io/repos/github/visionmedia/supertest/badge.svg?branch=master
[coverage]: https://coveralls.io/github/visionmedia/supertest?branch=master
[coverage-badge]: https://img.shields.io/codecov/c/github/visionmedia/supertest.svg
[coverage]: https://codecov.io/gh/visionmedia/supertest
[travis-badge]: https://travis-ci.org/visionmedia/supertest.svg?branch=master

@@ -308,0 +337,0 @@ [travis]: https://travis-ci.org/visionmedia/supertest

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc