Name: js-handler/node_modules/nodeunit/lib/reporters/default.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:
    track = require('../track'),
15:
    path = require('path'),
16:
    AssertionError = require('../assert').AssertionError;
17:
 
18:
/**
19:
 * Reporter info string
20:
 */
21:
 
22:
exports.info = "Default tests reporter";
23:
 
24:
 
25:
/**
26:
 * Run all tests within each module, reporting the results to the command-line.
27:
 *
28:
 * @param {Array} files
29:
 * @api public
30:
 */
31:
 
32:
exports.run = function (files, options, callback) {
33:
 
34:
    if (!options) {
35:
        // load default options
36:
        var content = fs.readFileSync(
37:
            __dirname + '/../../bin/nodeunit.json', 'utf8'
38:
        );
39:
        options = JSON.parse(content);
40:
    }
41:
 
42:
    var error = function (str) {
43:
        return options.error_prefix + str + options.error_suffix;
44:
    };
45:
    var ok    = function (str) {
46:
        return options.ok_prefix + str + options.ok_suffix;
47:
    };
48:
    var bold  = function (str) {
49:
        return options.bold_prefix + str + options.bold_suffix;
50:
    };
51:
    var assertion_message = function (str) {
52:
        return options.assertion_prefix + str + options.assertion_suffix;
53:
    };
54:
 
55:
    var start = new Date().getTime();
56:
    var tracker = track.createTracker(function (tracker) {
57:
        if (tracker.unfinished()) {
58:
            console.log('');
59:
            console.log(error(bold(
60:
                'FAILURES: Undone tests (or their setups/teardowns): '
61:
            )));
62:
            var names = tracker.names();
63:
            for (var i = 0; i < names.length; i += 1) {
64:
                console.log('- ' + names[i]);
65:
            }
66:
            console.log('');
67:
            console.log('To fix this, make sure all tests call test.done()');
68:
            process.reallyExit(tracker.unfinished());
69:
        }
70:
    });
71:
 
72:
  var opts = {
73:
      testspec: options.testspec,
74:
      testFullSpec: options.testFullSpec,
75:
        moduleStart: function (name) {
76:
            console.log('\n' + bold(name));
77:
        },
78:
        testDone: function (name, assertions) {
79:
            tracker.remove(name);
80:
 
81:
            if (!assertions.failures()) {
82:
                console.log('✔ ' + name);
83:
            }
84:
            else {
85:
                console.log(error('✖ ' + name) + '\n');
86:
                assertions.forEach(function (a) {
87:
                    if (a.failed()) {
88:
                        a = utils.betterErrors(a);
89:
                        if (a.error instanceof AssertionError && a.message) {
90:
                            console.log(
91:
                                'Assertion Message: ' +
92:
                                assertion_message(a.message)
93:
                            );
94:
                        }
95:
                        console.log(a.error.stack + '\n');
96:
                    }
97:
                });
98:
            }
99:
        },
100:
        done: function (assertions, end) {
101:
            var end = end || new Date().getTime();
102:
            var duration = end - start;
103:
            if (assertions.failures()) {
104:
                console.log(
105:
                    '\n' + bold(error('FAILURES: ')) + assertions.failures() +
106:
                    '/' + assertions.length + ' assertions failed (' +
107:
                    assertions.duration + 'ms)'
108:
                );
109:
            }
110:
            else {
111:
                console.log(
112:
                   '\n' + bold(ok('OK: ')) + assertions.length +
113:
                   ' assertions (' + assertions.duration + 'ms)'
114:
                );
115:
            }
116:
 
117:
            if (callback) callback(assertions.failures() ? new Error('We have got test failures.') : undefined);
118:
        },
119:
        testStart: function(name) {
120:
            tracker.put(name);
121:
        }
122:
    };
123:
  if (files && files.length) {
124:
      var paths = files.map(function (p) {
125:
          return path.join(process.cwd(), p);
126:
      });
127:
      nodeunit.runFiles(paths, opts);
128:
  } else {
129:
    nodeunit.runModules(files,opts);
130:
  }
131:
};