A minimal JavaScript test harness with TAP-like output, designed for simplicity and async support.
npm install tiny-test-harness
const { createHarness } = require('tiny-test-harness');
const test = createHarness();
test.test('Basic assertions', (t) => {
t.equal(1, 1, 'numbers should be equal');
t.deepEqual({a: 1}, {a: 1}, 'objects should match');
t.throws(() => { throw new Error() }, 'should throw');
t.end();
});
test.test('Async test', (t) => {
t._pendingAsync++; // Mark async operation start
setTimeout(() => {
t.pass('async test passed');
t.done(); // Mark async operation complete
t.end();
}, 100);
});
Available assertion methods:
t.equal(actual, expected, message)
t.deepEqual(actual, expected, message)
t.throws(fn, expectedError, message)
t.pass(message)
t.fail(message)
- Tests can be nested using
t.test()
- Each test must call
t.end()
when complete - Async tests should increment
t._pendingAsync
and callt.done()
let output = '';
test.createStream().on('data', (row) => {
output += row + '\n';
console.log(row);
});
test.on('finish', () => {
console.log('All tests completed');
});
- Simple TAP-like output
- Nested test support
- Async test support
- Lightweight (~5kb minified)
- No external dependencies
GNU Affero General Public License (AGPL)