supertape
πŸ“Ό Supertape simplest high speed test runner with superpowers
Last updated 10 months ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install supertape 
SYNC missed versions from official npm registry.

πŸ“Ό Supertape NPM version Build Status Coverage Status License: MIT

supertape

Tape-inspired TAP-compatible simplest high speed test runner with superpowers.

πŸ“Ό Supertape is a fast, minimal test runner with the soul of tape. It's designed to be as compatible as possible with tape while still having some key improvements, such as:

πŸ“Ό Supertape doesn't contain:

For a list of all built-in assertions, see Operators.

How πŸ“ΌSupertape test looks like?

You can use both CommonJS and ESM, here is ESM example:

import {test} from 'supertape';

const sump = (a, b) => a + b;

test('calc: sum', (t) => {
    const result = sum(1, 2);
    const expected = 3;
    
    t.equal(result, expected);
    t.end();
});

Install

npm i supertape -D

Usage

Usage: supertape [options] [path]
Options
   -h, --help                  display this help and exit
   -v, --version               output version information and exit
   -f, --format                use a specific output format - default: progress-bar/tap on CI
   -r, --require               require module
   --no-check-scopes           do not check that messages contains scope: 'scope: message'
   --no-check-assertions-count do not check that assertion count is no more then 1
   --no-check-duplicates       do not check messages for duplicates
   --no-worker                 disable worker thread

Environment variables

  • SUPERTAPE_TIMEOUT - timeout for long running processes, defaults to 3000 (3 seconds);
  • SUPERTAPE_CHECK_DUPLICATES - toggle check duplicates;
  • SUPERTAPE_CHECK_SCOPES - check that test message has a scope: scope: subject;
  • SUPERTAPE_CHECK_ASSERTIONS_COUNT - check that assertion count is no more then 1;
  • SUPERTAPE_CHECK_SKIPED - check that skiped count equal to 0, exit with status code;
  • SUPERTAPE_LOAD_LOOP_TIMEOUT - timeout for load tests, defaults to 5ms, when mocha used as runner - 50ms optimal;
test('tape: error', (t) => {
    t.equal(error.code, 'ENOENT');
    t.end();
});

🀷 How to migrate from tape?

You can convert your codebase from tape to πŸ“ΌSupertape with help of 🐊Putout, which has built-in @putout/plugin-tape, which has a lot of rules that helps to write tests. Here is result example.

ESLint rules

eslint-plugin-putout has rules for πŸ“ΌSupertape:

Operators

The assertion methods of πŸ“Ό Supertape are heavily influenced by tape. However, to keep a minimal core of assertions, there are no aliases and some superfluous operators have been removed (such as t.throws()).

The following is a list of the base methods maintained by πŸ“Ό Supertape. Others, such as assertions for stubbing, are maintained in special operators. To add custom assertion operators, see Extending.

Core Operators

t.equal(result: any, expected: any, message?: string)

Asserts that result and expected are strictly equal. If message is provided, it will be outputted as a description of the assertion.

Note: uses Object.is(result, expected)

t.notEqual(result: any, expected: any, message?: string)

Asserts that result and expected are not strictly equal. If message is provided, it will be outputted as a description of the assertion.

Note: uses !Object.is(result, expected)

t.deepEqual(result: any, expected: any, message?: string)

Asserts that result and expected are loosely equal, with the same structure and nested values. If message is provided, it will be outputted as a description of the assertion.

Note: uses node's deepEqual() algorithm with strict comparisons (===) on leaf nodes

t.notDeepEqual(result: any, expected: any, message?: string)

Asserts that result and expected not loosely equal, with different structure and/or nested values. If message is provided, it will be outputted as a description of the assertion.

Note: uses node's deepEqual() algorithm with strict comparisons (===) on leaf nodes

t.ok(result: boolean | any, message?: string)

Asserts that result is truthy. If message is provided, it will be outputted as a description of the assertion.

t.notOk(result: boolean | any, message?: string)

Asserts that result is falsy. If message is provided, it will be outputted as a description of the assertion.

t.pass(message: string)

Generates a passing assertion with message as a description.

t.fail(message: string)

Generates a failing assertion with message as a description.

t.end()

Declares the end of a test explicitly. Must be called exactly once per test. (See: Single Call to t.end())

t.match(result: string, pattern: string | RegExp, message?: string)

Asserts that result matches the regex pattern. If pattern is not a valid regex, the assertion fails. If message is provided, it will be outputted as a description of the assertion.

t.notMatch(result: string, pattern: string | RegExp, message?: string)

Asserts that result does not match the regex pattern. If pattern is not a valid regex, the assertion always fails. If message is provided, it will be outputted as a description of the assertion.

t.comment(message: string)

Print a message without breaking the TAP output. Useful when using a tap-reporter such as tap-colorize, where the output is buffered and console.log() will print in incorrect order vis-a-vis TAP output.

Special Operators

To simplify the core of πŸ“Ό Supertape, other operators are maintained in separate packages. The following is a list of all such packages:

Here is a list of built-int operators:

Package Version
@supertape/operator-stub npm

