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

trial

v1.1.0

Published

A testing framework

Downloads

26

Readme

Trial

Trail is a node module that provides concurrent testing with strong dependency support. Each test consists of bits that look quite a lot like the perl Test::More bits. Becuase they are asynchronous, it works a tad differently.

Overview

Each test consists of:

  • test // a function that runs the tests.
  • name // arbitrary user test name
  • plan // number of tests you intend to run
  • requires // array of named requirements
  • provides // array of named satisfications

Like typical tap tests, a test would look something like this:

function() {
  this.ok(true, "this better pass");
  this.is(1+2, 3, "adding sorta works in javascript");
  this.ok(false, "this test will certainly fail");
}

A test that includes this test must have a plan equal to 3. Due to the asynchronous nature of many tests, the framework will wait until three tests checks report back before considering the test complete. If you trigger too few, it will hang waiting (as expected). If you trigger too many, the world will end (and it's your fault).

As tests run, they can stash things in a trial-accessible key value store by calling this.stash("mykey", myvalue). Tests can retrieve this data by calling this.fetch("mykey").

A test can depend on another test by leveraging the requires and provides arrays. If the "createuser" test has a provides: ['test_user_id'] and other tests in the system have a requires: ['test_user_id'], then the dependent tests will wait until the "createuser" test completes before beginning. This combined with the stash/fetch provides a simple way to synchronize complex and dependent tests while still maximizing concurrency.

Each test is run in a new vm sandbox.

API

var trial = new Trial([params])

creates a new trial object that respects the following param keys:

  • verbose [false] : be verbose
  • brief [false] : be brief
  • summary [true] : summarize the trial
  • incremental_reporting [false] : don't wait until each test finishes
  • tap [false] : use TAP output (above are ignored)
  • suppress [{}] : keys of test names to suppress (not run)
  • require : an optional replacement for require() maintain sandboxing

Node, if verbose, brief, summary, or incremental_reporting are not specified, then they are taken from the environment variables TEST_VERBOSE, TEST_BRIEF, TEST_SUMMARY, or INCREMENTAL_REPORTING, respectively.

trial.run()

will start the trial executing all tests as the dependency graph dictates. Upon completion a report will be issued. Verbose details will be shown if TEST_VERBOSE environment variable is set (or the verbose attribute is passed to the Trial creation).

trial.noexit()

informs the trial that upon completion it should not exit (node) with a status code that indicates the overall trial sucess (0 for good, 1 for bad).

If critical errors are encountered during test build or run, node will exit with a value of 2.

trial.add(new Test(params))

Adds a new test to a trial.

trial.load(dir)

Will recursively load all .tjs files and create tests will full dependencies. .tjs files are javascript source files that have each attribute of the Test (above) as global assignable variables:

stupid.tjs

name = "dumb test"
plan = 1
provides = ['no value']
test = function() { this.ok(true, 'eureka'); }

Larger integrations

The simple case can be solved using the runtests helper.

var runtests = require('trial').runtests;
var trial = runtests("./tests");

Junit output for CI integration

# var trial = new Trial()
var runtests = require('trial').runtests;
var trial = runtests("./tests");
new Junit(trial, "test_detail.xml");