Skip to content

Instantly share code, notes, and snippets.

@masylum
Created July 7, 2011 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masylum/1069502 to your computer and use it in GitHub Desktop.
Save masylum/1069502 to your computer and use it in GitHub Desktop.
Port of a.rb to nodejs. Minimal testing library! 376bytes!
function j(){var a=[],b=0,c="",d=[],e="\033[3",f="\n";return function g(h){h?(a=
a.concat(h),b++):(h=new Date,a.map(function(a){a.call(g,function(a){if(!a)try{
throw Error()}catch(b){d.push(e+"1mFailure:"+b.stack.split(f)[3]+e+"9m")}c+=e+(a
?"2m.":"1mF")})}),console.log([c,e+"9m"+(new Date-h)+"ms",b+" tests, "+c.length+
" assertions, "+d.length+" failures",d.join(f)].join(f)))}}
// Example usage
var test = j();
test([
function setup() {
this.user = {some: 'object'};
}
, function test_user_has_property(assert) {
assert(this.user.some === 'object');
assert(!this.user.other);
}
, function teardown() {
this.user = null;
}
]);
test([
function setup() {
this.foo = [1, 2, 3];
}
, function test_user_has_property(assert) {
assert(this.foo.length === 3);
assert(this.foo[2] > 934); // Should fail at line 27
this.foo[1] = 99;
assert(this.foo[1] !== 2);
}
, function teardown() {
this.bar = 'something';
}
]);
test();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment