Giter Club home page Giter Club logo

uvu's Introduction

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

example with suites

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

View the uvu CLI documentation

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

Module: uvu

View uvu API documentation

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

Module: uvu/assert

View uvu/assert API documentation

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

uvu's People

Contributors

agilgur5 avatar alexvipond avatar hyanmandian avatar lorenzofox3 avatar lukeed avatar maraisr avatar marvinhagemeister avatar matej21 avatar omgimalexis avatar prantlf avatar zigomir avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.