Ultimate Velocity, Unleashed
Features
- Super lightweight
- Extremely performant
- Individually executable test files
- Supports
async
/await
tests - Supports native ES Modules
- Browser-Compatible
- Familiar API
This fork includes benchmarks with up-to-date versions of test frameworks and additional ones - baretest
, jasmine
, pta
, tap
, test
and zora
- including sizes of their NPM packages, all executed in the current Node.js 14 LTS. See the benchmark results below.
Install
$ npm install --save-dev uvu
Usage
Check out
/examples
for a list of working demos!
// tests/demo.js
import { test } from 'uvu';
import * as assert from 'uvu/assert';
test('Math.sqrt()', () => {
assert.is(Math.sqrt(4), 2);
assert.is(Math.sqrt(144), 12);
assert.is(Math.sqrt(2), Math.SQRT2);
});
test('JSON', () => {
const input = {
foo: 'hello',
bar: 'world'
};
const output = JSON.stringify(input);
assert.snapshot(output, `{"foo":"hello","bar":"world"}`);
assert.equal(JSON.parse(output), input, 'matches original');
});
test.run();
Then execute this test file:
# via `uvu` cli, for all `/tests/**` files
$ uvu -r esm tests
# via `node` directly, for file isolation
$ node -r esm tests/demo.js
Note: The
-r esm
is for legacy Node.js versions. Learn More
Assertions
The uvu/assert
module is completely optional.
In fact, you may use any assertion library, including Node's native assert
module! This works because uvu
relies on thrown Errors to detect failures. Implicitly, this also means that any uncaught exceptions and/or unhandled Promise
rejections will result in a failure, which is what you want!
API
uvu
Module: The main entry from which you will import the test
or suite
methods.
uvu/assert
Module: A collection of assertion methods to use within your tests. Please note that:
- these are browser compatible
- these are completely optional
Benchmarks
via the
/bench
directory with Node v14.16.0
Below you'll find each test runner with the following values:
- the
took ___
value is the total process execution time โ from startup to termination - the first parenthesis value (
(___)
) is the self-reported execution time, if known - the second parenthesis value (
(___)
) is the download size of the NPM module
Each test runner's stdout
is printed to the console to verify all assertions pass.
Said output is excluded below for brevity.
First run:
~> "ava" took 1,080ms ( ??? ) ( 2,480.00 KiB)
~> "baretest" took 57ms ( ??? ) ( 6.42 KiB)
~> "jasmine" took 97ms ( 11.0ms) ( 149.81 KiB)
~> "jest" took 1,680ms (616.0ms) ( 8,350.00 KiB)
~> "mocha" took 307ms ( 4.0ms) ( 1,590.00 KiB)
~> "pta" took 133ms ( ??? ) ( 350.77 KiB)
~> "tap" took 737ms (361.1ms) (16,880.00 KiB)
~> "tape" took 175ms ( ??? ) ( 568.69 KiB)
~> "test" took 47ms ( ??? ) ( 159.06 KiB)
~> "uvu" took 66ms ( 0.8ms) ( 145.04 KiB)
~> "zora" took 56ms ( ??? ) ( 20.72 KiB)
Second run:
~> "ava" took 714ms ( ??? )
~> "baretest" took 54ms ( ??? )
~> "jasmine" took 93ms ( 11.0ms)
~> "jest" took 1,170ms (480.0ms)
~> "mocha" took 228ms ( 4.0ms)
~> "pta" took 117ms ( ??? )
~> "tap" took 595ms (344.4ms)
~> "tape" took 126ms ( ??? )
~> "test" took 54ms ( ??? )
~> "uvu" took 63ms ( 0.8ms)
~> "zora" took 54ms ( ??? )
License
MIT ยฉ Luke Edwards