Tape compatible TAP test runner with superpowers. Contains:
- ability to work with esm modules (take a look at mock-import for mocking).
- shows colored diff when test not
equal
or notdeepEqual
; - produces deteiled stack traces for
async functions
; - as many
only
as you wish; - ability to extend;
- smart timeouts for long running tests 🏃♂️(configured with
SUPERTAPE_TIMEOUT
); - more natural assertions:
expected, result
->result, expected
, for example:
t.equal(error.message, 'hello world', `expected error.message to be 'hello world'`);
Doesn't contain:
es3 code
and lot's of ponyfills.- aliases, methods list much shorter;
throws
,doesNotThrows
- use tryCatch, tryToCatch withequal
instead.
Supertape
was written from scratch after messing a lot with tape
, it inspired by tape
and willing to be compatible with it.
npm i supertape -D
You can convert your codebase from tape
to supertape
with help of a putout and built-in @putout/plugin-tape.
Here is example of a result.
To simplify supertape
core some operators moved out into separate packages, called operators
:
Here is a list of built-int operators:
Package | Version | Dependencies |
---|---|---|
@supertape/operator-stub |
There is a list of built-int formatters
to customize output:
Package | Version | Dependencies |
---|---|---|
@supertape/formatter-tap |
||
@supertape/formatter-fail |
||
@supertape/formatter-short |
||
@supertape/formatter-progress-bar |
||
@supertape/formatter-json-lines |
The assertion methods in supertape
are heavily influenced or copied from the methods
in tape.
const test = require('supertape');
Create a new test with name
string.
cb(t)
fires with the new test object t
once all preceding tests have
finished. Tests execute serially.
Like test(name, cb)
except if you use .only
this is the only test case
that will run for the entire process, all other test cases using tape
will
be ignored.
Generate a new test that will be skipped over.
Extend base assertions with more:
const {extend} = require('supertape');
const test = extend({
transform: (operator) => (a, b, message = 'should transform') => {
const {is, output} = operator.equal(a + 1, b - 1);
return {
is,
output,
};
},
});
test('assertion', (t) => {
t.transform(1, 3);
t.end();
});
Declare the end of a test explicitly.
Generate a failing assertion with a message msg
.
Generate a passing assertion with a message msg
.
Assert that value
is truthy with an optional description of the assertion msg
.
Assert that value
is falsy with an optional description of the assertion msg
.
Assert that pattern: string | regexp
matches actual
with an optional description of the assertion msg
.
Assert that pattern: string | regexp
not matches actual
with an optional description of the assertion msg
.
Assert that Object.is(actual, expected)
with an optional description of the assertion msg
.
Assert that !Object.is(actual, expected)
with an optional description of the assertion msg
.
Assert that actual
and expected
have the same structure and nested values using
node's deepEqual() algorithm
with strict comparisons (===
) on leaf nodes and an optional description of the assertion msg
.
Assert that actual
and expected
do not have the same structure and nested values using
node's deepEqual() algorithm
with strict comparisons (===
) on leaf nodes and an optional description of the assertion msg
.
Print a message without breaking the tap output. (Useful when using e.g. tap-colorize
where output is buffered & console.log
will print in incorrect order vis-a-vis tap output.)
const test = require('supertape');
test('lib: arguments', async (t) => {
throw Error('hello');
// will call t.fail with an error
// will call t.end
});
test('lib: diff', (t) => {
t.equal({}, {hello: 'world'}, 'should equal');
t.end();
});
// output
`
- Expected
+ Received
- Object {}
+ Object {
+ "hello": "world",
+ }
`;
MIT