Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

tad

medikoo752ISC3.1.1

JavaScript test suite

test, factory, unit, unittest, runner, tests, tdd, testing

readme

TAD - JavaScript test suite

Goal of this framework is to allow writing tests with minimal hassle. TAD will locate your test file, and provide tested module for your test functions.

Example console output:

Installation

$ npm install tad

Usage

File management

Keep your tests in test folder. For each file in in main folder have corresponding test file in test folder.

Test files

Tests should be written as set of functions, it can be just one function:

module.exports = function (t, a, d) {
  // tests
};

or many thematically grouped functions:

exports["Test this"] = function (t, a, d) {
  // tests
};
exports["Test that"] = function (t, a, d) {
  // tests
};

Test functions

Arguments passed to test functions are:

  • t - Tested module
  • a - Assert object
  • d - Done function, it's for tests that need to be run asynchronously. You may pass additional block of tests to this function and they'll be run right after. d argument makes no sense for synchrounous tests, declare such tests without it.

All arguments are optional, and by the way function is declared suite detect which arguments should be passed to test function. Examples:

  • Asynchronous test:
exports["Some tests"] = funtcion (t, a, d) {
        // tests
        setTimeout(function () {
           // tests
           d();
        }, 100);
};
  • Synchronous test:
exports["Some tests"] = function (t, a) {
  // tests
};

Tests can be nested, and declared various ways (synchronous/asynchronous)

module.exports["Test all"] = function (t, a) {
  // Preparation code

  // ... tests ...

  return {
    "Test this": function () {
      // We already have module and assert object
      // ... tests ...
    },
    "Test that async way": function (d) {
      // This one is asynchronous
      // ... tests ....

      seTimeout(function () {
        // ... tests ...
        d({
          "Some extra tests": function () {
            // ... tests ...
          }
        });
      }, 100);
    }
  };
};

Assertions

TAD uses assert object from UncommonJS tests runner, It's API is nearly same as of assert that can be found in Node. Full spec is available at https://github.com/kriskowal/uncommonjs/blob/master/tests/specification.md .

TAD adds some extra sugar to UncommonJS Assert object:

  • a === a.strictEqual, so you can write your assertions as:
a(shouldBeTrue, true, "It's true");
// it has same effect as:
a.strictEqual(shouldBeTrue, true, "It's true");
  • a.not is an alias for a.notStrictEqual
  • a.deep is an alias for a.deepEqual
  • a.notDeep is an alias for a.notDeepEqual
  • assert.never with that you can check function paths that should never be called.

Running tests

Test your file with provided binary:

$ bin/tad lib/test-file

or test all files in path:

$ bin/tad lib

TODO

  • Full custom context support
  • Code coverage
  • TAP support
  • jslint, jshint as side validation option
  • Port tests to browsers

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

3.1.1 (2023-08-24)

Bug Fixes

  • Ensure to support test functions configured as object methods (4972a8b)

3.1.0 (2021-10-15)

Features

  • Ignore *.config.js files when auto-indexing (1d9ddf2)

Maintenance Improvements

3.0.1 (2019-08-30)

Bug Fixes

  • Catch orphaned assertions and expose them as errors (987e692)
  • Let process to gracefully exit (aa28832)

3.0.0 (2019-08-30)

Bug Fixes

  • Recognize signatures of async and arrow functions (7817b0a)

Features

  • Ensure to expose unhandled rejections as crashes (619dfab)
  • Support thenable test returns (ad83077)

BREAKING CHANGES

  • Drop support for Node.js versions lower than v0.11.8
  • Due to implied thenable support. Objects which have then method, and are result of test functions, are no longer processed further as test dictionaries but instead are processed as promises

2.0.1 (2019-04-30)

Bug Fixes

  • ensure ncjsm as normal dependency (01913b9)

2.0.0 (2019-04-30)

Bug Fixes

  • Ensure Node.js v12 support (eabc639)

chore

Features

  • remove outdated 'next' dependency (88da6ff)

BREAKING CHANGES

  • Drop support for Node.js v0.10.16 and below

1.0.0 (2019-02-22)

chore

  • rename binary file to tad.js (5289439)

Features

  • skip js files starting with '.' in automatic testing (cce5af6)

BREAKING CHANGES

  • Binary file direct name was renamed from bin/tad into bin/tad.js
  • JS files starting with '.' are not considered as modules to be tested

0.2.8 (2018-09-14)

Bug Fixes

  • support for Node.js version prior v0.12 (4267dbf)