Name: js-handler/node_modules/nodeunit/lib/reporters/eclipse.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 = "Reporter for eclipse plugin";
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:
    var start = new Date().getTime();
35:
    var paths = files.map(function (p) {
36:
        if (p.indexOf('/') === 0) {
37:
            return p;
38:
        }
39:
        return path.join(process.cwd(), p);
40:
    });
41:
    var tracker = track.createTracker(function (tracker) {
42:
        if (tracker.unfinished()) {
43:
            console.log('');
44:
            console.log('FAILURES: Undone tests (or their setups/teardowns): ');
45:
            var names = tracker.names();
46:
            for (var i = 0; i < names.length; i += 1) {
47:
                console.log('- ' + names[i]);
48:
            }
49:
            console.log('');
50:
            console.log('To fix this, make sure all tests call test.done()');
51:
            process.reallyExit(tracker.unfinished());
52:
        }
53:
    });
54:
 
55:
    nodeunit.runFiles(paths, {
56:
        testspec: undefined,
57:
        moduleStart: function (name) {
58:
            console.log('\n' + name);
59:
        },
60:
        testDone: function (name, assertions) {
61:
            tracker.remove(name);
62:
 
63:
            if (!assertions.failures()) {
64:
                console.log('✔ ' + name);
65:
            }
66:
            else {
67:
                console.log('✖ ' + name + '\n');
68:
                assertions.forEach(function (a) {
69:
                    if (a.failed()) {
70:
                        a = utils.betterErrors(a);
71:
                        if (a.error instanceof AssertionError && a.message) {
72:
                            console.log(
73:
                                'Assertion Message: ' + a.message
74:
                            );
75:
                        }
76:
                        console.log(a.error.stack + '\n');
77:
                    }
78:
                });
79:
            }
80:
        },
81:
        done: function (assertions, end) {
82:
            var end = end || new Date().getTime();
83:
            var duration = end - start;
84:
            if (assertions.failures()) {
85:
                console.log(
86:
                    '\n' + 'FAILURES: ' + assertions.failures() +
87:
                    '/' + assertions.length + ' assertions failed (' +
88:
                    assertions.duration + 'ms)'
89:
                );
90:
            }
91:
            else {
92:
                console.log(
93:
                   '\n' + 'OK: ' + assertions.length +
94:
                   ' assertions (' + assertions.duration + 'ms)'
95:
                );
96:
            }
97:
 
98:
            if (callback) callback(assertions.failures() ? new Error('We have got test failures.') : undefined);
99:
        },
100:
        testStart: function (name) {
101:
            tracker.put(name);
102:
        }
103:
    });
104:
};