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

http-testify

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-testify - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

2

dist/cjs/instances/request.js

@@ -47,3 +47,3 @@ "use strict";

function requestInstance(server, configOptions) {
const { timeout = 30 * 1000 } = configOptions || {};
const { timeout = 30 * 1000 } = configOptions !== null && configOptions !== void 0 ? configOptions : {};
const instance = axios_1.default.create({

@@ -50,0 +50,0 @@ baseURL: server.baseUrl,

@@ -74,22 +74,20 @@ "use strict";

function serverInstance(app, configOptions) {
const { port = 65025 } = configOptions || {};
const { port = 65025 } = configOptions !== null && configOptions !== void 0 ? configOptions : {};
let server;
if (typeof app === "function") {
server = http.createServer(app);
let keepOpen = false;
switch (typeof app) {
case "function":
server = http.createServer(app);
server.baseUrl = `http://localhost:${port}`;
break;
case "object":
server = app;
server.baseUrl = `http://localhost:${port}`;
break;
default:
server = {};
server.baseUrl = app;
}
else if (typeof app === "object") {
server = app;
}
else {
server = {};
}
if (["function", "object"].includes(typeof app)) {
server.baseUrl = `http://localhost:${port}`;
}
else {
server.baseUrl = typeof app == "string" ? app : undefined;
}
server.start = function () {
if (["function", "object"].includes(typeof app) &&
typeof server.address != "undefined") {
if (typeof server.address != "undefined" && !keepOpen) {
server = server.listen(port);

@@ -99,9 +97,20 @@ }

server.end = function () {
if (["function", "object"].includes(typeof app) &&
typeof server.getConnections !== "undefined") {
if (typeof server.getConnections !== "undefined" && !keepOpen) {
server.close();
}
};
server.stayConnected = function () {
if (!keepOpen) {
server.start();
keepOpen = true;
}
};
server.closeConnection = function () {
if (keepOpen) {
keepOpen = false;
server.close();
}
};
return server;
}
exports.serverInstance = serverInstance;

@@ -55,7 +55,13 @@ "use strict";

const module = (0, default_1.defaultModule)(server, configOptions);
module.all = (0, promise_1.promiseModule)(server, configOptions).all;
module.allSettled = (0, promise_1.promiseModule)(server, configOptions).allSettled;
module.race = (0, promise_1.promiseModule)(server, configOptions).race;
const promiseModuleInstance = (0, promise_1.promiseModule)(server, configOptions);
module.all = promiseModuleInstance.all;
module.allSettled = promiseModuleInstance.allSettled;
module.race = promiseModuleInstance.race;
module.closeConnection = server.closeConnection;
module.stayConnected = () => {
server.stayConnected();
return module;
};
return module;
}
exports.request = request;

@@ -5,2 +5,3 @@ /// <reference types="node" />

import { Express } from "express";
export type ANY = any;
/**

@@ -10,24 +11,49 @@ * Represents a callback function that provides an Axios instance and returns an array of promises for Axios responses.

* @param {AxiosInstance} instance - The Axios instance to use for making requests.
* @returns {Array<Promise<AxiosResponse<any, any>>>} - An array of promises for Axios responses.
* @returns {Array<Promise<AxiosResponse<ANY, ANY>>>} - An array of promises for Axios responses.
*/
export type RequestPromiseCallback = (instance: AxiosInstance) => Array<Promise<AxiosResponse<any, any>>>;
export type RequestPromiseCallback = (instance: AxiosInstance) => Array<Promise<AxiosResponse<ANY, ANY>>>;
/**
* Represents an array of Axios responses returned from multiple concurrent requests using `Axios.all`.
*/
export type RequestAllResponse = AxiosResponse<any, any>[];
export type RequestAllResponse = AxiosResponse<ANY, ANY>[];
/**
* Represents an array of promise settlement results from multiple concurrent requests using `Axios.allSettled`.
*/
export type RequestAllSettledResponse = PromiseSettledResult<AxiosResponse<any, any>>[];
export type RequestAllSettledResponse = PromiseSettledResult<AxiosResponse<ANY, ANY>>[];
/**
* Represents an Axios response from a request that wins a race among multiple concurrent requests using `Axios.race`.
*/
export type RequestRaceResponse = AxiosResponse<any, any>;
export type RequestRaceResponse = AxiosResponse<ANY, ANY>;
/**
* Represents an instance of Axios, extended with additional methods like `all`, `allSettled`, and `race`.
* RequestInstance represents an AxiosInstance with extended functionality for making HTTP requests.
*/
export type RequestInstance = AxiosInstance & {
/**
* Performs multiple HTTP requests in parallel and returns an array of responses.
* @param callback - A function that specifies the requests to be made.
* @returns A Promise that resolves to an array of responses.
*/
all: (callback: RequestPromiseCallback) => Promise<RequestAllResponse>;
/**
* Performs multiple HTTP requests in parallel and returns an array of response states.
* Response states include both successful responses and errors.
* @param callback - A function that specifies the requests to be made.
* @returns A Promise that resolves to an array of response states.
*/
allSettled: (callback: RequestPromiseCallback) => Promise<RequestAllSettledResponse>;
/**
* Races multiple HTTP requests and returns the response of the first completed request.
* @param callback - A function that specifies the requests to be raced.
* @returns A Promise that resolves to the response of the first completed request.
*/
race: (callback: RequestPromiseCallback) => Promise<RequestRaceResponse>;
/**
* Ensures that the connection to the server is maintained, preventing it from being closed.
* @returns The modified RequestInstance with a maintained connection.
*/
stayConnected: () => RequestInstance;
/**
* Closes the connection to the server.
*/
closeConnection: () => void;
};

@@ -38,3 +64,3 @@ /**

*/
export type RequestApp = Express | http.Server | ((...res: any) => void | Promise<void>) | string;
export type RequestApp = Express | http.Server | ((...res: ANY) => void | Promise<void>) | string;
/**

@@ -54,3 +80,3 @@ * Represents configuration options that can be used to customize request-related settings.

/**
* Represents an instance of an HTTP server, extended with methods to start and end the server.
* Represents an instance of an HTTP server, extended with methods to start, end, stay connected, and close the server.
*/

@@ -60,2 +86,12 @@ export type ServerInstance = http.Server & {

* Starts the server instance and makes it listen on the specified port.
*
* @remarks
* This method starts the server instance and makes it listen on the specified port. If the server is already running, calling this method may have no effect.
*
* @example
* ```typescript
* // Example: Start the server instance
* serverInstance.start();
* // The server starts listening on the specified port.
* ```
*/

@@ -65,2 +101,12 @@ start: () => void;

* Ends the server instance, stopping it from listening.
*
* @remarks
* This method stops the server instance from listening, effectively ending its operation. Subsequent requests to the server will not be accepted after calling this method.
*
* @example
* ```typescript
* // Example: End the server instance
* serverInstance.end();
* // The server stops listening and is no longer active.
* ```
*/

@@ -72,2 +118,30 @@ end: () => void;

baseUrl?: string;
/**
* Ensures that the server remains connected by starting it if not already running.
*
* @remarks
* This method checks if the server is not already running (based on the `keepOpen` flag). If the server is not running, it starts the server instance using the `start` method.
*
* @example
* ```typescript
* // Example: Ensure the server remains connected
* serverInstance.stayConnected();
* // If the server was not already running, it starts and remains connected.
* ```
*/
stayConnected: () => void;
/**
* Closes the server connection if it is currently open.
*
* @remarks
* This method checks if the server connection is currently open (based on the `keepOpen` flag). If the server connection is open, it closes the server instance using the `end` method.
*
* @example
* ```typescript
* // Example: Close the server connection if it is open
* serverInstance.closeConnection();
* // If the server connection was open, it is closed.
* ```
*/
closeConnection: () => void;
};

@@ -47,3 +47,3 @@ "use strict";

function requestInstance(server, configOptions) {
const { timeout = 30 * 1000 } = configOptions || {};
const { timeout = 30 * 1000 } = configOptions !== null && configOptions !== void 0 ? configOptions : {};
const instance = axios_1.default.create({

@@ -50,0 +50,0 @@ baseURL: server.baseUrl,

@@ -74,22 +74,20 @@ "use strict";

function serverInstance(app, configOptions) {
const { port = 65025 } = configOptions || {};
const { port = 65025 } = configOptions !== null && configOptions !== void 0 ? configOptions : {};
let server;
if (typeof app === "function") {
server = http.createServer(app);
let keepOpen = false;
switch (typeof app) {
case "function":
server = http.createServer(app);
server.baseUrl = `http://localhost:${port}`;
break;
case "object":
server = app;
server.baseUrl = `http://localhost:${port}`;
break;
default:
server = {};
server.baseUrl = app;
}
else if (typeof app === "object") {
server = app;
}
else {
server = {};
}
if (["function", "object"].includes(typeof app)) {
server.baseUrl = `http://localhost:${port}`;
}
else {
server.baseUrl = typeof app == "string" ? app : undefined;
}
server.start = function () {
if (["function", "object"].includes(typeof app) &&
typeof server.address != "undefined") {
if (typeof server.address != "undefined" && !keepOpen) {
server = server.listen(port);

@@ -99,9 +97,20 @@ }

server.end = function () {
if (["function", "object"].includes(typeof app) &&
typeof server.getConnections !== "undefined") {
if (typeof server.getConnections !== "undefined" && !keepOpen) {
server.close();
}
};
server.stayConnected = function () {
if (!keepOpen) {
server.start();
keepOpen = true;
}
};
server.closeConnection = function () {
if (keepOpen) {
keepOpen = false;
server.close();
}
};
return server;
}
exports.serverInstance = serverInstance;

@@ -55,7 +55,13 @@ "use strict";

const module = (0, default_1.defaultModule)(server, configOptions);
module.all = (0, promise_1.promiseModule)(server, configOptions).all;
module.allSettled = (0, promise_1.promiseModule)(server, configOptions).allSettled;
module.race = (0, promise_1.promiseModule)(server, configOptions).race;
const promiseModuleInstance = (0, promise_1.promiseModule)(server, configOptions);
module.all = promiseModuleInstance.all;
module.allSettled = promiseModuleInstance.allSettled;
module.race = promiseModuleInstance.race;
module.closeConnection = server.closeConnection;
module.stayConnected = () => {
server.stayConnected();
return module;
};
return module;
}
exports.request = request;

@@ -5,2 +5,3 @@ /// <reference types="node" />

import { Express } from "express";
export type ANY = any;
/**

@@ -10,24 +11,49 @@ * Represents a callback function that provides an Axios instance and returns an array of promises for Axios responses.

* @param {AxiosInstance} instance - The Axios instance to use for making requests.
* @returns {Array<Promise<AxiosResponse<any, any>>>} - An array of promises for Axios responses.
* @returns {Array<Promise<AxiosResponse<ANY, ANY>>>} - An array of promises for Axios responses.
*/
export type RequestPromiseCallback = (instance: AxiosInstance) => Array<Promise<AxiosResponse<any, any>>>;
export type RequestPromiseCallback = (instance: AxiosInstance) => Array<Promise<AxiosResponse<ANY, ANY>>>;
/**
* Represents an array of Axios responses returned from multiple concurrent requests using `Axios.all`.
*/
export type RequestAllResponse = AxiosResponse<any, any>[];
export type RequestAllResponse = AxiosResponse<ANY, ANY>[];
/**
* Represents an array of promise settlement results from multiple concurrent requests using `Axios.allSettled`.
*/
export type RequestAllSettledResponse = PromiseSettledResult<AxiosResponse<any, any>>[];
export type RequestAllSettledResponse = PromiseSettledResult<AxiosResponse<ANY, ANY>>[];
/**
* Represents an Axios response from a request that wins a race among multiple concurrent requests using `Axios.race`.
*/
export type RequestRaceResponse = AxiosResponse<any, any>;
export type RequestRaceResponse = AxiosResponse<ANY, ANY>;
/**
* Represents an instance of Axios, extended with additional methods like `all`, `allSettled`, and `race`.
* RequestInstance represents an AxiosInstance with extended functionality for making HTTP requests.
*/
export type RequestInstance = AxiosInstance & {
/**
* Performs multiple HTTP requests in parallel and returns an array of responses.
* @param callback - A function that specifies the requests to be made.
* @returns A Promise that resolves to an array of responses.
*/
all: (callback: RequestPromiseCallback) => Promise<RequestAllResponse>;
/**
* Performs multiple HTTP requests in parallel and returns an array of response states.
* Response states include both successful responses and errors.
* @param callback - A function that specifies the requests to be made.
* @returns A Promise that resolves to an array of response states.
*/
allSettled: (callback: RequestPromiseCallback) => Promise<RequestAllSettledResponse>;
/**
* Races multiple HTTP requests and returns the response of the first completed request.
* @param callback - A function that specifies the requests to be raced.
* @returns A Promise that resolves to the response of the first completed request.
*/
race: (callback: RequestPromiseCallback) => Promise<RequestRaceResponse>;
/**
* Ensures that the connection to the server is maintained, preventing it from being closed.
* @returns The modified RequestInstance with a maintained connection.
*/
stayConnected: () => RequestInstance;
/**
* Closes the connection to the server.
*/
closeConnection: () => void;
};

@@ -38,3 +64,3 @@ /**

*/
export type RequestApp = Express | http.Server | ((...res: any) => void | Promise<void>) | string;
export type RequestApp = Express | http.Server | ((...res: ANY) => void | Promise<void>) | string;
/**

@@ -54,3 +80,3 @@ * Represents configuration options that can be used to customize request-related settings.

/**
* Represents an instance of an HTTP server, extended with methods to start and end the server.
* Represents an instance of an HTTP server, extended with methods to start, end, stay connected, and close the server.
*/

@@ -60,2 +86,12 @@ export type ServerInstance = http.Server & {

* Starts the server instance and makes it listen on the specified port.
*
* @remarks
* This method starts the server instance and makes it listen on the specified port. If the server is already running, calling this method may have no effect.
*
* @example
* ```typescript
* // Example: Start the server instance
* serverInstance.start();
* // The server starts listening on the specified port.
* ```
*/

@@ -65,2 +101,12 @@ start: () => void;

* Ends the server instance, stopping it from listening.
*
* @remarks
* This method stops the server instance from listening, effectively ending its operation. Subsequent requests to the server will not be accepted after calling this method.
*
* @example
* ```typescript
* // Example: End the server instance
* serverInstance.end();
* // The server stops listening and is no longer active.
* ```
*/

@@ -72,2 +118,30 @@ end: () => void;

baseUrl?: string;
/**
* Ensures that the server remains connected by starting it if not already running.
*
* @remarks
* This method checks if the server is not already running (based on the `keepOpen` flag). If the server is not running, it starts the server instance using the `start` method.
*
* @example
* ```typescript
* // Example: Ensure the server remains connected
* serverInstance.stayConnected();
* // If the server was not already running, it starts and remains connected.
* ```
*/
stayConnected: () => void;
/**
* Closes the server connection if it is currently open.
*
* @remarks
* This method checks if the server connection is currently open (based on the `keepOpen` flag). If the server connection is open, it closes the server instance using the `end` method.
*
* @example
* ```typescript
* // Example: Close the server connection if it is open
* serverInstance.closeConnection();
* // If the server connection was open, it is closed.
* ```
*/
closeConnection: () => void;
};
{
"name": "http-testify",
"version": "1.0.1",
"version": "1.0.2",
"description": "A Node.js library for testing HTTP servers.",

@@ -45,4 +45,4 @@ "author": "Alok Shete",

"test-suite": "yarn test test/**/*.test.ts",
"prepare": "npm run build",
"prepublishOnly": "npm run test-suite"
"prepublishOnly": "npm run test-suite",
"format": "prettier --write . && eslint --fix . "
},

@@ -58,5 +58,13 @@ "files": [

"@types/mocha": "^10.0.1",
"@types/node": "^20.6.2",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"chai": "^4.3.8",
"eslint": "^8.49.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"express": "^4.18.2",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"prettier": "^3.0.3",
"ts-node": "^10.9.1",

@@ -66,5 +74,4 @@ "typescript": "^4.9.5"

"dependencies": {
"axios": "^1.4.0",
"express": "^4.18.2"
"axios": "^1.4.0"
}
}

@@ -76,14 +76,14 @@ # HTTPtestify

HTTPtestify provides a variety of methods to facilitate testing HTTP interactions. Check the [documentation](https://httptestify.web.app) for detailed information.
HTTPtestify provides a variety of methods to facilitate testing HTTP interactions. Check the <a href = "https://httptestify.web.app" target="_blank">documentation</a> for detailed information.
## Contributing
Contributions to HTTPtestify are welcome! Feel free to submit issues and pull requests on the [GitHub repository](https://github.com/alok-shete/http-testify).
Contributions to HTTPtestify are welcome! Feel free to submit issues and pull requests on the <a href = "https://github.com/alok-shete/http-testify" target="_blank">GitHub repository<a>.
## Donate
Please consider donating if you think HTTPtestify is helpful to you or that my work is valuable. I am happy if you can help me [buy a cup of coffee. ❤️](https://www.buymeacoffee.com/shetealok)
Please consider donating if you think HTTPtestify is helpful to you or that my work is valuable. I am happy if you can help me <a href = "https://www.buymeacoffee.com/shetealok" target="_blank">buy a cup of coffee. ❤️
## License
This project is licensed under the [MIT License](https://github.com/alok-shete/http-testify/blob/main/LICENSE).
This project is licensed under the<a href = "https://github.com/alok-shete/http-testify/blob/main/LICENSE" target="_blank">MIT License</a>
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