Neatly Positioned Magazines

    supertape

    5.5.0 • Public • Published

    Supertape NPM version Dependency Status Build Status Coverage Status

    Tape compatible TAP test runner with superpowers. Contains:

    • ability to work with esm modules (take a look at mock-import for mocking).
    • shows colored diff when test not equal or not deepEqual;
    • produces deteiled stack traces for async functions;
    • as many only as you wish
    • ability to extend
    • smart timeouts for long running tests 🏃‍♂️(configured with SUPERTAPE_TIMEOUT);
    • more natural assertions: expected, result -> result, expected, for example:
    t.equal(error.message, 'hello world', `expected error.message to be 'hello world'`);

    Doesn't contain:

    • es3 code and lot's of ponyfills.
    • aliases, methods list much shorter;
    • throws, doesNotThrows - use tryCatch, tryToCatch with equal instead.

    Supertape was written from scratch after messing a lot with tape, it inspired by tape and willing to be compatible with it.

    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
    

    Codemod

    You can convert your codebase from tape to supertape with help of a putout and built-in @putout/plugin-tape. Here is example of a result.

    API

    Methods

    The assertion methods in supertape are heavily influenced or copied from the methods in tape.

    const test = require('supertape');

    test(name, cb)

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

    test.only(name, cb)

    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(name, cb)

    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();
    });

    t.end()

    Declare the end of a test explicitly.

    t.fail(msg)

    Generate a failing assertion with a message msg.

    t.pass(msg)

    Generate a passing assertion with a message msg.

    t.ok(value, msg)

    Assert that value is truthy with an optional description of the assertion msg.

    t.notOk(value, msg)

    Assert that value is falsy with an optional description of the assertion msg.

    t.match(actual, regexp [, msg])

    Assert that regexp.test matches actual with an optional description of the assertion msg.

    t.equal(actual, expected, msg)

    Assert that Object.is(actual, expected) with an optional description of the assertion msg.

    t.notEqual(actual, expected, msg)

    Assert that !Object.is(actual, expected) with an optional description of the assertion msg.

    t.deepEqual(actual, expected, msg)

    Assert that actual and expected have the same structure and nested values using node's deepEqual() algorithm with strict comparisons (===) on leaf nodes and an optional description of the assertion msg.

    t.notDeepEqual(actual, expected, msg)

    Assert that actual and expected do not have the same structure and nested values using node's deepEqual() algorithm with strict comparisons (===) on leaf nodes and an optional description of the assertion msg.

    t.comment(message)

    Print a message without breaking the tap output. (Useful when using e.g. tap-colorize where output is buffered & console.log will print in incorrect order vis-a-vis tap output.)

    Example

    const test = require('supertape');
    
    test('lib: arguments', async (t) => {
        throw Error('hello');
        // will call t.fail with an error
        // will call t.end
        
        t.end();
    });
    
    test('lib: diff', (t) => {
        t.equal({}, {hello: 'world'}, 'should equal');
        t.end();
    });
    
    // output
    `
    - Expected
    + Received
    
    - Object {}
    + Object {
    +   "hello": "world",
    + }
    `;

    License

    MIT

    Install

    npm i supertape

    DownloadsWeekly Downloads

    190

    Version

    5.5.0

    License

    MIT

    Unpacked Size

    39.9 kB

    Total Files

    19

    Last publish

    Collaborators

    • avatar