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

harness

v0.0.6

Published

Yet another test organizer except this one works in NodeJS, Mongo 2.2's shell and modern web browsers.

Downloads

75

Readme

build status harness-js

Yet another test organizers except that is work in NodeJS, Mongo's shell. Being able to run across these three environments with depending on things like RequireJS was a major reason to write this module. Hopefully it is helpful to others.

Overview

Harness provides a simple way of organizing assertive tests in Mongo's shell (using mongo-modules), NodeJS and in many web browsers.

NodeJS example

	var path = require("path"),
		assert = require("assert"),
		harness = require("harness");
	
	// Setup a test by assigning a function to callback and
	// a label to the test group.
	harness.push({callback: function () {
		assert.strictEqual(harness.counts("running"), 1, "Should have on test running for 'Testing push()'");
	
		// Now that you've completed this test
		// group tell harness that this label
		// is now complete.
		harness.completed("Test group 1");
	}, label: "Test group 1"});
	
	// This is a second test group just to show you can do
	// more than one group of tests.
	// Setup a test by assigning a function to callback and
	// a label to the test group.
	harness.push({callback: function () {
		assert.strictEqual(harness.counts("running"), 2, "Should have on test running for 'Testing push()'");
	
		// Now that you've completed this test
		// group tell harness that this label
		// is now complete.
		harness.completed("Test group 2");
	}, label: "Test group 2"});
	
	harness.RunIt(path.basename(module.filename), 10);

The command to run example/node-example.js looks like-

	node example/node-example.js

The output would look something like-

	Starting [node-example.js] ...
		Starting Test group 1 ...
			Test group 1 called
			Test group 1 OK
		Starting Test group 2 ...
			Test group 2 called
			Test group 2 OK
	node-example.js Success!

Mongo example

Harness support comes with mongo-modules and mongo-modules will need to be installed for it to work. Other than that it looks much like the NodeJS version above. The difference is that the module.filename object isn't defined by mongo-modules so we must define that ourselves.

	var path = require("path"),
		assert = require("assert"),
		harness = require("harness"),
		// mongo-modules does not define the module object's
		// filename.
		module = {
			filename: "mongo-example.js"
		};
	
	// Setup a test by assigning a function to callback and
	// a label to the test group.
	harness.push({callback: function () {
		assert.strictEqual(harness.counts("running"), 1,
			"Should have on test running for 'Testing push()'");

		// Now that you've completed this test
		// group tell harness that this label
		// is now complete.
		harness.completed("Test group 1");
	}, label: "Test group 1"});
	
	// This is a second test group just to show you can do
	// more than one group of tests.
	// Setup a test by assigning a function to callback and
	// a label to the test group.
	harness.push({callback: function () {
		assert.strictEqual(harness.counts("running"), 2, "Should have on test running for 'Testing push()'");
	
		// Now that you've completed this test
		// group tell harness that this label
		// is now complete.
		harness.completed("Test group 2");
	}, label: "Test group 2"});
	
	harness.RunIt(path.basename(module.filename), 10);

Running the example/mongo-example.js with mongo-modules available is done like-

	mongo ~/.mongojs.rc example/mongo-example.js

The output should look something like-

	MongoDB shell version: 2.2.0
	connecting to: test
	loading file: /Users/johndoe/.mongorc.js
	loading file: example/mongo-example.js
	Starting [mongo-example.js] ...
		Starting Test group 1 ...
			Test group 1 called
			Test group 1 OK
		Starting Test group 2 ...
			Test group 2 called
			Test group 2 OK
	mongo-example.js Success!