Name: js-handler/node_modules/nodeunit/lib/reporters/minimal.js 
1:
/*!
2:
 * Nodeunit
3:
 * Copyright (c) 2010 Caolan McMahon
4:
 * MIT Licensed
5:
 */
6:
 
7:
/**
8:
 * Module dependencies
9:
 */
10:
 
11:
var nodeunit = require('../nodeunit'),
12:
    utils = require('../utils'),
13:
    fs = require('fs'),
14:
    path = require('path'),
15:
    AssertionError = require('assert').AssertionError;
16:
 
17:
/**
18:
 * Reporter info string
19:
 */
20:
 
21:
exports.info = "Pretty minimal output";
22:
 
23:
/**
24:
 * Run all tests within each module, reporting the results to the command-line.
25:
 *
26:
 * @param {Array} files
27:
 * @api public
28:
 */
29:
 
30:
exports.run = function (files, options, callback) {
31:
 
32:
    if (!options) {
33:
        // load default options
34:
        var content = fs.readFileSync(
35:
            __dirname + '/../../bin/nodeunit.json', 'utf8'
36:
        );
37:
        options = JSON.parse(content);
38:
    }
39:
 
40:
    var red   = function (str) {
41:
        return options.error_prefix + str + options.error_suffix;
42:
    };
43:
    var green = function (str) {
44:
        return options.ok_prefix + str + options.ok_suffix;
45:
    };
46:
    var magenta = function (str) {
47:
        return options.assertion_prefix + str + options.assertion_suffix;
48:
    };
49:
    var bold  = function (str) {
50:
        return options.bold_prefix + str + options.bold_suffix;
51:
    };
52:
 
53:
    var start = new Date().getTime();
54:
 
55:
  var opts = {
56:
      testspec: options.testspec,
57:
      testFullSpec: options.testFullSpec,
58:
        moduleStart: function (name) {
59:
            process.stdout.write(bold(name) + ': ');
60:
        },
61:
        moduleDone: function (name, assertions) {
62:
            console.log('');
63:
            if (assertions.failures()) {
64:
                assertions.forEach(function (a) {
65:
                    if (a.failed()) {
66:
                        a = utils.betterErrors(a);
67:
                        if (a.error instanceof AssertionError && a.message) {
68:
                            console.log(
69:
                                'Assertion in test ' + bold(a.testname) + ': ' +
70:
                                magenta(a.message)
71:
                            );
72:
                        }
73:
                        console.log(a.error.stack + '\n');
74:
                    }
75:
                });
76:
            }
77:
 
78:
        },
79:
        testStart: function () {
80:
        },
81:
        testDone: function (name, assertions) {
82:
            if (!assertions.failures()) {
83:
                process.stdout.write('.');
84:
            }
85:
            else {
86:
                process.stdout.write(red('F'));
87:
                assertions.forEach(function (assertion) {
88:
                    assertion.testname = name;
89:
                });
90:
            }
91:
        },
92:
        done: function (assertions) {
93:
            var end = new Date().getTime();
94:
            var duration = end - start;
95:
            if (assertions.failures()) {
96:
                console.log(
97:
                    '\n' + bold(red('FAILURES: ')) + assertions.failures() +
98:
                    '/' + assertions.length + ' assertions failed (' +
99:
                    assertions.duration + 'ms)'
100:
                );
101:
            }
102:
            else {
103:
                console.log(
104:
                    '\n' + bold(green('OK: ')) + assertions.length +
105:
                    ' assertions (' + assertions.duration + 'ms)'
106:
                );
107:
            }
108:
 
109:
            if (callback) callback(assertions.failures() ? new Error('We have got test failures.') : undefined);
110:
        }
111:
    };
112:
 
113:
  if (files && files.length) {
114:
      var paths = files.map(function (p) {
115:
          return path.join(process.cwd(), p);
116:
      });
117:
      nodeunit.runFiles(paths, opts);
118:
  } else {
119:
    nodeunit.runModules(files,opts);
120:
  }
121:
};