File: track.js

package info (click to toggle)
node-nodeunit 0.11.2%2Bds3-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,044 kB
  • sloc: makefile: 154; sh: 2
file content (48 lines) | stat: -rw-r--r-- 1,204 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*!
 * Simple util module to track tests. Adds a process.exit hook to print
 * the undone tests.
 */


exports.createTracker = function (on_exit) {
    var names = {};
    var tracker = {
        names: function () {
            var arr = [];
            for (var k in names) {
                if (names.hasOwnProperty(k)) {
                    arr.push(k);
                }
            }
            return arr;
        },
        unfinished: function () {
            return tracker.names().length;
        },
        put: function (testname) {
            names[testname] = testname;
        },
        remove: function (testname) {
            delete names[testname];
        }
    };

    process.on('exit', function() {
        on_exit = on_exit || exports.default_on_exit;
        on_exit(tracker);
    });

    return tracker;
};

exports.default_on_exit = function (tracker) {
    if (tracker.unfinished()) {
        console.log('');
        console.log('Undone tests (or their setups/teardowns): ');
        var names = tracker.names();
        for (var i = 0; i < names.length; i += 1) {
            console.log(names[i]);
        }
        process.reallyExit(tracker.unfinished());
    }
};