Supertest with Proxy Support
supertest-with-proxy is a specialized wrapper around the popular `supertest` library, designed to facilitate testing HTTP servers that require proxy configurations. It extends `supertest`'s capabilities by enabling the specification of an HTTP proxy for test requests, a common requirement in enterprise or complex network environments. The current stable version is 5.0.2. This package appears to be abandoned, with its last publish occurring over six years ago, meaning there are no active releases or maintenance, and its compatibility with modern Node.js or `supertest` versions is uncertain. Its key differentiator was providing direct proxy integration, which standard `supertest` does not offer out-of-the-box, simplifying testing for proxy-aware applications with a familiar, chainable API.
Common errors
-
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".js" for /path/to/node_modules/supertest-with-proxy/index.js
cause Attempting to import a CommonJS-only package using ES Module `import` syntax in an ESM project.fixChange `import request from 'supertest-with-proxy';` to `const request = require('supertest-with-proxy');`. -
supertest-with-proxy is not a function
cause This error can occur if `require('supertest-with-proxy')` returns `undefined` or an unexpected value, often due to Node.js version incompatibility or an issue during module loading.fixEnsure your Node.js version is compatible (though old versions are specified, newer ones might break it). Reinstall the package (`npm install supertest-with-proxy`) to rule out corrupted node_modules. Check for conflicting dependencies or global Node.js module issues.
Warnings
- breaking The package has not been updated in over six years and is considered abandoned. This means no new features, bug fixes, or security patches will be released, potentially leading to critical vulnerabilities or incompatibility with modern environments.
- gotcha The `engines.node` field specifies `>=6.0.0`, which is an extremely old Node.js version. Running this package on recent Node.js versions (e.g., Node.js 16, 18, 20+) may lead to unexpected behavior or runtime errors due to breaking changes in Node.js itself.
- gotcha The package's README points to a specific fork of `supertest` (`tauheedkhan/supertest` or `soniajasuja/supertest`) rather than the official, actively maintained `supertest` package. This suggests it might be tightly coupled to an older or specific `supertest` version, leading to potential API inconsistencies or a lack of support for features introduced in newer `supertest` releases.
Install
-
npm install supertest-with-proxy -
yarn add supertest-with-proxy -
pnpm add supertest-with-proxy
Imports
- request
import request from 'supertest-with-proxy';
const request = require('supertest-with-proxy'); - request
const { request } = require('supertest-with-proxy');const request = require('supertest-with-proxy'); - request
import { request } from 'supertest-with-proxy';const request = require('supertest-with-proxy');
Quickstart
const request = require('supertest-with-proxy');
const express = require('express');
const app = express();
app.get('/user', function(req, res) {
res.status(200).json({ name: 'john' });
});
request(app)
.get('/user')
.proxy('http://example.com')
.expect('Content-Type', /json/)
.expect('Content-Length', '15')
.expect(200)
.end(function(err, res) {
if (err) throw err;
console.log('Test passed for user endpoint with proxy.');
});