UNPKG

3.54 kBMarkdownView Raw
1<div align="center">
2 <img src="shots/uvu.jpg" alt="uvu" height="120" />
3</div>
4
5<div align="center">
6 <a href="https://npmjs.org/package/uvu">
7 <img src="https://badgen.now.sh/npm/v/uvu" alt="version" />
8 </a>
9 <a href="https://github.com/lukeed/uvu/actions">
10 <img src="https://github.com/lukeed/uvu/workflows/CI/badge.svg" alt="CI" />
11 </a>
12 <a href="https://npmjs.org/package/uvu">
13 <img src="https://badgen.now.sh/npm/dm/uvu" alt="downloads" />
14 </a>
15 <a href="https://packagephobia.now.sh/result?p=uvu">
16 <img src="https://packagephobia.now.sh/badge?p=uvu" alt="install size" />
17 </a>
18</div>
19
20<div align="center">
21 <b>uvu</b> is an extremely fast and lightweight test runner for Node.js and the browser<br>
22 <b>U</b>ltimate <b>V</b>elocity, <b>U</b>nleashed<br><br>
23 <img width="380" alt="example with suites" src="shots/suites.gif"/>
24</div>
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
51import { test } from 'uvu';
52import * as assert from 'uvu/assert';
53
54test('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
60test('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
72test.run();
73```
74
75Then 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
92The [`uvu/assert`](/docs/api.assert.md) module is _completely_ optional.
93
94In 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
103The 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
109A 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
119Below 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
124Each test runner's `stdout` is printed to the console to verify all assertions pass.<br>Said output is excluded below for brevity.
125
126```
127~> "ava" took 594ms ( ??? )
128~> "jest" took 962ms (356 ms)
129~> "mocha" took 209ms ( 4 ms)
130~> "tape" took 122ms ( ??? )
131~> "uvu" took 72ms ( 1.3ms)
132```
133
134
135## License
136
137MIT © [Luke Edwards](https://lukeed.com)