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

supertest-oauth

v0.1.6

Published

Supertest extensions, adding oauth functionality

Readme

supertest-oauth

These are my extensions to SuperTest. Originaly forked by supertest-oauth

Features

Append request and response contents to stack trace

When a test fails, the stack trace displayed by Mocha (or whatever you use) won't contain information about the request itself. I mean, it's good to see that you got an HTTP 500 instead of the expected 200, but what was the error message? What was the data you sent in that request?

supertest-oauth keeps track of the currently running request and, on error, appends all relevant information to the stack trace: request URL, headers, and body as well as response headers and body. You don't need to do anything to enable this, it just works.

Since that information can be quite a lot of output, the maximum length of attached response body data can be limited:

// Limit to 500 characters, the default.
supertest.setMaxBodyDump(500);

// Disable the limit.
supertest.setMaxBodyDump(Infinity);

It would be useful if all of the requests were written to a file for later analysis, but this is currently not implemented.

Easy HTTP Basic auth, defaults possible

To easily use HTTP Basic authentication in your calls, you can use the auth() method, which also supports setting defaults:

var supertest = require("supertest-oauth");

// Simple authed request.
supertest(app)
	.get("/whatever")
	.auth("user", "pass")
	.expect(200)
	.end(done)

// Set default credentials.
supertest.defaultCredentials("user", "pass");

// Use default credentials.
supertest(app)
	.get("/whatever")
	.auth()
	.expect(200)
	.end(done)

Show request/response data for certain tests

There is a convenience wrapper that you can use to log information about any request, for example to show what is actually sent to or received from the server. This information is part of the request dump that's appended to the stack trace of failed test (see above), but using this wrapper you can do that for tests that don't fail as well. Simply use .end(supertest.debug(done)) instead of a plain .end(done).

Methods for generating random strings

First of all, these are not perfect, but they work for me. You can access them using supertest.methodName(). Here are some examples for all methods that exist:

var supertest = require("supertest-oauth");

supertest.getRandomChar("asdff")
// Returns either "a", "s", "d" or "f", with "f" being twice as likely to be
// returned than the others.

supertest.generateRandomString(5, "abc", "def", "ghi")
// Returns a string that's 5 characters long and consists of one of "abc",
// then three of "def" (duplicates can happen), then one of "ghi", so for
// example "bdedg".

supertest.generateRandomString(5, "abc", "def")
// Equivalent to (5, "abc", "def", "def").

supertest.generateRandomString(5, "abc")
// Equivalent to (5, "abc", "abc", "abc").

supertest.generateRandomLengthString(5, 10, "abc", "def", "ghi")
// Calls generateRandomString with a count parameter between 5 and 10,
// inclusive. The strings are passed unmodified. You can omit some of them
// in the same way.

supertest.generateConservativeDomain()
// Returns a domain with top and second-level part, e.g. "xyzzy.wtf". (Yes,
// the TLD is a random string, but only 2 or 3 characters long.)

supertest.generateLiberalDomain()
// Returns a domain with a random number of parts, which have a random
// length as well. There is no check for the maxium length of the whole
// string. (Which is possibly a bug.)

supertest.generateConservativeEmail()
// Returns an e-mail address with a valid local part and a "conservative"
// domain.

Shortcut for sending form data

We define request(foo).sendForm(data), which is just a shortcut for request(foo).type("form").send(data).

Extension vs. fork

Instead of forking SuperTest and implementing the new features there, this project chose to extend the SuperTest code by messing around with the functions and objects it defines. This is a bit clumsy sometimes, but works surprisingly well. If TJ Holowaychuk is interested, I can integrate some or all of the supertest-oauth features in SuperTest. However, this would introduce more dependencies and more code, and since SuperTest is quite minimal, I'm not sure whether he's interested in that.

The stability of the request dumps

To do these request dumps, supertest-oauth wraps the original .get(), .post() etc. methods and keeps track of the most recent one using a module-global variable. And if a test returns an error, attachCurrentRequestToError() is called to attach a string representation of the request and response to the stack trace.