pta
test runner for nodejs using zora testing library
Last updated 6 months ago by lorenzofox3 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install pta 
SYNC missed versions from official npm registry.

zora-node

Test runner for nodejs using zora testing library.

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
    });
<summary>Animated screen shots of diverse user experiences</summary>

ux screen shot

  • Support esm module syntax with no extra bundling step (thanks to esm module) - we could eventually consider to remove it from the package and use node's require hook instead (node -r esm myFile.js), but for now using ESM syntax seems to be a common enough practice to embed esm as a dependency

  • 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

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.
<summary> Report screen shot</summary>

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

ts-node ./node_modules/.bin/pta [...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]

Current Tags

  • 0.1.3                                ...           latest (6 months ago)

6 Versions

  • 0.1.3                                ...           6 months ago
  • 0.1.2                                ...           6 months ago
  • 0.1.1                                ...           6 months ago
  • 0.1.0                                ...           7 months ago
  • 0.0.2                                ...           7 months ago
  • 0.0.1                                ...           8 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 6
Last Month 18
Dependencies (7)
Dev Dependencies (1)
  • c8 ^6.0.1
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |