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