Navigation Menu

Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

lorenzofox3/zora-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zora-node

Test runner for nodejs using zora testing library.

Support Node >= 14,

For zora v4 only. For the latest versions of zora ( >= v5) please refer to the zora monorepo

Points of interest

  • zero config

  • one of the lightest

pta tape Jest AVA Mocha
Install size pta tape jest ava mocha
  • yet the fastest

See the user experience when running a test program made of 12 files with 8 tests compared to other popular frameworks. A test being:

    test('test', async function (assert) {
        await new Promise(resolve => {
            setTimeout(() => resolve(), 50); //wait 50 ms (database is processing, etc)
        });
        assert.truthy(Math.random() * 100 > 3); // fails 3% of the time
    });
Animated screen shots of diverse user experiences

ux screen shot

  • Support esm module syntax with no extra bundling step

  • Effective reporters, perfect to find out about errors ("where", "what" and "why"). Not extra noise, fancy code highlights, etc ... straight to the point!

  • All the goodies from zora

Installation

npm i --save-dev pta

Usage

Write your spec files with a default export function taking as argument a zora's assertion object

./test/foo.js

export default (t) => {
    t.test(`should greet`, t => {
        t.ok(true, 'hello world');
    });
}

and run with the cli:

pta

More info about the CLI options can be found in usage

Reporters

default

A reporter which takes advantage of TTYs to create very informative, straight to the point reports:

  1. A test files diagnostic
  2. A diagnostic per failing assertion (with location, semantic structure, and detailed difference between expected and actual value)
  3. A summary counter.
Report screen shot

test report screen shot

log

Dump JSON stringified zora's protocol messages. It is very convenient if you want to create a custom reporter. In modern versions of node it has been trivial to write transform streams thanks to Async Iterators:

consider the following 20 lines program

#!/usr/bin/env node
const readline = require('readline');
const {stream} = require('@lorenzofox3/for-await');

async function processLineByLine(input = process.stdin) {
    const inputStream = stream(
        readline.createInterface({
                input
            }
        ))
        .map(m => JSON.parse(m))
        .filter(m => m.type === 'ASSERTION' && m.data.pass === false);

    for await (const m of inputStream) {
        console.log(m.data);
    }
}

processLineByLine();

That's it. You have a custom reporter (whose package's name is "custom-reporter" for example) which prints in the console the failing assertions' details.

pta -r log | custom-reporter

tap

A flatten TAP (Test Anything Protocol) stream in the same format as tape produces. Can be parsed and piped into one (of the plenty) custom reporter available in npm (or any other technology's package registry - tap is widely spread).

Example with faucet:

pta -r tap | faucet

tap-indent

Another common structure of tap stream (used by node-tap). The structure can be parsed with common tap parser (such as tap-parser) And will be parsed as well by tap parser which do not understand the indentation. However to take full advantage of the structure you should probably use a formatter (such tap-mocha-reporter) aware of this specific structure to get the whole benefit of the format.

Example with tap-mocha-reporter

pta -r tap-indent | tap-mocha-reporter classic

Typescript

We recommend to use ts-node

As ts-node support for native ES module is partial, you should tell pta to use the cjs module loader

ts-node ./node_modules/.bin/pta --module-loader=cjs [...args]

Code coverage

We recommend to use c8:

c8 pta [...args]

Watch mode

We recommend to use chokidar-cli or onchange

chokidar '{test,src}/*.js' -c 'pta [...args]'

or

onchange '**/*.js' -- pta [...args]