Formatters

There is a list of built-int formatters to customize output:

Package Version
@supertape/formatter-tap npm
@supertape/formatter-fail npm
@supertape/formatter-short npm
@supertape/formatter-progress-bar npm
@supertape/formatter-json-lines npm

API

test(message: string, fn: (t: Test) => void, options?: TestOptions)

Create a new test with message string. fn(t) fires with the new test object t once all preceding tests have finished. Tests execute serially.

Here is Possible options similar to Environment Variables but relates to one test:

  • checkDuplicates;
  • checkScopes;-
  • checkAssertionsCount;
  • timeout;

test.only(message, fn, options?)

Like test(name, cb) except if you use .only this is the only test case that will run for the entire process, all other test cases using tape will be ignored.

test.skip(message, fn, options?)

Generate a new test that will be skipped over.

test.extend(extensions)

Extend base assertions with more:

const {extend} = require('supertape');
const test = extend({
    transform: (operator) => (a, b, message = 'should transform') => {
        const {is, output} = operator.equal(a + 1, b - 1);
        
        return {
            is,
            output,
        };
    },
});

test('assertion', (t) => {
    t.transform(1, 3);
    t.end();
});

Example

const test = require('supertape');

test('lib: arguments', async (t) => {
    throw Error('hello');
    // will call t.fail with an error
    // will call t.end
});

test('lib: diff', (t) => {
    t.equal({}, {hello: 'world'}, 'should equal');
    t.end();
});

// output
`
- Expected
+ Received

- Object {}
+ Object {
+   "hello": "world",
+ }
`;

πŸšͺExit Codes

πŸ“ΌSupertape can have one of next exit codes:

Code Name Description
0 OK no errors found
1 FAIL test failed
2 WAS_STOP test was halted by user
3 UNHANDLED unhandled exception occurred
4 INVALID_OPTION wrong option provided
5 SKIPED works only with SUPERTAPE_CHECK_SKIPED env variable when skiped files 1 and more

Here is how exit code can look like:

import {SKIPED} from 'supertape/exit-codes';

const env = {
    ESCOVER_SUCCESS_EXIT_CODE: SKIPED,
    SUPERTAPE_CHECK_SKIPED: 1,
};

export default {
    test: () => [env, `escover tape 'test/**/*.js' 'lib/**/*.spec.js'`],
};

License

MIT

Current Tags

  • 10.7.1                                ...           latest (6 months ago)

