Name: js-handler/node_modules/nodeunit/lib/reporters/browser.js 
1:
/*!
2:
 * Nodeunit
3:
 * Copyright (c) 2010 Caolan McMahon
4:
 * MIT Licensed
5:
 *
6:
 * THIS FILE SHOULD BE BROWSER-COMPATIBLE JS!
7:
 * You can use @REMOVE_LINE_FOR_BROWSER to remove code from the browser build.
8:
 * Only code on that line will be removed, its mostly to avoid requiring code
9:
 * that is node specific
10:
 */
11:
 
12:
 
13:
/**
14:
 * NOTE: this test runner is not listed in index.js because it cannot be
15:
 * used with the command-line tool, only inside the browser.
16:
 */
17:
 
18:
 
19:
/**
20:
 * Reporter info string
21:
 */
22:
 
23:
exports.info = "Browser-based test reporter";
24:
 
25:
 
26:
/**
27:
 * Run all tests within each module, reporting the results
28:
 *
29:
 * @param {Array} files
30:
 * @api public
31:
 */
32:
 
33:
exports.run = function (modules, options) {
34:
    var start = new Date().getTime(), div;
35:
  options = options || {};
36:
  div = options.div || document.body;
37:
 
38:
    function setText(el, txt) {
39:
        if ('innerText' in el) {
40:
            el.innerText = txt;
41:
        }
42:
        else if ('textContent' in el){
43:
            el.textContent = txt;
44:
        }
45:
    }
46:
 
47:
    function getOrCreate(tag, id) {
48:
        var el = document.getElementById(id);
49:
        if (!el) {
50:
            el = document.createElement(tag);
51:
            el.id = id;
52:
            div.appendChild(el);
53:
        }
54:
        return el;
55:
    };
56:
 
57:
    var header = getOrCreate('h1', 'nodeunit-header');
58:
    var banner = getOrCreate('h2', 'nodeunit-banner');
59:
    var userAgent = getOrCreate('h2', 'nodeunit-userAgent');
60:
    var tests = getOrCreate('ol', 'nodeunit-tests');
61:
    var result = getOrCreate('p', 'nodeunit-testresult');
62:
 
63:
    setText(userAgent, navigator.userAgent);
64:
 
65:
    nodeunit.runModules(modules, {
66:
        moduleStart: function (name) {
67:
            /*var mheading = document.createElement('h2');
68:
            mheading.innerText = name;
69:
            results.appendChild(mheading);
70:
            module = document.createElement('ol');
71:
            results.appendChild(module);*/
72:
        },
73:
        testDone: function (name, assertions) {
74:
            var test = document.createElement('li');
75:
            var strong = document.createElement('strong');
76:
            strong.innerHTML = name + ' <b style="color: black;">(' +
77:
                '<b class="fail">' + assertions.failures() + '</b>, ' +
78:
                '<b class="pass">' + assertions.passes() + '</b>, ' +
79:
                assertions.length +
80:
            ')</b>';
81:
            test.className = assertions.failures() ? 'fail': 'pass';
82:
            test.appendChild(strong);
83:
 
84:
            var aList = document.createElement('ol');
85:
            aList.style.display = 'none';
86:
            test.onclick = function () {
87:
                var d = aList.style.display;
88:
                aList.style.display = (d == 'none') ? 'block': 'none';
89:
            };
90:
            for (var i=0; i<assertions.length; i++) {
91:
                var li = document.createElement('li');
92:
                var a = assertions[i];
93:
                if (a.failed()) {
94:
                    li.innerHTML = (a.message || a.method || 'no message') +
95:
                        '<pre>' + (a.error.stack || a.error) + '</pre>';
96:
                    li.className = 'fail';
97:
                }
98:
                else {
99:
                    li.innerHTML = a.message || a.method || 'no message';
100:
                    li.className = 'pass';
101:
                }
102:
                aList.appendChild(li);
103:
            }
104:
            test.appendChild(aList);
105:
            tests.appendChild(test);
106:
        },
107:
        done: function (assertions) {
108:
            var end = new Date().getTime();
109:
            var duration = end - start;
110:
 
111:
            var failures = assertions.failures();
112:
            banner.className = failures ? 'fail': 'pass';
113:
 
114:
            result.innerHTML = 'Tests completed in ' + duration +
115:
                ' milliseconds.<br/><span class="passed">' +
116:
                assertions.passes() + '</span> assertions of ' +
117:
                '<span class="all">' + assertions.length + '<span> passed, ' +
118:
                assertions.failures() + ' failed.';
119:
        }
120:
    });
121:
};