Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lukeed/uvu
uvu is an extremely fast and lightweight test runner for Node.js and the browser
https://github.com/lukeed/uvu
Last synced: 11 days ago
JSON representation
uvu is an extremely fast and lightweight test runner for Node.js and the browser
- Host: GitHub
- URL: https://github.com/lukeed/uvu
- Owner: lukeed
- License: mit
- Created: 2020-05-11T21:02:01.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-05-12T20:08:21.000Z (6 months ago)
- Last Synced: 2024-05-15T14:13:23.041Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 305 KB
- Stars: 2,940
- Watchers: 21
- Forks: 102
- Open Issues: 81
-
Metadata Files:
- Readme: readme.md
- Funding: .github/FUNDING.yml
- License: license
Awesome Lists containing this project
- awesome-list - uvu
- awesome-node-esm - uvu - an extremely fast and lightweight test runner for Node.js and the browser. (Packages / Testing)
- awesome-javascript - uvu
- awesome-javascript - uvu
README
uvu is an extremely fast and lightweight test runner for Node.js and the browser
Ultimate Velocity, Unleashed
## Features
* Super [lightweight](https://npm.anvaka.com/#/view/2d/uvu)
* Extremely [performant](#benchmarks)
* Individually executable test files
* Supports `async`/`await` tests
* Supports native ES Modules
* Browser-Compatible
* Familiar API## Install
```
$ npm install --save-dev uvu
```## Usage
> Check out [`/examples`](/examples) for a list of working demos!
```js
// 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:
```sh
# 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](/docs/esm.md)
> [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 knownEach test runner's `stdout` is printed to the console to verify all assertions pass.
Said output is excluded below for brevity.```
~> "ava" took 594ms ( ??? )
~> "jest" took 962ms (356 ms)
~> "mocha" took 209ms ( 4 ms)
~> "tape" took 122ms ( ??? )
~> "uvu" took 72ms ( 1.3ms)
```## License
MIT © [Luke Edwards](https://lukeed.com)