168 Versions

  • 10.7.1                                ...           6 months ago
  • 10.7.0                                ...           7 months ago
  • 10.6.1                                ...           7 months ago
  • 10.6.0                                ...           8 months ago
  • 10.5.0                                ...           9 months ago
  • 10.4.0                                ...           10 months ago
  • 10.3.0                                ...           10 months ago
  • 10.2.2                                ...           10 months ago
  • 10.2.1                                ...           10 months ago
  • 10.2.0                                ...           10 months ago
  • 10.1.0                                ...           10 months ago
  • 10.0.0                                ...           a year ago
  • 9.5.0                                ...           a year ago
  • 9.4.0                                ...           a year ago
  • 9.3.0                                ...           a year ago
  • 9.2.0                                ...           a year ago
  • 9.1.0                                ...           a year ago
  • 9.0.0                                ...           a year ago
  • 8.10.0                                ...           a year ago
  • 8.9.0                                ...           a year ago
  • 8.8.0                                ...           a year ago
  • 8.7.0                                ...           a year ago
  • 8.6.1                                ...           a year ago
  • 8.6.0                                ...           a year ago
  • 8.5.0                                ...           a year ago
  • 8.4.1                                ...           a year ago
  • 8.4.0                                ...           a year ago
  • 8.3.0                                ...           2 years ago
  • 8.2.0                                ...           2 years ago
  • 8.1.0                                ...           2 years ago
  • 8.0.1                                ...           2 years ago
  • 8.0.0                                ...           2 years ago
  • 7.7.1                                ...           2 years ago
  • 7.7.0                                ...           2 years ago
  • 7.6.0                                ...           2 years ago
  • 7.5.1                                ...           3 years ago
  • 7.5.0                                ...           3 years ago
  • 7.4.1                                ...           3 years ago
  • 7.4.0                                ...           3 years ago
  • 7.3.0                                ...           3 years ago
  • 7.2.3                                ...           3 years ago
  • 7.2.2                                ...           3 years ago
  • 7.2.1                                ...           3 years ago
  • 7.2.0                                ...           3 years ago
  • 7.1.1                                ...           3 years ago
  • 7.1.0                                ...           3 years ago
  • 7.0.1                                ...           3 years ago
  • 7.0.0                                ...           3 years ago
  • 6.13.1                                ...           3 years ago
  • 6.13.0                                ...           3 years ago
  • 6.12.1                                ...           3 years ago
  • 6.12.0                                ...           3 years ago
  • 6.11.0                                ...           3 years ago
  • 6.10.0                                ...           3 years ago
  • 6.9.4                                ...           3 years ago
  • 6.9.3                                ...           3 years ago
  • 6.9.2                                ...           3 years ago
  • 6.9.1                                ...           3 years ago
  • 6.9.0                                ...           3 years ago
  • 6.8.2                                ...           3 years ago
  • 6.8.1                                ...           3 years ago
  • 6.8.0                                ...           3 years ago
  • 6.7.4                                ...           3 years ago
  • 6.7.3                                ...           3 years ago
  • 6.7.2                                ...           3 years ago
  • 6.7.1                                ...           3 years ago
  • 6.7.0                                ...           3 years ago
  • 6.6.0                                ...           3 years ago
  • 6.5.0                                ...           3 years ago
  • 6.4.0                                ...           3 years ago
  • 6.3.1                                ...           3 years ago
  • 6.3.0                                ...           3 years ago
  • 6.2.0                                ...           3 years ago
  • 6.1.1                                ...           3 years ago
  • 6.1.0                                ...           3 years ago
  • 6.0.5                                ...           3 years ago
  • 6.0.4                                ...           3 years ago
  • 6.0.3                                ...           3 years ago
  • 6.0.2                                ...           3 years ago
  • 6.0.1                                ...           3 years ago
  • 6.0.0                                ...           3 years ago
  • 5.8.1                                ...           3 years ago
  • 5.8.0                                ...           3 years ago
  • 5.7.0                                ...           3 years ago
  • 5.6.0                                ...           3 years ago
  • 5.5.0                                ...           3 years ago
  • 5.4.1                                ...           4 years ago
  • 5.4.0                                ...           4 years ago
  • 5.3.0                                ...           4 years ago
  • 5.2.0                                ...           4 years ago
  • 5.1.0                                ...           4 years ago
  • 5.0.0                                ...           4 years ago
  • 4.9.2                                ...           4 years ago
  • 4.9.1                                ...           4 years ago
  • 4.9.0                                ...           4 years ago
  • 4.8.2                                ...           4 years ago
  • 4.8.1                                ...           4 years ago
  • 4.8.0                                ...           4 years ago
  • 4.7.0                                ...           4 years ago
  • 4.6.0                                ...           4 years ago
  • 4.5.1                                ...           4 years ago
  • 4.5.0                                ...           4 years ago
  • 4.4.0                                ...           4 years ago
  • 4.3.1                                ...           4 years ago
  • 4.3.0                                ...           4 years ago
  • 4.2.0                                ...           4 years ago
  • 4.1.1                                ...           4 years ago
  • 4.1.0                                ...           4 years ago
  • 4.0.1                                ...           4 years ago
  • 4.0.0                                ...           4 years ago
  • 3.13.1                                ...           4 years ago
  • 3.13.0                                ...           4 years ago
  • 3.12.0                                ...           4 years ago
  • 3.11.0                                ...           4 years ago
  • 3.10.0                                ...           4 years ago
  • 3.9.2                                ...           4 years ago
  • 3.9.1                                ...           4 years ago
  • 3.9.0                                ...           4 years ago
  • 3.8.2                                ...           4 years ago
  • 3.8.1                                ...           4 years ago
  • 3.8.0                                ...           4 years ago
  • 3.7.3                                ...           4 years ago
  • 3.7.2                                ...           4 years ago
  • 3.7.1                                ...           4 years ago
  • 3.7.0                                ...           4 years ago
  • 3.6.2                                ...           4 years ago
  • 3.6.1                                ...           4 years ago
  • 3.6.0                                ...           4 years ago
  • 3.5.0                                ...           4 years ago
  • 3.4.3                                ...           4 years ago
  • 3.4.2                                ...           4 years ago
  • 3.4.1                                ...           4 years ago
  • 3.4.0                                ...           4 years ago
  • 3.3.1                                ...           4 years ago
  • 3.3.0                                ...           4 years ago
  • 3.2.0                                ...           4 years ago
  • 3.1.3                                ...           4 years ago
  • 3.1.2                                ...           4 years ago
  • 3.1.1                                ...           4 years ago
  • 3.1.0                                ...           4 years ago
  • 3.0.3                                ...           4 years ago
  • 3.0.2                                ...           4 years ago
  • 3.0.1                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 2.0.1                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.3.10                                ...           5 years ago
  • 1.3.9                                ...           5 years ago
  • 1.3.8                                ...           5 years ago
  • 1.3.7                                ...           5 years ago
  • 1.3.6                                ...           5 years ago
  • 1.3.5                                ...           5 years ago
  • 1.3.4                                ...           5 years ago
  • 1.3.3                                ...           5 years ago
  • 1.3.2                                ...           5 years ago
  • 1.3.1                                ...           5 years ago
  • 1.3.0                                ...           5 years ago
  • 1.2.4                                ...           5 years ago
  • 1.2.3                                ...           6 years ago
  • 1.2.2                                ...           6 years ago
  • 1.2.1                                ...           6 years ago
  • 1.2.0                                ...           6 years ago
  • 1.1.1                                ...           6 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.3                                ...           6 years ago
  • 1.0.2                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Total 1
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dev Dependencies (18)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE