#!/usr/bin/env node

/**
 * @overview nodeunit test runner.
 */

var path = require('path');
function findReporter(name) {
    var nodeunit = require('nodeunit');
    return nodeunit.reporters[name] || require(name);
}

var reporterName = process.argv[2];
var reporter = findReporter(reporterName);

process
    .on('message', function (filepaths) {
        reporter.run(filepaths, null, function (err, report) {
            process.send({
                err: err,
                report: report
            });
        });
    });

process.on('uncaughtException', function (err) {
    console.error(err.stack);
    process.send({
        err: err,
        report: []
    });
});

