Skip to content
This repository has been archived by the owner on Oct 12, 2017. It is now read-only.
/ retest Public archive

Request driven library for testing node.js HTTP servers

License

Notifications You must be signed in to change notification settings

blakeembrey/retest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Retest

Greenkeeper badge

NPM version NPM downloads Build status Test coverage

Request driven library for testing node.js HTTP servers via request.

Note: This library is not heavily maintained. If you're looking for a functional request library with hte ability to mount servers during tests, consider trying Popsicle with the server plugin.

Installation

npm install retest --save-dev

Usage

You may pass a http.Server, function or string to retest() - if the server is not listening for connections it will be bound to an ephemeral port so there is no need to keep track of ports.

var retest  = require('retest');
var express = require('express');

var app = express();

app.get('/', function (req, res) {
  res.send('hello');
});

retest(app).get('/user', function (err, res) {
  if (err) throw err;
});

A retest instance accepts the same arguments as request, including the options object.

Multipart Requests

A multipart request can be sent using the form-data module. Just use retest.form() to create an instance and pass it as the body option, as you would any other object.

var retest = require('retest');
var test   = retest(app);

var form = test.form();

// Append fields and files as you normally would.
form.append('username', 'blakeembrey');
form.append('password', 'hunter2');

test.post({
  uri: '/user',
  body: form
}, function (err, res) {
  // ...
});

Callbacks

The callback function is called with two arguments, the error and response. The response body will be automatically parsed when possible based on the content type (current application/json and application/x-www-form-urlencoded).

Agent

Create an instance that will reuse cookies between requests by calling retest.agent(app).

License

MIT

About

Request driven library for testing node.js HTTP servers

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published