# webtap

> TAP wrapper for testing webservers

Latest version **0.2.0** (published 2013-04-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install webtap
pnpm add webtap
yarn add webtap
bun add webtap
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2013-04-10 |
| First published | 2013-03-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Julian Gruber |
| Maintainers | juliangruber |
| Keywords | tap,, test,, server,, webserver |

## Links

- npm: https://www.npmjs.com/package/webtap
- Repository: https://github.com/juliangruber/webtap
- npm.io page: https://npm.io/package/webtap

## Recent versions

- 0.2.0 (latest) — 2013-04-10
- 0.1.3 — 2013-03-21
- 0.1.2 — 2013-03-21
- 0.1.1 — 2013-03-21
- 0.1.0 — 2013-03-18
- 0.0.0 — 2013-03-18

## README

# webtap

A TAP wrapper for testing webservers

[![Build Status](https://travis-ci.org/juliangruber/webtap.png)](https://travis-ci.org/juliangruber/webtap)

## Usage

Write a test for your webserver:

```js
// 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:

```bash
$ 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 object
* `res`, the response object from `http.request()`

The test name is either `name` or a combination of `method` and `path`, like `GET /`.

`path` can be left out if `method` already contains the path, like:

```js
test('name', 'GET /', cb);
test('GET /', cb);
```

### 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.

If `str` is not a string but any other JavaScript object, the response will be parsed as JSON and
compared to `str`.

### t.*

See the [tap documentation](https://github.com/isaacs/node-tap).

## Installation

With [npm](http://npmjs.org) do

```bash
$ npm install webtap
```

and

```bash
$ npm install -g tap
```

## License

(MIT)

---
_Source: https://npm.io/package/webtap · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
