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 🙏

© 2026 – Pkg Stats / Ryan Hefner

kludjs

v1.0.0

Published

Ultimately minimal unit-testing library

Readme

klud.js

Klud.js (kludges) is an ultimately minimal unit testing library.

Briefly, klud.js gives you just four functions:

  • test() to write tests or to configure test reporting
  • ok() to do assertions
  • eq() to compare complex data
  • spy() to make spies (testable function wrappers)

Installation

Download klud.js or klud.min.js if you want a core version without any test reporters.

Download kludjs.js or kludjs.min.js if you want to use it in browser or Node:

var test = require('kludjs');
test('My first test', function() {
	...
});

Usage

If you're using a bare minimal version you may want to setup a function to report about passed/failed assertions etc:

test(function(e, test, msg) {
	switch (e) {
		case 'begin':
			console.log('Test started: ' + test);
			break;
		case 'end':
			console.log('Test finished: ' + test);
			break;
		case 'pass':
			console.log('Assertion passed: ' + test + ':' + msg);
			break;
		case 'fail':
			console.log('Assertion failed: ' + test + ':' + msg);
			break;
		case 'except':
			console.log('Unhandled exception: ' + test + ':' + msg);
			break;
	}
});

For Node and Browser version you already have a simple reporter included.

Now you can start writing your tests:

var test = require('kludjs');

function isEven(x) {
	return x % 2 == 0;
}

test('Testing isEven', function() {
	ok(isEven(0), 'Zero is even');
	ok(isEven(1) == false, 'One is odd');
	ok(isEven(12), 'Twelve is even');
});

test() is a test declaration. Inside a test function you can use ok() to do assertions.

If your assertion needs to compare objects or arrays you can use eq() function:

test('Equal objects', function() {
	ok(eq([1, 2, 3], [1, 2, 3]), 'Arrays are equal');
	ok(eq({a:1, b:false}, {b:false, a:1}), 'Objects are equal');
});

Finally, if you have asynchronous code (I bet you have if you're using javascript) you can use async tests and spies to test your functions.

Asynchronous test looks very similar to normal tests, except for a next parameter is added to a test routine and the third parameter is added to the test function:

test('Async test', function(next) {
	setTimeout(function() {
		ok(1 == 1, 'it works!');
		next();
	}, 1000);
}, true);

All asynchronous tests are put to the queue and executed one by one, so be careful to not miss the next() call when your async test is finished.

A spy wraps a normal function but remembers function calls and thrown exceptions:

test('Function should be called', function() {
	var f = spy();
	ok(!f.called, 'function is not called yet');
	f();
	ok(f.called, 'function is called');
});

test('Function should throw exception', function() {
	var f = spy(function() {
		var a = unknownVariable; // should throw an exception
	});
	f();
	ok(f.thrown.length == 1, 'exception thrown');
});

called and thrown are arrays. The first one contains the lists of arguments for every spy call, and the second one contains exception objects for every function call or undefined if no exception was thrown during the call.

Spy without an underlying function behaves like a function that returns undefined. It's useful to test is the callbacks are called in the right time in the right place with the right arguments.

That's all for now. Have fun!