0.2.0 • Published 11 years ago
webtap v0.2.0
webtap
A TAP wrapper for testing webservers
Usage
Write a test for your webserver:
// test/test.js
var webtap = require('webtap');
var test = webtap(function (req, res) {
res.statusCode = 404;
res.end('file not found');
});
test('GET', '/', function (t, res) {
t.equal(res.statusCode, 404);
t.body('file not found');
});
test('custom name', 'POST', '/', function (t, res) {
t.equal(res.statusCode, 404);
t.body('file not found');
});
Then execute it:
$ tap test/test.js
TAP version 13
# GET /
ok 1 status code 404
ok 2 friendly message
# custom name
ok 3 status code 404
ok 4 friendly message
1..4
# tests 4
# pass 4
# ok
API
var test = webtap(server)
Return the test
function. server
can either be a request handler function (e.g. what express
exports) or a server from http.createServer()
.
test(name, method, path, cb)
Fire a request with method
on path
to the given server
can call cb
with:
t
, the TAP test objectres
, the response object fromhttp.request()
The test name is either name
or a combination of method
and path
, like GET /
.
t.body(str, msg)
t
is augmented by a body
method that buffers the request body into a string, compares it with
str
and then calls t.end()
to finish the test.
t.*
See the tap documentation.
Installation
With npm do
$ npm install webtap
and
$ npm install -g tap
License
(MIT)