New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

assert-runner

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assert-runner

runs tests based on node's built in assert

1.1.2
Source
npm
Version published
Weekly downloads
1
-50%
Maintainers
1
Weekly downloads
 
Created
Source

Assert Runner

Author: Rich Hildred inspired by Gabriel Llamas' answer to this stack overflow question.

License: MIT

Really light weight test runner based on node's builtin assert.

TestRunner.js

npm install assert-runner

Given a class TestClass under test:

var Toolbox = require('js-toolbox');

var TestClass = Toolbox.Base.extend({
	constructor: function(){
		return this;
	},
	synchronous: function(req, res){
		res.end("synchronous test");
	},
	asynchronous: function(req, res, callback){
		res.end("asynchronous test");
		if(typeof callback != 'undefined') callback();
	}
});

module.exports = TestClass;

TestClass can be tested using the following code (in test.js):

var TestRunner = require('TestRunner'),
assert = require('assert'),
TestClass = require('./classes/TestClass.js');

var oTest = null;
var tests = {
		"TestClass constructor" : function(){
			oTest = new TestClass();
			assert(oTest != null);
		},
		"TestClass synchronous": function(){
			var oReq = new TestRunner.TestRequest();
			var oResp = new TestRunner.TestResponse();
			oTest.synchronous(oReq, oResp);
			assert(oResp.sBody == "synchronous test");
		},
		"Test asynchronous": function(done){
			var oReq = new TestRunner.TestRequest();
			var oResp = new TestRunner.TestResponse();
			oTest.asynchronous(oReq, oResp, function(){
				assert(oResp.sBody == "asynchronous test");
				done();
			});
			
		}
};

new TestRunner(tests).again(0);

If we run node test.js the output produced will be:

Passed Test: "TestClass constructor" 1 of 3
Passed Test: "TestClass synchronous" 2 of 3
Passed Test: "Test asynchronous" 3 of 3

Depends on:

Keywords

Node.js

FAQs

Package last updated on 29 Nov 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts