A lite test framework for node.js
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example/test
lib
.gitignore
README.md
package.json

README.md

#Santos

A lite test framework for node.js (for complex testing scenarios).

Santos makes this easy:

  • Nested test structures
  • Recursive test structures
  • Conditional firing of new tests
  • "Oder agnostic" test sequences
  • Easily graft into complex test applications

If these concerns aren't important for your current testing scenario, then why not try Mocha?

##Why Santos?

"Why Santos" is a reasonable question because there are already other popular solutions such as Mocha.

The problem is that sometimes your testing strategy requires a level of complexity that other test frameworks don't support. This is mainly due to the monolithic test script paradigms common to TDD (where quaint additions like "pre" and "post" functions for wrapping your tests in don't help enough).

Santos plays nice with your complex testing applications.

###Example Use Case:

You have developed a custom protocol that uses UDP for various physical devices to communicate with a node.js Server process in "the cloud". There are many rules about when and what can be sent based on various states of your physical devices.

You make some progress writing Mocha tests for your node.js Server but things get out of hand pretty quickly. The total combination of Server and device states and possible tests is overwhelming.

You end up writing a state machine that is almost as complex as the node.js Server itself. It checks the behavior of the Server nicely. It's way beyond the complexity you'd normally find in a series Mocha tests scripts.

Now you need a simple test framework to graft in. You need Santos.

##Examples

###Basic Example:

var test = require("../../lib/santos").test;

//the simplest example of a test
test("An example test that will pass", function(done){
    done();
})

Santos - A lite test framework for node.js
------------------------------------------

    An example test that will pass: ............................................. OK

    1 of 1 tests succeeded

###Conditional Example:

var test = require("../../lib/santos").test;

function handlePacket(data){
    test("Packet is well formed", function(done){
        console.assert(data.length==1, 'Packet is 1 char long');
        done();
    });
}

for(var i=8; i<11; i++){
    handlePacket(i+'');
}
Santos - A lite test framework for node.js
------------------------------------------

    Packet is well formed: ...................................................... OK
    Packet is well formed: ...................................................... OK
    Packet is well formed: ................................................... ERROR


AssertionError: Packet is 1 char long
    at Console.assert (console.js:102:23)
    at /Users/Trindaz/code/santos/example/test/example8.js:5:17
    at runTest (/Users/Trindaz/code/santos/lib/santos.js:178:5)
    at /Users/Trindaz/code/santos/lib/santos.js:190:13
    at /Users/Trindaz/code/santos/lib/santos.js:16:13
    at Object.q.process (/Users/Trindaz/code/santos/node_modules/async/lib/async.js:608:21)
    at /Users/Trindaz/code/santos/node_modules/async/lib/async.js:614:27
    at completeTest (/Users/Trindaz/code/santos/lib/santos.js:123:9)
    at done (/Users/Trindaz/code/santos/lib/santos.js:162:13)
    at /Users/Trindaz/code/santos/example/test/example8.js:6:9
    2 of 3 tests succeeded

###Recursive Example:

var test = require("../../lib/santos").test;

function consumeTail(data){
	test("Tail is well formed", function(done){
		console.assert(!isNaN(data.substr(data.length-1,1)), 'Tail is numeric');
		if(data.length>1){
			consumeTail(data.substr(0, data.length-1));
		}
		done();
	});
}

consumeTail('1234567a890');
Santos - A lite test framework for node.js
------------------------------------------

	Tail is well formed:
	Tail is well formed:
	Tail is well formed:
	Tail is well formed: ..................................................... ERROR


AssertionError: Tail is numeric
	at Console.assert (console.js:102:23)
	at /Users/Trindaz/code/santos/example/test/example9.js:5:17
	at runTest (/Users/Trindaz/code/santos/lib/santos.js:178:5)
	at /Users/Trindaz/code/santos/lib/santos.js:190:13
	at /Users/Trindaz/code/santos/lib/santos.js:16:13
	at q.process (/Users/Trindaz/code/santos/node_modules/async/lib/async.js:608:21)
	at process._tickCallback (node.js:415:13)
	at Function.Module.runMain (module.js:499:11)
	at startup (node.js:119:16)
	at node.js:902:3
	0 of 4 tests succeeded

###Nested Example:

var test = require("../../lib/santos").test;

test("The first test in a nested test structure", function(done){
    test("The second test in a nested test structure", function(done){
        setTimeout(done, 300);
    });
    setTimeout(done, 100);
});


test("The first test in a 2nd nested test structure", function(done){
    test("The second test in a 2nd nested test structure", function(done){
        test("The third test in a 2nd nested test structure", function(done){
            setTimeout(done, 1000);
        });
        setTimeout(done, 5000);
    });
    setTimeout(done, 100);
});
Santos - A lite test framework for node.js
------------------------------------------

    The first test in a nested test structure:
    The second test in a nested test structure: ................................. OK
      (The first test in a nested test structure, after all child tests completed) OK

    The first test in a 2nd nested test structure:
    The second test in a 2nd nested test structure:
    The third test in a 2nd nested test structure: .............................. OK
      (The second test in a 2nd nested test structure, after all child tests completed) OK
      (The first test in a 2nd nested test structure, after all child tests completed) OK

    5 of 5 tests succeeded