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

A Node.js library for testing HTTP servers.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
94
decreased by-24.19%
Maintainers
1
Weekly downloads
 
Created
Source

HTTPtestify

HTTPtestify is a versatile library for testing HTTP APIs in Node.js environments. It provides a promise-based API inspired by Axios, allowing you to make HTTP requests, perform assertions on responses, and conduct integration testing with ease.

Features

  • Promise-Based API: Enjoy a promise-based API that lets you make HTTP requests using async/await and promise chaining, promoting clean and readable code.
  • Integration Testing: Seamlessly perform integration tests on your HTTP APIs to ensure they function as intended.
  • HTTP Request Methods: Support for various HTTP request methods, including GET, POST, PUT, DELETE, and more, allowing interaction with diverse API endpoints.
  • Request Customization: Tailor your requests with ease, adjusting headers, query parameters, and request bodies as required.
  • Response Assertions: Utilize chainable methods to validate different aspects of responses, such as status codes, headers, and response data.
  • Chaining Requests: Seamlessly chain requests together, enabling complex testing scenarios with dependent requests.
  • Parallel Requests (All): Perform multiple requests simultaneously using the all method, receiving an array of responses when all requests complete.
  • Parallel Requests (Race): Race multiple requests with the race method, resolving with the response of the first completed request.
  • Parallel Requests (AllSettled): Perform parallel requests using allSettled, resolving with an array of response states, including both successful responses and errors.
  • Custom Port: Set a custom port between 1 and 65535 for the mock server instance, allowing flexibility in defining the server's listening port.
  • Cancellation: Cancel pending requests when they're no longer needed, preventing unnecessary processing.
  • Concurrent Requests: Boost performance by sending multiple requests concurrently.
  • Error Handling: Automatically handle network errors and HTTP errors, providing comprehensive error information.
  • Proxy Support: Seamlessly navigate proxies with configuration options for smoother testing.
  • JSON and XML Handling: Automatically parse JSON responses and optionally support XML responses for easy assertion and testing.
  • Download and Upload Progress: Monitor progress when dealing with large files, ensuring efficient request handling.
  • Cookie Handling: Simplify authentication and stateful API testing with methods to manage and assert cookies.
  • Session Persistence: Maintain session continuity between requests, crucial for scenarios that involve sequential interactions.

Installation

You can install HTTPtestify using npm:

npm install http-testify

Usage

Making HTTP Requests

To make HTTP requests using HTTPtestify, you can follow this example:

const HTTPtestify = require("http-testify");
const app = require("./your-app"); // Replace with your actual app instance

// Create a mock server instance with the target app and port
const server = HTTPtestify.request(app);

// Make a GET request to a specific route
server
  .get("/api/data")
  .then((response) => {
    console.log("Response from /api/data:", response.data);
  })
  .catch((error) => {
    console.error("Error occurred:", error);
  });

Parallel Requests with all

You can perform multiple requests in parallel using the all method:

// Use promise-based operations
const promises = server
  .all((instance) => [instance.get("/api/data1"), instance.get("/api/data2")])
  .then((responses) => {
    console.log("All responses:", responses);
  })
  .catch((error) => {
    console.error("An error occurred:", error);
  });

Docs

HTTPtestify provides a variety of methods to facilitate testing HTTP interactions. Check the documentation for detailed information.

Contributing

Contributions to HTTPtestify are welcome! Feel free to submit issues and pull requests on the GitHub repository.

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. ❤️

License

This project is licensed under the MIT License.

Keywords

FAQs

Package last updated on 11 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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