node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org ยป



Library that generates the html for a browser test runner.


var testable = require('testable');

// Get the final html string (default is qunit)

// Get markup for jasmine test runner.
testable.markup({ framework: 'jasmine' });

// Get the absolute path to a the directory of bundled assets



Set what built in test framework adapter to use.

Bundled adapters: qunit (default), jasmine, and mocha.


Array of strings that are the files to be loaded in the test runner. These strings are passed through node-glob. Files included here are filtered, and css files are included in the page head, and js files are included in order in the page body.


Array of strings that works exactly like files. This should include the files that have your tests. files and tests have to be separate because code can be injected in between the files script tags and the tests script tags.


This options can be a string or a function. In the resulting html, the paths to the files in the files configuration will be relative to process.cwd(). Those paths may not be reachable by the browser depending on how the webserver is setup. transformPath can modify each path to something that is reachable.

When transformPath is a string, it is used as the search in a call to String.replace(). If the files option is set to ['tmp/build/js/**/*.js'] and transformPath is tmp/build/, then in the browser, the script tag src attributes will be js/....

transformPath can also be a function which gets the src path as a param and returns the path that should be set in the browser.


See section at the bottom about custom adapters.

config.chai (mocha framework only)

When using the mocha framework, the chai configuration option is used to choose what type of assertion style to use with chai. See for more information. Valid options are expect (default), assert, and should. (mocha framework only)

When using the mocha framework, the style configuration option is used to set the spec syntax for mocha. See mocha interfaces for more information. Valid options are bdd (default), tdd, exports, and qunit.


Here is a quick example app using Express.js.

var express = require('express'),
	testable = require('testable'),
	app = express(), testableConfig;
testableConfig = {
	framework: 'qunit',
	files: ['public/js/app.js'],
	tests: ['public/test/**/*_test.js'],
	transformPath: 'public/'

// Make testable assets available
app.use(express.static(__dirname + '/public'));

app.get('/test.html', function(req, res) {
	res.setHeader('Content-Type', 'text/html');


Also check out testable-middleware to use testable with Connect or Express.

Custom Adapters

To add support for new testing frameworks, or your own framework, you could create a custom adapter. An adapter is simply an object that exposes five methods:

adapter: {
	css: function() { return ['custom.css']; },
	libs: function() { return ['custom.js']; },
	markup: function() {
		return '<div id="custom-framework"></div>';
	extras: function() {
		return '<script>MyFramework.setup(config);</script>';
	startup: function() {
		return '<script>;</script>';


An array of css files necessary for the test framework.


An array js files necessary for the test framework.


Most frameworks require a small html snippet added to the body. The string returned from adapter.markup() is the first thing added to the test runner body tag.


The string returned from this method is added to the test runner markup between the config.files script tags and the the config.tests script tags.


The string returned from this method is the last thing added to the test runner.