-
-
Save masylum/1069502 to your computer and use it in GitHub Desktop.
Port of a.rb to nodejs. Minimal testing library! 376bytes!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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