Registry / testing / http-testify

http-testify

JSON →
library1.0.3jsnpmunverified

HTTPtestify is a Node.js library designed for comprehensive integration testing of HTTP APIs. It provides a promise-based API, drawing inspiration from Axios, to facilitate making HTTP requests, asserting response properties, and conducting end-to-end tests. The current stable version is 1.0.3, with releases driven by feature additions and minor bug fixes rather than a strict schedule. Key differentiators include its extensive support for various HTTP methods (GET, POST, PUT, DELETE), advanced request customization (headers, body, query parameters), and sophisticated parallel request handling capabilities like `all`, `race`, and `allSettled`. The library also offers features such as request cancellation, proxy support, robust cookie and session management, and automatic parsing of JSON and optional XML responses, making it a versatile tool for complex API testing scenarios.

npm install http-testify
INSTALL
IMPORT
SIG · HTTP-TESTIFY
H
http-testify
testingjavascriptv1.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HTTPtestify
import HTTPtestify from 'http-testify';
const HTTPtestify = require('http-testify');
While the library's `README` uses `require` for CommonJS, modern Node.js applications and TypeScript projects should prefer the ESM `import` syntax. The package is designed with TypeScript in mind, ensuring proper type inference with `import`.
request
const server = HTTPtestify.request(app);
import { request } from 'http-testify';
`request` is a method on the default-imported `HTTPtestify` object, used to initialize a test server instance. It is not a named export that can be destructured directly from the package.
get
server.get('/api/data').then(...);
HTTPtestify.get('/api/data').then(...);
HTTP methods like `get`, `post`, `put`, etc., are invoked on the `server` instance returned by `HTTPtestify.request(app)`, not directly on the main `HTTPtestify` object.

Demonstrates how to set up `http-testify` with a simple Express server, make GET and POST requests, and execute parallel requests, logging their responses.

import HTTPtestify from 'http-testify'; import express from 'express'; // Common framework for HTTP APIs // 1. Create a minimal Express app instance for testing const app = express(); app.use(express.json()); // Enable JSON body parsing for POST requests // Define a simple GET endpoint app.get('/api/status', (req, res) => { res.status(200).json({ status: 'ok', version: '1.0' }); }); // Define a simple POST endpoint app.post('/api/submit', (req, res) => { const data = req.body; res.status(201).json({ message: 'Data received', received: data }); }); // 2. Initialize HTTPtestify with the app instance const server = HTTPtestify.request(app); // 3. Define an async test function async function runExampleTests() { try { // Perform a GET request const getResponse = await server.get('/api/status'); console.log('GET /api/status Status:', getResponse.status); // Expected: 200 console.log('GET /api/status Data:', getResponse.data); // Expected: { status: 'ok', version: '1.0' } // Perform a POST request with a JSON body const postResponse = await server.post('/api/submit', { item: 'widget', quantity: 5 }); console.log('POST /api/submit Status:', postResponse.status); // Expected: 201 console.log('POST /api/submit Data:', postResponse.data); // Expected: { message: 'Data received', received: { item: 'widget', quantity: 5 } } // Demonstrate parallel GET requests const [res1, res2] = await server.all((instance) => [ instance.get('/api/status'), instance.get('/api/status') ]); console.log('Parallel Requests Results:', res1.status, res2.status); console.log('\nAll example tests completed successfully!'); } catch (error) { console.error('An error occurred during tests:', error); } } runExampleTests();
Debug
Known issues
gotchaWhen migrating from older CommonJS (`require`) patterns to modern ESM (`import`) in Node.js, ensure your project's `package.json` and TypeScript configuration are set up for ESM, as `http-testify` ships with types and is designed for modern usage.
fix
Use `import HTTPtestify from 'http-testify';` and ensure `type: 'module'` in `package.json` or configure TypeScript to emit ESM.
affects: >=1.0.0
gotchaAsynchronous operations with `http-testify` require proper handling of Promises. Forgetting `await` or neglecting `.then().catch()` chains can lead to tests completing prematurely or unhandled promise rejections, making debugging difficult.
fix
Always use `await` with `http-testify` methods in `async` functions, or chain `.then()` for successful responses and `.catch()` for error handling.
affects: >=1.0.0
gotchaWhile `http-testify` manages the lifecycle of its internal mock server, it's crucial to ensure proper test isolation and cleanup within your test suite. Shared state or external resources not properly reset between tests can lead to flaky results.
fix
Design tests to be stateless where possible. For stateful scenarios, use test runner hooks (e.g., `beforeEach`, `afterEach` in Jest/Mocha) to reset application state or mock external dependencies.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: HTTPtestify.request is not a function
Attempting to destructure `request` as a named import (e.g., `import { request } from 'http-testify'`) when it's a method on the default export.
fix
Import the default `HTTPtestify` object and then call `HTTPtestify.request(app)`.
AssertionError: Expected status 200, got 404
The tested API endpoint returned an unexpected HTTP status code, often due to an incorrect route, missing handler, or server-side error.
fix
Verify the endpoint path, HTTP method, and server-side route definitions. Check server logs for internal errors during the request.
UnhandledPromiseRejectionWarning: This error originated either by throwing an error inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().
An `http-testify` operation (or subsequent assertion) rejected a Promise, and the rejection was not caught by an `await` within a `try/catch` block or a `.catch()` handler.
fix
Wrap asynchronous test code in `try...catch` blocks, or ensure all Promises are handled with `.catch()` to log or assert on errors explicitly.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
http-testify — npm install http-testify · libregistry