2.0.9 • Published 6 years ago

testnow v2.0.9

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

testnow

Minimalistic testing framework

    npm install testnow

This framework doesn't have any CLI, only programmatic API.
It's designed to be cross-platform and to be able to be integrated with any build / CICD / deployment tools.

Examples are in typescript.

Setting up / describing tests

import test from "testnow";

function mySetImmediate(cb: () => void) {
    return setTimeout(cb, 0);
}

test.group("mySetImmediate", () => {
    test("Executes callback", (end: test.Handler) =>
        mySetImmediate(() => end()));

    test("May be cancelled with clearTimeout", (end: test.Handler) => {
        let timeoutId = mySetImmediate(
            () => end(new Error(`Callback executed`))
        );
        clearTimeout(timeoutId);
        setTimeout(() => end(), 100);
    });
});

Executing tests

nodejs

import test from "testnow";

import "./mySetImmediate";
import util from "util";

test.run().then(result => {
    console.log(util.inspect(result, true, 10, true));
});

Several simple reporters are now built in testnow. Reporter is simply a function that takes test results and does something with them. Usually reporters output the results somewhere. Right now there are 4 simple reporter types: plain - using the most basic and cross-platform console.log functionality, console and terminal - are similar to plain for now, dom - inserts a html-formatted report as innerHTML into a given dom-node. The reporter export provided by testnow contains not reporters themselves, but reporter creators, functions that have optional reporter-options object as a parameter and return a reporter. We could rewrite the above example using a simple built-in reporter which just logs results to the console:

import test, {reporter} from "testnow";

import "./mySetImmediate";

test.run().then(result => {
    reporter.plain({})(result);
});

browser

import test, { reporter } from "testnow";

window.onload = () => {
    test.run().then(result => {
        reporter.dom({})(result);
    });
}

We should compile the code above into a bundle.js somehow, and then we can see the results using following html:

<html>

<head>
    <script src="bundle.js"></script>
</head>

<body>

</body>

</html>
2.0.9

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago