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

wrestle

v0.1.0

Published

A REST API testing library.

Downloads

5

Readme

Wrestle

A REST API unit testing framework

Wrestle enables you to unit test and automatically document your API from the command line or the browser by specifying intuitive, unit tests for each route.

Features

  • Simple unit test defintion.
  • Run tests in the browser or from the command line.
  • Generate documentation (with themes) from the test spec.

Installation

Install Wrestle with npm.

$ npm install wrestle -g

Tests

Defining tests with Wrestle is as simple as defining the route, the HTTP method and the expected JSON response.

wrestle.describe("Get user named 'foo'")
.get("/user/foo").expect({
	username: "foo",
	id: /\w{6}/
});

wrestle.post("/user", {
	username: "bar"
}).expect(200, {
	success: true
});

Command Line

Wrestle tests can be executed from the command line by simple supplying the file to the wrestle test command then run the tests.

$ wrestle test path/to/tests.js

Command line example

Browser

Wrestle tests can also be run in the browser. Define your tests and include index.js, browser/interface.js and the test file.

There are a couple of caveats however due to the Cross-Origin Resource Sharing (CORS) policy which doesn't allow cross-domain requests (or in fact any requests from a static page) so the following options to enable testing in the browser.

  1. Host and run the tests under the same domain as the API.
  2. Start Chrome with the --disable-web-security flag to disable the CORS security.
  3. Enable CORS in your API's headers.

Documentation

Command line

wrestle -- Simple REST API testing
  help 			 		Shows this help.
  test <file> 			Run a test file.
    --simple  		 	Simple output report
    --report  		 	Just output report
    --i x..y   		 	Run tests numbers x through to y
    --i x, y, z		 	Run tests x, y, z only
  doc <file> 			Output API documentation
    --theme <theme>		Output documentation with theme from doc/theme/
    --output <path>		Specify output path for documentation. Defaults to test file directory.

Test defintion API

wrestle.describe( <string> )

Describe a test case. This is the description variable in the documentation generator

wrestle.describe("Generate a random username")
	.post("/username").expect({
		username: String
	});

wrestle.method( <path>, <data> )

Create a test case for a GET, PUT, POST or DELETE HTTP method. path can contain variables expanded by wrestle.format. data is the request data to be passed along to the server. Data specified alongside the GET method will be converted to URL parameters.

wrestle.get("/user/foo").expect({
	username: "foo",
	email: String
});

<test>.expect( <code>, <responseSchema>, <callback> )

Define the response schema for a test. code is the expected HTTP status code. responseSchema is the schema for the JSON response, see wrestle.schema for a full description on defining schemas.

wrestle.get("/404").expect(404);

wrestle.get("/user/foo").expect({
	id: Number,
	name: String,
	gender: /male|female/
});

wrestle.<request|response>.schema( <method>, <code>, <responseSchema> )

Define a schema for request data or JSON response that matches either the request method, HTTP status code or both. A schema is an object that defines a set of rules another a request or response object must conform to. Wrestle loops over the object and tests if the property exists in the schema and that the property's value is of the same type as the schema or matches a regular expression. Schemas can contain variables which will be replaced by values when the request is executed (variables are defined using wrestle.define).

wrestle.response.schema(200, {
	meta: {
		code: 200,
		url: String,
		error: Boolean
	}
});

wrestle.request.schema("post", {
	session: ":session",
	auth: {
		username: "admin",
		password: "root"
	}
});

wrestle.define( <name>, <value> )

Define a variable for use within schemas or paths which can be accessed using the : prefix.

Suite tools

wrestle.on( <event>, <callback> )

Add an event listener to the test suite using .on or .addEventListener. Below is a list of events and the details sent to them.

Below is the list of events sent to a test. These can be binded to the test sent when the test event above is called.

wrestle.begin( [x, y, x] | [upper, lower] )

Begin testing. Optionally pass in array of test indexs or bound to only run selected tests.

wrestle.pause()

Pause testing.

wrestle.run()

Resume testing.

Themes

Wrestle can compile your API spec into some pretty informative documentation. It does this with a Mustache templating system. As is matures, more complex data will be passed into the documentation and maybe even a selection of templating engines but for now, it's fairly basic. Below is a table of all the variables passed into the theme. See the Mustache.js documentation for some help in theme formatting.

TODO

  • Create a GUI for the browser