uvu

uvu is an extremely fast and lightweight test runner for Node.js and the br...

README

uvu
version CI downloads install size
uvu is an extremely fast and lightweight test runner for Node.js and the browser
Ultimate Velocity, Unleashed

example with suites


Features


Extremely performant
Individually executable test files
Supports async/await tests
Supports native ES Modules
Browser-Compatible
Familiar API


Install


  1. ```
  2. $ npm install --save-dev uvu
  3. ```


Usage


Check out [/examples](/examples) for a list of working demos!


  1. ```js
  2. // tests/demo.js
  3. import { test } from 'uvu';
  4. import * as assert from 'uvu/assert';

  5. test('Math.sqrt()', () => {
  6.   assert.is(Math.sqrt(4), 2);
  7.   assert.is(Math.sqrt(144), 12);
  8.   assert.is(Math.sqrt(2), Math.SQRT2);
  9. });

  10. test('JSON', () => {
  11.   const input = {
  12.     foo: 'hello',
  13.     bar: 'world'
  14.   };

  15.   const output = JSON.stringify(input);

  16.   assert.snapshot(output, `{"foo":"hello","bar":"world"}`);
  17.   assert.equal(JSON.parse(output), input, 'matches original');
  18. });

  19. test.run();
  20. ```

Then execute this test file:

  1. ```sh
  2. # via `uvu` cli, for all `/tests/**` files
  3. $ uvu -r esm tests

  4. # via `node` directly, for file isolation
  5. $ node -r esm tests/demo.js
  6. ```

Note: The -r esm is for legacy Node.js versions. Learn More


[View the uvu CLI documentation](/docs/cli.md)



Assertions


The [uvu/assert](/docs/api.assert.md) module is _completely_ optional.

In fact, you may use any assertion library, including Node's native [assert](https://nodejs.org/api/assert.html) 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


Module: uvu


[View uvu API documentation](/docs/api.uvu.md)


The main entry from which you will import the test or suite methods.

Module: uvu/assert


[View uvu/assert API documentation](/docs/api.assert.md)


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](/bench) directory with Node v10.21.0


Below you'll find each test runner with two timing values:

the took ___ value is the total process execution time – from startup to termination
the parenthesis value ((___)) is the self-reported execution time, if known

Each test runner's `stdout` is printed to the console to verify all assertions pass.
Said output is excluded below for brevity.

  1. ```
  2. ~> "ava"   took   594ms  (  ???  )
  3. ~> "jest"  took   962ms  (356  ms)
  4. ~> "mocha" took   209ms  (  4  ms)
  5. ~> "tape"  took   122ms  (  ???  )
  6. ~> "uvu"   took    72ms  (  1.3ms)
  7. ```


License