123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- var path = require('path');
- var fs = require('fs');
- var nodeunit = require('nodeunit');
-
- var filepaths = fs.readdirSync('test').map(function(filename) {
- return path.join('test', filename);
- });
-
- var unfinished = {};
- var currentModule;
- function sendMessage(message) {
- process.stdout.write(JSON.stringify(message) + '\n');
- }
-
-
- process.on('uncaughtException', function (e) {
- sendMessage({error: [e.name, e.message, e.stack]});
- process.exit();
- });
-
-
- var unfinished = {};
- process.on('exit', function (e) {
- var len = Object.keys(unfinished).length
- if (len > 0) {
- sendMessage({exit: ['UNFINISHED']});
-
- } else {
- sendMessage({exit: ['finished']});
- }
-
- });
-
- nodeunit.reporters.test = {
- run: function(files, options, callback) {
-
- var paths = files.map(function (filepath) {
- return path.resolve(filepath);
- });
- nodeunit.runFiles(paths, {
-
- testspec: undefined,
-
-
- moduleStart: function(name) {
-
-
- currentModule = name;
-
- sendMessage({moduleStart: [name.toString()]});
- },
-
-
- moduleDone: function(name) {
-
- if (name !== currentModule) { return; }
-
- sendMessage({moduleDone: [name.toString()]});
- },
-
- testStart: function(name) {
-
-
- unfinished[name] = name;
-
- sendMessage({testStart: [name.toString()]});
- },
-
- testDone: function(name, assertions) {
- delete unfinished[name];
-
- sendMessage({testDone: [
- name.toString(),
- assertions.failures(),
- assertions.map(function(assertion) {
- var e = assertion.error;
- if (e) {
- assertion.error = {
- name: e.name,
- message: e.message,
- stack: e.stack
- };
- }
- return assertion;
- })
- ]});
- },
-
- done: function (assertions) {
-
- sendMessage({done: [
- assertions.failures(),
- assertions.duration,
- assertions
- ]});
- }
- });
- }
- }
-
- nodeunit.reporters.test.run(filepaths, {});
|