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

tupe

v0.0.0-alpha.3

Published

Generic unit-testing framework for front-end

Downloads

16

Readme

Tupe

licence npm version npm downloads

API | Congiguration | Examples | FAQ

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

Features

  • 🚀 Blazing fast: Tupe use the great Parcel as bundler, and Puppeteer as runtime environment under the hook, making it fast on both bundle-time and runtime.
  • 🌓 Isolation & 🎎 Concurrency: Each test file is bundled and run as a isolated new tab on puppeteer concurrently.
  • 🎨 Descriptive assertion: bonus with Power-Assert builtin.
  • 🐦 Configuration-Free: almost no configuration, except for some basic babel setup, which might agrees to your project setup already
  • ❄️ Simplicity. use the standard assert interface.

Motivations

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

  • some requires a bit configuration, like karma, not simple enough.
  • when it comes to front-end code testing that requires a browser environment, many of them utilize jsdom, which is a subset emulation of a web browser for use in nodejs environment. That's awesome, but would it be great and more reliable if our code runs in a real-world browser?
  • features like concurrency and isolation are great. You should definitely try out AVA and Jest, they are awesome. But again, they don't seems to bundle for a real-world browser? Correct me if I'm wrong, thanks~
  • Puppeteer is born, which seems to be a perfect fit for browser-side JavaScript testing. Maybe we can try it out and learn how to build a unit test runner, And have all the fun along the way, that's the whole point..

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

  • files: file or glob for test files
  • tmpdir: this is a temporary folder used by Parcel for compiled files
  • fail-fast: in a test file, global before or after hooks failure will always terminate the runner as failure; For each individual case, if a beforeEach hook failed, this case itself and its afterEach hooks will not be executed, a case-failure event will araise and the runner will continue to the next case. However, by setting this option to true, any case failure will terminate the runner of that test file.
  • coverage: options for istanbul, defaults to this
{
    "tupe": {
        "files": [
            "test/**/*.js"
        ],
        "tmpdir": ".tmp",
        "fail-fast": false,
        "coverage": {
            "dir": "test/.coverage",
            "reporters": ["text"],
            "check": {
            }
        }
    }
}

API

  • test.before([title], fn(t, [callback]))
  • test.beforeEach([title], fn(t, [callback]))
  • test.afterEach([title], fn(t, [callback]))
  • test.after([title], fn(t, [callback]))
  • test(title, fn(t, [callback]))
  • t is a enhenced assert function, added with a additional t.context abject as a isolated context for each case, live through beforeEach due afterEach hook

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

render1539627393699

FAQ