21 |
uvu is an extremely fast and lightweight test runner for Node.js and the browser
22 |
Ultimate
Velocity,
Unleashed
23 |

24 |
25 |
26 |
27 | ## Features
28 |
29 | * Super [lightweight](https://npm.anvaka.com/#/view/2d/uvu)
30 | * Extremely [performant](#benchmarks)
31 | * Individually executable test files
32 | * Supports `async`/`await` tests
33 | * Supports native ES Modules
34 | * Browser-Compatible
35 | * Familiar API
36 |
37 |
38 | ## Install
39 |
40 | ```
41 | $ npm install --save-dev uvu
42 | ```
43 |
44 |
45 | ## Usage
46 |
47 | > Check out [`/examples`](/examples) for a list of working demos!
48 |
49 | ```js
50 | // tests/demo.js
51 | import { test } from 'uvu';
52 | import * as assert from 'uvu/assert';
53 |
54 | test('Math.sqrt()', () => {
55 | assert.is(Math.sqrt(4), 2);
56 | assert.is(Math.sqrt(144), 12);
57 | assert.is(Math.sqrt(2), Math.SQRT2);
58 | });
59 |
60 | test('JSON', () => {
61 | const input = {
62 | foo: 'hello',
63 | bar: 'world'
64 | };
65 |
66 | const output = JSON.stringify(input);
67 |
68 | assert.snapshot(output, `{"foo":"hello","bar":"world"}`);
69 | assert.equal(JSON.parse(output), input, 'matches original');
70 | });
71 |
72 | test.run();
73 | ```
74 |
75 | Then execute this test file:
76 |
77 | ```sh
78 | # via `uvu` cli, for all `/tests/**` files
79 | $ uvu -r esm tests
80 |
81 | # via `node` directly, for file isolation
82 | $ node -r esm tests/demo.js
83 | ```
84 |
85 | > **Note:** The `-r esm` is for legacy Node.js versions. [Learn More](/docs/esm.md)
86 |
87 | > [View the `uvu` CLI documentation](/docs/cli.md)
88 |
89 |
90 | ## Assertions
91 |
92 | The [`uvu/assert`](/docs/api.assert.md) module is _completely_ optional.
93 |
94 | 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!
95 |
96 |
97 | ## API
98 |
99 | ### Module: `uvu`
100 |
101 | > [View `uvu` API documentation](/docs/api.uvu.md)
102 |
103 | The main entry from which you will import the `test` or `suite` methods.
104 |
105 | ### Module: `uvu/assert`
106 |
107 | > [View `uvu/assert` API documentation](/docs/api.assert.md)
108 |
109 | A collection of assertion methods to use within your tests. Please note that:
110 |
111 | * these are browser compatible
112 | * these are _completely_ optional
113 |
114 |
115 | ## Benchmarks
116 |
117 | > via the [`/bench`](/bench) directory with Node v10.21.0
118 |
119 | Below you'll find each test runner with two timing values:
120 |
121 | * the `took ___` value is the total process execution time – from startup to termination
122 | * the parenthesis value (`(___)`) is the self-reported execution time, if known
123 |
124 | Each test runner's `stdout` is printed to the console to verify all assertions pass.