var fs = require("fs");

var runCount = 0,
    testCount = 0,
    failCount = 0;

function getSortedObject(obj) {
    if (typeof obj !== "object" || Array.isArray(obj)) return obj;
    return Object.keys(obj)
        .sort()
        .reduce(function(o, name) {
            o[name] = obj[name];
            return o;
        }, {});
}

function runTests(test) {
    //read files, load them, run them
    fs.readdirSync(__dirname + test.dir)
        .map(function(file) {
            if (file[0] === ".") return false;
            return require(__dirname + test.dir + file);
        })
        .forEach(function(file) {
            if (file === false) return;
            var second = false,
                failed = false;

            runCount++;

            console.log("Testing:", file.name);

            test.test(file, function(err, dom) {
                if (err) console.log("Handler error:", err);

                var expected = JSON.stringify(
                        getSortedObject(file.expected),
                        null,
                        2
                    ),
                    got = JSON.stringify(getSortedObject(dom), null, 2);
                if (expected !== got) {
                    failed = true;
                    console.log("Expected", expected, "Got", got, second);
                }

                if (second) {
                    runCount--;
                    testCount++;
                    if (failed) failCount++;

                    console.log(
                        "[" + file.name + "]:",
                        failed ? "failed" : "passed"
                    );
                } else second = true;
            });
        });
    console.log("->", test.dir.slice(1, -1), "iterated");
}

//run all tests
[
    "./01-dom.js",
    "./02-feed.js",
    "./03-events.js",
    "./04-dom_utils.js",
    "./05-stream.js"
]
    .map(require)
    .forEach(runTests);

//log the results
(function check() {
    if (runCount !== 0) {
        return setTimeout(check, 50);
    }
    console.log("Total tests:", testCount);
    console.log("Failed tests:", failCount);

    if (failCount !== 0) {
        throw Error("Encountered " + failCount + " errors!");
    }
})();

@@ -19,319 +19,79 @@
 fs%22)
-;%0A%0Avar runCount = 0,%0A    testCount = 0,%0A    failCount = 0;%0A%0Afunction getSortedObject(obj) %7B%0A    if (typeof obj !== %22object%22 %7C%7C Array.isArray(obj)) return obj;%0A    return Object.keys(obj)%0A        .sort()%0A        .reduce(function(o, name) %7B%0A            o%5Bname%5D = obj%5Bname%5D;%0A            return o;%0A        %7D, %7B%7D);%0A%7D
+,%0A    assert = require(%22assert%22);%0A%0Avar runCount = 0,%0A    testCount = 0;
 %0A%0Afu
@@ -270,16 +270,142 @@
  false;%0A
+            if (file.substr(-5) === %22.json%22)%0A                return JSON.parse(fs.readFileSync(__dirname + test.dir + file));%0A
         
@@ -518,22 +518,13 @@
 if (
+!
 file
- === false
 ) re
@@ -557,40 +557,8 @@
 nd =
- false,%0A                failed =
  fal
@@ -705,54 +705,29 @@
     
-if (err) console.log(%22Handler error:%22, 
+assert.ifError(
 err);%0A
-%0A
     
@@ -742,37 +742,24 @@
     
-var expected = JSON.stringify
+assert.deepEqual
 (%0A  
@@ -780,28 +780,8 @@
     
-    getSortedObject(
 file
@@ -789,17 +789,16 @@
 expected
-)
 ,%0A      
@@ -815,289 +815,61 @@
     
-    null,%0A                        2%0A                    ),%0A                    got = JSON.stringify(getSortedObject(dom), null, 2);%0A                if (expected !== got) %7B%0A                    failed = true;%0A                    console.log(%22Expected%22, expected, %22Got%22, got, second);
+dom,%0A                    %22didn't get expected output%22
 %0A   
@@ -881,17 +881,18 @@
         
-%7D
+);
 %0A%0A      
@@ -984,211 +984,8 @@
 ++;%0A
-                    if (failed) failCount++;%0A%0A                    console.log(%0A                        %22%5B%22 + file.name + %22%5D:%22,%0A                        failed ? %22failed%22 : %22passed%22%0A                    );%0A
     
@@ -1096,13 +1096,12 @@
 ), %22
-itera
+star
 ted%22
@@ -1342,238 +1342,83 @@
  0) 
-%7B%0A        return setTimeout(check, 50);%0A    %7D%0A    console.log(%22Total tests:%22, testCount);%0A    console.log(%22Failed tests:%22, failCount);%0A%0A    if (failCount !== 0) %7B%0A        throw Error(%22Encountered %22 + failCount + %22 errors!%22);%0A    %7D
+return process.nextTick(check);%0A    console.log(%22Total tests:%22, testCount);
 %0A%7D)(

Use the assert library for equality checks, + some minor improvements