npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tad

v3.1.1

Published

JavaScript test suite

Downloads

674

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