Join us to discuss the challenges, solutions and best practices for in-house JavaScript code sharing. Tuesday, 12/17 at 10am PT/1pm ET.Sign up here »

test-director

2.0.0 • 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.

Setup

To install from npm run:

npm install test-director --save-dev

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 testDirector = 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 testDirector = new TestDirector()
 
testDirector.add('JavaScript addition.', () => {
  equal(1 + 1, 2)
})

An async test.

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

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 tests.

testDirector.run()

Run nested tests.

const { TestDirector } = require('test-director')
 
const testDirector1 = new TestDirector()
 
testDirector1.add('Test A.', async () => {
  const testDirector2 = new TestDirector()
 
  testDirector2.add('Test B.', () => {
    // …
  })
 
  testDirector2.add('Test C.', () => {
    // …
  })
 
  await testDirector2.run(true)
})
 
testDirector1.add('Test D.', () => {
  // …
})
 
testDirector1.run()

TestDirector instance property tests

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

Type: Map<string, Function>

Keywords

Install

npm i test-director

DownloadsWeekly Downloads

37

Version

2.0.0

License

MIT

Unpacked Size

9.35 kB

Total Files

4

Last publish

Collaborators

  • avatar