Test small things, with a small thing
Go to file
Geoff Doty 0bc6300cbc 1.1.1 2022-07-31 11:48:00 -04:00
dist switching to esbuild 2021-01-02 03:42:41 -05:00
src bump version 2020-09-20 16:02:45 -04:00
test linting 2022-07-31 01:40:35 -04:00
.eslintrc.js replace jshint w/ eslint 2020-09-08 17:27:17 -05:00
.gitignore add .gitignore 2018-04-02 04:24:53 -04:00
CONTRIBUTING.md contrib fixes 2018-12-02 03:40:30 -05:00
LICENSE switching to esbuild 2021-01-02 03:42:41 -05:00
README.md switching to esbuild 2021-01-02 03:42:41 -05:00
package-lock.json 1.1.1 2022-07-31 11:48:00 -04:00
package.json 1.1.1 2022-07-31 11:48:00 -04:00

README.md

Test.it

A minimalistic client-side testing library

Test.it is a small client-side testing library for people that want to live in code, not in tests. No over engineering here. Inspired by the simplicity of libraries like Jasmine, but implementation ideas based on TinyTest

This is probally not a cure-all testing solution, if you want something more robust checkout Jasmine, Tape or Mocha -- this is to...

Test small things, with small things

Features

  • Designed for the Browser
  • Under a 100 lines
  • Single File
  • No Dependicies
  • 2kb footprint (before gzip)
  • Extend with custom reporters
  • Uses Simple Assert

No Bloat Here!

Usage

By default, you can run your tests like

import test from 'testit';

test.it({
    'my passing test': function() {
        test.assert(true);
    },
    'my failing test': function() {
        test.assert(true === false, 'just wanted to fail fast');
    }
}).run();

NOTE: run() can be called elsewhere, see tests/

by default, your test results are logged to the console

+OK my passing test
-ERR my failing test
---
Error: just wanted to fail fast
    ...error stack...
---

# tests 2 pass 1 fail 1

A +OK will proceed test lines that pass and a -ERR for those that fail, An error stack is included by default after the failing test wrapped in ---. You can suppress outputing the error stack by passing false as an argument to run(), ie run(false).

You can, also, write your own custom test runner...

Custom Test Runners

test.it .run() method provides an optional next function parameter that passes the results as an object for you to process however you like.

For Example...

For Fans of TinyTest

test.it({
    'my passing test': function() {
        test.assert(true);
    }
}, function(results) {
    if (window.document && document.body) {
        document.body.style.backgroundColor = (
            results.fail.length ? '#ff9999' : '#99ff99'
        );
    }
});

If using the optional next param will return results as JSON

{
    "pass": ["list of passed tests", "..."],
    "fail": ["list of errored tests", "..."],
}

From this object you can easily find the number of tests ran pass.length, number of failed tests fail.length or the total test count by adding the two. Simple.

REMEMBER: you can bypass error output too

A sample test runner is provided for the BROWSER in the test/ directory; index.html and runner.js respectfully, with the spec in index.spec.js.

Methods

To stay minimal, test.it only has 3 core functions:

  • it to capture your tests
  • run to execute yours tests
  • and assert to write your assertions

While you can use your own assertion library, the included assert evaluates an expression/condition tests:

if you want to shorten test typing try

let assert = test.assert;

putting that above your tests will allow you to write like

test.it({
    "my test should work": function() {
        assert(true);
    }
});

TODO

  • provide sample test runner for CI environments
  • maybe spec files export results && runner identifies failure

Support

Please open an issue for support.

Contributing

Anyone is welcome to contribute, however, if you decide to get involved, please take a moment to review the guidelines, they're minimalistic;)

License

MIT Geoff Doty