# tests

> Console test runner - writes to stdin, reads stdout

Latest version **0.4.2** (published 2013-01-21) · 0 weekly downloads

## Install

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

Provides the command `tests`.

## 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.4.2 |
| Published | 2013-01-21 |
| First published | 2012-05-03 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Fyodor Sheremetyev |
| Maintainers | sheremetyev |
| Keywords | test, console, stdin, stdout |

## Links

- npm: https://www.npmjs.com/package/tests
- Repository: https://github.com/sheremetyev/tests.js
- npm.io page: https://npm.io/package/tests

## Dependencies (3)

- [chai](https://npm.io/package/chai.md) 0.5.x
- [mocha](https://npm.io/package/mocha.md) 1.0.x
- [walkdir](https://npm.io/package/walkdir.md) *

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 0.4.2 (latest) — 2013-01-21
- 0.4.1 — 2012-12-22
- 0.4.0 — 2012-06-06
- 0.3.0 — 2012-06-05
- 0.2.0 — 2012-05-12
- 0.1.1 — 2012-05-03
- 0.1.0 — 2012-05-03
- 0.0.1 — 2012-05-03

## README

tests.js
========

Console Test Runner: writes to stdin, reads stdout.

**tests.js** is useful for test-driven development of command-line utilities.
Works on Mac OS X, Windows and Linux so you can write cross-platform tests.
Tests do not depend on the implementation language of the program.

Usage
=====

You will need Node.js and NPM. Install using the following command.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$ npm install -g tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Then create some `.test` files and execute the following command in the folder
with tests.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$ tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Test files should have the following structure.

-   first line—command to execute (can be relative path, can contain pipeline of
    several commands),

-   then `<<<` and input to send to the program (can be multiple lines),

-   then `>>>` and expected output.

[Example][1]:

[1]: <https://github.com/sheremetyev/tests.js/blob/master/test/wc.test>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wc
<<<
one two three
>>>
       1       3      14
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This test executes `wc` command, sends string `one two three` to its stdin and
checks the output of the program.

When the test is run you should see something like

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
✓  /path/to/tests/wc.test: 9ms

✔  1 test complete (9ms)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To compare program’s output with expected output not as literal strings but as
JSON objects write `>>>JSON` in the test file instead of `>>>`.

For more examples see
<https://github.com/sheremetyev/texts.js/tree/master/test>.

Acknowledgements
================

The idea was borrowed from John MacFarlane’s tests format in Pandoc2.

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