npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

request-it

v0.0.7

Published

Helper for writing functional API tests in Mocha

Downloads

21

Readme

npm david

Request-It

This project is a (mostly) drop-in replacement for Mocha's it function and aims to improve on Mocha's default functionality by allowing:

  1. Clear arrange, act, and assert blocks
  2. Explicit API calls under test
  3. Flat, highly readable test blocks
  4. Informative test failure output
  5. Mocha-like syntax

Quick Start

Example usage:

const it = require('reqeust-it');

it('gets client quotes by date', async (request) => {
    // ARRANGE
    // ... setup test state here ...

    // ACT
    const result = await request({
        get: 'http://clientsapi.com/v2/client/123/quotes',
        headers: { Authorization: myToken },
        query: {
            date: '>2015',
            count: '20',
        }
    });

    // ASSERT
    // ... make assertions here ...
});

Note that as long as the test methods passed to it return Promises, tests using request-it are fully backwards compatible with vanilla Mocha. The only caveat is that callback-based asynchronous tests are not supported because they anticipate Mocha's done function whereas request-it passes a request function.

request

The request method provides a facade for making HTTP calls. It provides enough parameters to explicitly define the entire API call being tested.

Example GET request:

{
    get: 'http://clientsapi.com/v2/client/123/quotes',
    headers: { Authorization: myToken },
    query: {
        date: '>2015',
        count: '20',
    }
}

Example POST request:

{
    post: 'http://clientsapi.com/v2/client/123/quotes',
    headers: { Authorization: myToken },
    body: {
        date: '2017-09-01',
        price: 49.95,
    }
}

Parameters must include one HTTP method property (delete, get, head, options, patch, post, put) whose value is the URI to be called.

You can provide headers, query, and/or body parameters to add those values to the request. (Note that the query can also be included in the URI.)

Errors

The messages from any errors thrown before the request function is called will indicate that they originated from the "ARRANGE" block. This is useful to determine that the API method under test was not called and thus the test was technically inconclusive.

During the execution of request, error messages will indicate that they originated during the "ACT" block. The message will also include details about the request (method, URI, headers, etc).

Once the request function has resolved, errors messages (usually from AssertionErrors) will indicate that they occurred in the "ASSERT" block. They, too, will include details about the request (method, URI, headers, etc). Response details are not currently included.