unitest icon indicating copy to clipboard operation
unitest copied to clipboard

Standalone test/assertion library

Open rtsao opened this issue 7 years ago • 0 comments

The goals of TAP and tape are great, but an alternative would be nice for a number of reasons:

  1. 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
  2. tape requires a bunch of Node.js built-ins (fs, Buffer, process)
    • Bundling these for a browser test environment is simply unacceptable
  3. Tape is generally more bloated and complex than needed.
  4. The tape interface is not oriented around async/await

A replacement should be implemented while preserving the following desirable qualities from tape:

  1. Not require any special test runner (i.e. running tests directly via Node.js should work fine)
  2. Works fine in Node.js and browsers
  3. 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');
});

rtsao avatar Dec 09 '17 01:12 rtsao