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
-
zero config
-
one of the lightest
pta | tape | Jest | AVA | Mocha | |
---|---|---|---|---|---|
Install size |
- 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
});
-
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
npm i --save-dev pta
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
A reporter which takes advantage of TTYs to create very informative, straight to the point reports:
- A test files diagnostic
- A diagnostic per failing assertion (with location, semantic structure, and detailed difference between expected and actual value)
- A summary counter.
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
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
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
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]
We recommend to use c8:
c8 pta [...args]
We recommend to use chokidar-cli or onchange
chokidar '{test,src}/*.js' -c 'pta [...args]'
or
onchange '**/*.js' -- pta [...args]