Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

test-director

4.0.1 • Public • Published

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.

Setup

To install from npm run:

npm install test-director --save-dev

Support

  • Node.js 10 - 12 || >= 13.7

API

Table of contents

class TestDirector

An ultra lightweight unit test director for Node.js.

Examples

Import and construct a new test director.

const { TestDirector } = require('test-director');
 
const tests = new TestDirector();

TestDirector instance method add

Adds a test.

Parameter Type Description
name string Unique test name.
test Function Test to run; may return a Promise.
Examples

A sync test.

const { equal } = require('assert');
const { TestDirector } = require('test-director');
 
const tests = new TestDirector();
 
tests.add('JavaScript addition.', () => {
  equal(1 + 1, 2);
});
 
tests.run();

An async test.

const { ok } = require('assert');
const fetch = require('node-fetch');
const { TestDirector } = require('test-director');
 
const tests = new TestDirector();
 
tests.add('GitHub is up.', async () => {
  const { ok } = await fetch('https://github.com');
  ok(ok);
});
 
tests.run();

TestDirector instance method run

Runs the tests one after another, in the order they were added.

Parameter Type Description
throwOnFailure boolean? = false After tests run, throw an error if some failed.

Returns: Promise<void> — Resolves once tests have run.

Examples

Run nested tests.

const { TestDirector } = require('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();

TestDirector instance property tests

A map of test functions that have been added, keyed by their test names.

Type: Map<string, Function>

Install

npm i test-director

DownloadsWeekly Downloads

22

Version

4.0.1

License

MIT

Unpacked Size

13.3 kB

Total Files

6

Last publish

Collaborators

  • avatar