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

zora

v6.0.0

Published

the lightest yet the fastest javascript testing library

Downloads

2,463

Readme

Zora

npm install size

Usage

The library is a regular Javascript module and can be directly imported from a CDN:

import {test} from 'https://unpkg.com/zora@latest/dist/index.js'

test(`hello from zora`, ({ok}) => {
    ok(true, 'it worked');
})

(Like in the following codepen)

Or installed via a package manager such NPM by running the command (assuming you have Nodejs installed on your machine):

npm i -D zora

You can then build your testing program by using the exported test function

import {test} from 'zora';

test(`my very first test`, (assertion) => {
    const input = false;
    assertion.ok(input, 'input should be truthy');
})

You can run the testing program (with node's runtime for example) and it will start reporting its execution into the console

TAP version 13
# my very first test
not ok 1 - input should be truthy
  ---
    actual: false
    expected: "truthy value"
    operator: "ok"
    at: " file:///path/to/sample.js:5:13"
  ...

1..1
# tests 1
# pass  0
# fail  1
# skip  0

Reporters

This output format is called TAP (Test Anything Protocol). It is a standard text based format a machine can easily parse. It means there are plenty of reporters you can pipe the standard output stream into (not only in the Javascript world). This will help you to tailor the reporting for your particular needs.

for example, you can use tap-diff: node path/to/testing/program.js | tap-diff

You can even use basic bash command:

node path/to/testing/program.js | grep '^not ok\|^\s' will output a basic, straight to the point test report:

not ok 1 - input should be truthy
  ---
    actual: false
    expected: "truthy value"
    operator: "ok"
    at: " file:///path/to/sample.js:5:13"
  ...

That is the beauty of using different processes to run the testing program and to format its output: it remains very flexible.

Assertion API

When you start a test suite with the test function. The spec functions you pass as argument will get an instance of the Assertion object so you can write a wide range of different expectations.

For the best performances, all the spec functions run concurrently unless you specifically wait for them within an asynchronous function (if for some reason, you want to run some test one after the other, in a serial mode).

import {test} from 'zora';

let state = 0;

test('test 1', t => {
    t.ok(true);
    state++;
});

test('test 2', t => {
    //Maybe yes maybe no, you have no guarantee ! In this case it will work as everything is sync
    t.equal(state, 1);
});

//Same thing here even in nested tests
test('grouped', t => {
    let state = 0;

    t.test('test 1', t => {
        t.ok(true);
        state++;
    });

    t.test('test 2', t => {
        //Maybe yes maybe no, you have no guarantee ! In this case it will work as everything is sync
        t.equal(state, 1);
    });
});

//And
test('grouped', t=>{
    let state = 0;

    t.test('test 1', async t=>{
        t.ok(true);
        await wait(100);
        state++;
    });

    test('test 2', t=>{
        t.equal(state, 0, 'see the old state value as it will have started to run before test 1 is done');
    });
});

//But
test('grouped', async t => {
    let state = 0;

    //specifically WAIT for the end of this test before moving on !
    await t.test('test 1', async t => {
        t.ok(true);
        await wait(100);
        state++;
    });

    test('test 2', t => {
        t.equal(state, 1, 'see the updated value!');
    });
});

Environment variables

You can configure the testing program with environment variables. With nodejs, simply pass it with the command line:

ZORA_REPORTER=json node path/to/testing/program.js

In the browser, you have to set it as a global before the testing program runs:

<script>
    window.ZORA_REPORTER='json'
</script>
<script type="module">
    import {test} from 'url/to/zora';
    
    test('some test', (t) => {
        t.ok(true);
    })
</script>

ZORA_REPORTER=json

By default, the output is a TAP stream; but you can decide to produce a stream defined by the zora json protocol messages if you which to build a custom reporter on top of it.

ZORA_ONLY=true

Beside the test function you can use the only function if you wish to skip all the other tests. However, from the testing program perspective, only is meaningless: it is just a convenience for a developer, locally on its machine.
So if you wish to use only you need to pass the ZORA_ONLY environment variable, otherwise the program will throw an exception to prevent only statement to slip in the remote versioning control system.

Beware that if you want to run only a nested test suite, all the parent test suites must use the ``only statement:

import {only, test} from 'zora';

test('will be skipped', t => {
    t.ok(false);
})

only('some test', t => {
 
    // will be skipped as well
    t.test('some nested test', t => {
        t.ok(false);
    });
    
    // will run
    t.only('some other nested test', t => {
        t.ok(true);
    });
});

ZORA_TIMEOUT

In milliseconds: change the default test timeout value (see below)

test timeout

If a test hangs or takes too long to complete, it will report a failure. By default, the threshold is 5000ms. You can change that global value thanks to the ZORA_TIMEOUT environment variable. You can change that value for a given text as well, thanks to the options object:

test(
  'broken promise',
  ({ ok }) => {
    return new Promise(() => {}).then(() => {
      ok(true);
    });
  },
  { timeout: 500 }
);

skip a test

You can skip a test using the root level skip function or within a test suite using the skip method of the assertion object

import {skip, test} from 'zora';

skip('will be skipped', t => {
    t.ok(false);
})

test('some test', t => {
 
    // will be skipped as well
    t.skip('some nested test', t => {
        t.ok(false);
    });
    
    // will run
    t.test('some other nested test', t => {
        t.ok(true);
    });
});