unitest
unitest copied to clipboard
Standalone test/assertion library
The goals of TAP and tape are great, but an alternative would be nice for a number of reasons:
- TAP is difficult to work with
- Bad experience for humans out of the box
- TAP formatters don't work that well, especially when regular stdout and tests are mixed
- tape requires a bunch of Node.js built-ins (
fs
,Buffer
,process
)- Bundling these for a browser test environment is simply unacceptable
- Tape is generally more bloated and complex than needed.
- The tape interface is not oriented around async/await
A replacement should be implemented while preserving the following desirable qualities from tape:
- Not require any special test runner (i.e. running tests directly via Node.js should work fine)
- Works fine in Node.js and browsers
- Optional, nice machine-readable test output.
Fortunately, the Chrome Remote debug protocol provides a mechanism to imperatively trigger a different logging mechanism for when a test runner wants to do fancier output.
API example
import test from 'unitest';
/**
* Synchronous tests (always executed serially)
*/
test('sync1', t => {
t.pass('dummy');
});
test('sync2', t => {
t.pass('dummy');
});
test('sync3', t => {
t.pass('dummy');
});
/**
* Async tests (concurrent execution by default)
*/
test('async1', async t => {
await something();
t.pass('dummy');
});
test('async2', async t => {
await something();
t.pass('dummy');
});
test('async3', async t => {
await something();
t.pass('dummy');
});
/**
* Async tests (forced serial execution)
*/
test.serial('async1 (serial)', async t => {
await something();
t.pass('dummy');
});
test.serial('async2 (serial)', async t => {
await something();
t.pass('dummy');
});
test.serial('async3 (serial)', async t => {
await something();
t.pass('dummy');
});