npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

Iโ€™ve always been into building performant and accessible sites, but lately Iโ€™ve been taking it extremely seriously. So much so that Iโ€™ve been building a tool to help me optimize and monitor the sites that I build to make sure that Iโ€™m making an attempt to offer the best experience to those who visit them. If youโ€™re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, ๐Ÿ‘‹, Iโ€™m Ryan Hefnerย  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If youโ€™re interested in other things Iโ€™m working on, follow me on Twitter or check out the open source projects Iโ€™ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soonโ€“ish.

Open Software & Tools

This site wouldnโ€™t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you ๐Ÿ™

ยฉ 2024 โ€“ย Pkg Stats / Ryan Hefner

supertape

v10.7.3

Published

๐Ÿ“ผ Supertape simplest high speed test runner with superpowers

Downloads

2,393

Readme

๐Ÿ“ผ 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