Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ladjs/supertest
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v7.0.0
Choose a base ref
...
head repository: ladjs/supertest
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v7.1.0
Choose a head ref
  • 7 commits
  • 5 files changed
  • 3 contributors

Commits on Oct 28, 2024

  1. test: fix test failure due to localhost being also ipv6

    Depending on runtime environment, "localhost" might resolve to both IPv4 and IPv6, resulting in an AggregateError in place of an Error.
    ikonst committed Oct 28, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    Letiste Léo Salé
    Copy the full SHA
    92079a0 View commit details

Commits on Mar 19, 2025

  1. fix: avoid server re-use race conditions

    Prevents ECONNRESET when the same HTTP Server is used for more than 3
    simultaneous connections.
    
    Closes #709
    Closes #844
    
    Ref:
    
    * #846
    alxndrsn committed Mar 19, 2025
    Copy the full SHA
    96c06e3 View commit details
  2. fix(dev): commitlint dev dependency & config

    alxndrsn committed Mar 19, 2025
    Copy the full SHA
    e67fcb2 View commit details

Commits on Mar 20, 2025

  1. Merge pull request #854 from alxndrsn/commitlint

    fix(dev): commitlint dev dependency & config
    titanism authored Mar 20, 2025
    Copy the full SHA
    35ac86f View commit details
  2. Merge pull request #845 from ikonst/master

    test: fix test failure due to localhost being also ipv6
    titanism authored Mar 20, 2025
    Copy the full SHA
    be0d5c7 View commit details
  3. Merge pull request #852 from alxndrsn/econnreset

    fix: avoid server re-use race conditions
    titanism authored Mar 20, 2025
    Copy the full SHA
    de045d4 View commit details
  4. 7.1.0

    titanism committed Mar 20, 2025
    Copy the full SHA
    359bc52 View commit details
Showing with 46 additions and 13 deletions.
  1. +3 −0 .commitlintrc.js
  2. +1 −5 index.js
  3. +16 −1 lib/test.js
  4. +3 −1 package.json
  5. +23 −6 test/supertest.js
3 changes: 3 additions & 0 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional']
};
6 changes: 1 addition & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@
* Module dependencies.
*/
const methods = require('methods');
const http = require('http');
let http2;
try {
http2 = require('http2'); // eslint-disable-line global-require
@@ -32,15 +31,12 @@ module.exports = function(app, options = {}) {
'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
}
}

methods.forEach(function(method) {
obj[method] = function(url) {
var test = new Test(app, method, url);
var test = new Test(app, method, url, options.http2);
if (options.http2) {
test.http2();
}
17 changes: 16 additions & 1 deletion lib/test.js
Original file line number Diff line number Diff line change
@@ -5,10 +5,17 @@
*/

const { inspect } = require('util');
const http = require('http');
const { STATUS_CODES } = require('http');
const { Server } = require('tls');
const { deepStrictEqual } = require('assert');
const { Request } = require('superagent');
let http2;
try {
http2 = require('http2'); // eslint-disable-line global-require
} catch (_) {
// eslint-disable-line no-empty
}

/** @typedef {import('superagent').Response} Response */

@@ -22,9 +29,17 @@ class Test extends Request {
* @param {String} path
* @api public
*/
constructor (app, method, path) {
constructor (app, method, path, optHttp2) {
super(method.toUpperCase(), path);

if (typeof app === 'function') {
if (optHttp2) {
app = http2.createServer(app); // eslint-disable-line no-param-reassign
} else {
app = http.createServer(app); // eslint-disable-line no-param-reassign
}
}

this.redirects(0);
this.buffer();
this.app = app;
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"name": "supertest",
"description": "SuperAgent driven library for testing HTTP servers",
"version": "7.0.0",
"version": "7.1.0",
"author": "TJ Holowaychuk",
"contributors": [],
"dependencies": {
"methods": "^1.1.2",
"superagent": "^9.0.1"
},
"devDependencies": {
"@commitlint/cli": "17",
"@commitlint/config-conventional": "17",
"body-parser": "^1.20.2",
"cookie-parser": "^1.4.6",
"eslint": "^8.32.0",
29 changes: 23 additions & 6 deletions test/supertest.js
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ describe('request(url)', function () {
});

server = app.listen(function () {
const url = 'http://localhost:' + server.address().port;
const url = 'http://127.0.0.1:' + server.address().port;
request(url)
.get('/')
.expect('hello', done);
@@ -51,7 +51,7 @@ describe('request(url)', function () {
});

server = app.listen(function () {
const url = 'http://localhost:' + server.address().port;
const url = 'http://127.0.0.1:' + server.address().port;
const test = request(url).get('/');
test.end(function (err, res) {
this.should.eql(test);
@@ -79,6 +79,23 @@ describe('request(app)', function () {
});
});

it('should not ECONNRESET on multiple simultaneous tests', function (done) {
const app = express();

app.get('/', function (req, res) {
res.send('hey');
});

const test = request(app);

const requestCount = 10;

const requests = [];
for (let i = 0; i < requestCount; i += 1) requests.push(test.get('/'));

global.Promise.all(requests).then(() => done(), done);
});

it('should work with an active server', function (done) {
const app = express();
let server;
@@ -107,7 +124,7 @@ describe('request(app)', function () {
});

server = app.listen(function () {
const url = 'http://localhost:' + server.address().port;
const url = 'http://127.0.0.1:' + server.address().port;
request(url)
.get('/')
.end(function (err, res) {
@@ -328,7 +345,7 @@ describe('request(app)', function () {
});

server = app.listen(function () {
const url = 'http://localhost:' + server.address().port;
const url = 'http://127.0.0.1:' + server.address().port;
request(url)
.get('/')
.timeout(1)
@@ -348,7 +365,7 @@ describe('request(app)', function () {
});

server = app.listen(function () {
const url = 'http://localhost:' + server.address().port;
const url = 'http://127.0.0.1:' + server.address().port;
server.close();
request(url)
.get('/')
@@ -381,7 +398,7 @@ describe('request(app)', function () {

describe('.expect(status)', function () {
it('should handle connection error', function (done) {
const req = request.agent('http://localhost:1234');
const req = request.agent('http://127.0.0.1:1234');

req
.get('/')