Home

Awesome

Tupe

<!-- Badges -->

licence npm version npm downloads

Features | Motivations | Configuration | API | Examples | FAQ

A generic unit-testing runner for front-end.➰

Features

Motivations

There are already tons of unit-testing runner/framework for JavaScript.

Install

yarn add --dev tupe

CLI

tupe <files...>

Run Tests

Positionals:
  files  path or glob for test files                                    [string]

Options:
  -h, --help     Show help                                             [boolean]
  -v, --verbose                                                 [default: false]
  --watch        watch mode                                     [default: false]
  --port         server port                                     [default: 1234]
  --tmpdir       temporary directory                           [default: ".tmp"]
  --fail-fast    exit on first fail                    [boolean] [default: true]

Configuration

You can configure Tupe by specifying a tupe field at your project's package.json

{
    "tupe": {
        "files": [
            "test/**/*.js"
        ],
        "tmpdir": ".tmp",
        "fail-fast": false,
        "coverage": {
            "dir": "test/.coverage",
            "reporters": ["text"],
            "check": {
            }
        }
    }
}

.babelrc

{
    "presets": ["@babel/env", "power-assert"],
    "plugins": [
        ["babel-plugin-espower", {
            "patterns": [
                "t(value, [message])",
                "t.ok(value, [message])",
                "t.equal(actual, expected, [message])",
                "t.deepEqual(actual, expected, [message])",
                "t.notEqual(actual, expected, [message])",
                "t.strictEqual(actual, expected, [message])",
                "t.notStrictEqual(actual, expected, [message])",
                "t.notDeepEqual(actual, expected, [message])",
                "t.deepStrictEqual(actual, expected, [message])",
                "t.notDeepStrictEqual(actual, expected, [message])",
                "t.throws(block, [error], [message])"
            ]
        }]
    ],
    "env": {
        "test": {
            "plugins": [
                ["istanbul", {
                    "include": [
                        "src/**/*.js"
                    ]
                }]
            ]
        }
    }
}

API

Examples

import test from 'tupe';

test('hello tupe!', t => {
    const who = { name: 'Tupe!' };
    t(who.name === 'Tupe!');
});

test('async waiting...', async t => {
    const answer = true;
    await new Promise(r => setTimeout(r, 1500));
    t(answer === true);
});

test('misspell my name ?', t => {
    const who = { name: 'Hello Tupe!' };
    t(who.name === 'Hel' + 'o Tupe~');
});

test('use callback ?', (t, done) => {
    setTimeout(() => {
        t('dump' === 'dump');
        done();
    }, 1500);
});

test('array assert', t => {
    const runners = ['AVA', 'Tupe'];
    t(runners.indexOf('Tupe') === 0);
});

render1539706926643

FAQ