test-director

An ultra lightweight unit test director for Node.js.

Usage no npm install needed!

<script type="module">
  import testDirector from 'https://cdn.skypack.dev/test-director';
</script>

README

test-director

npm version CI status

An ultra lightweight unit test director for Node.js.

Works well with any assertion library that throws errors, such as the Node.js assert API and snapshot-assertion.

Use coverage-node to run your test script and report code coverage.

Installation

To install with npm, run:

npm install test-director --save-dev

Examples

A sync test:

import { equal } from "assert";
import TestDirector from "test-director";

const tests = new TestDirector();

tests.add("JavaScript addition.", () => {
  equal(1 + 1, 2);
});

tests.run();

An async test:

import { ok } from "assert";
import fetch from "node-fetch";
import TestDirector from "test-director";

const tests = new TestDirector();

tests.add("GitHub is up.", async () => {
  const response = await fetch("https://github.com");
  ok(response.ok);
});

tests.run();

Nested tests:

import TestDirector from "test-director";

const tests = new TestDirector();

tests.add("Test A.", async () => {
  const tests = new TestDirector();

  tests.add("Test B.", () => {
    // …
  });

  tests.add("Test C.", () => {
    // …
  });

  await tests.run(true);
});

tests.add("Test D.", () => {
  // …
});

tests.run();

Requirements

  • Node.js: ^12.22.0 || ^14.17.0 || >= 16.0.0

Exports

These ECMAScript modules are published to npm and exported via the package.json exports field: