Name: js-handler/node_modules/nodeunit/lib/reporters/verbose.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 = "Verbose 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) {
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 paths = files.map(function (p) {
57:
        return path.join(process.cwd(), p);
58:
    });
59:
    var tracker = track.createTracker(function (tracker) {
60:
        if (tracker.unfinished()) {
61:
            console.log('');
62:
            console.log(error(bold(
63:
                'FAILURES: Undone tests (or their setups/teardowns): '
64:
            )));
65:
            var names = tracker.names();
66:
            for (var i = 0; i < names.length; i += 1) {
67:
                console.log('- ' + names[i]);
68:
            }
69:
            console.log('');
70:
            console.log('To fix this, make sure all tests call test.done()');
71:
            process.reallyExit(tracker.unfinished());
72:
        }
73:
    });
74:
 
75:
    nodeunit.runFiles(paths, {
76:
        testspec: options.testspec,
77:
        testFullSpec: options.testFullSpec,
78:
        moduleStart: function (name) {
79:
            console.log('\n' + bold(name));
80:
        },
81:
        testDone: function (name, assertions) {
82:
            tracker.remove(name);
83:
 
84:
            if (!assertions.failures()) {
85:
                console.log('✔ ' + name);
86:
            }
87:
            else {
88:
                console.log(error('✖ ' + name));
89:
            }
90:
            // verbose so print everything
91:
            assertions.forEach(function (a) {
92:
              if (a.failed()) {
93:
                console.log(error('  ✖ ' + a.message));
94:
                a = utils.betterErrors(a);
95:
                console.log('  ' + a.error.stack);
96:
              }
97:
              else {
98:
                console.log('  ✔ ' + a.message);
99:
              }
100:
            });
101:
        },
102:
        done: function (assertions, end) {
103:
            var end = end || new Date().getTime();
104:
            var duration = end - start;
105:
            if (assertions.failures()) {
106:
                console.log(
107:
                    '\n' + bold(error('FAILURES: ')) + assertions.failures() +
108:
                    '/' + assertions.length + ' assertions failed (' +
109:
                    assertions.duration + 'ms)'
110:
                );
111:
            }
112:
            else {
113:
                console.log(
114:
                   '\n' + bold(ok('OK: ')) + assertions.length +
115:
                   ' assertions (' + assertions.duration + 'ms)'
116:
                );
117:
            }
118:
        },
119:
        testStart: function(name) {
120:
            tracker.put(name);
121:
        }
122:
    });
123:
};