Skip to content

Commit 0ebcb26

Browse files
committed
Merge pull request #312 from brettz9/master
For reporting errors, provide options to: 1) display errors by defaul…
2 parents d8b4f70 + 0b66bbc commit 0ebcb26

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

examples/browser/nodeunit.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,8 @@ exports.info = "Browser-based test reporter";
19411941

19421942
exports.run = function (modules, options) {
19431943
var start = new Date().getTime();
1944+
var textareas = options.textareas;
1945+
var displayErrorsByDefault = options.displayErrorsByDefault;
19441946

19451947
function setText(el, txt) {
19461948
if ('innerText' in el) {
@@ -1989,8 +1991,8 @@ exports.run = function (modules, options) {
19891991
test.appendChild(strong);
19901992

19911993
var aList = document.createElement('ol');
1992-
aList.style.display = 'none';
1993-
test.onclick = function () {
1994+
aList.style.display = displayErrorsByDefault ? 'block' : 'none';
1995+
(displayErrorsByDefault ? strong : test).onclick = function () {
19941996
var d = aList.style.display;
19951997
aList.style.display = (d == 'none') ? 'block': 'none';
19961998
};
@@ -1999,7 +2001,9 @@ exports.run = function (modules, options) {
19992001
var a = assertions[i];
20002002
if (a.failed()) {
20012003
li.innerHTML = (a.message || a.method || 'no message') +
2002-
'<pre>' + (a.error.stack || a.error) + '</pre>';
2004+
(textareas ?
2005+
'<textarea rows="20" cols="100">' + (a.error.stack || a.error) + '</textarea>' :
2006+
'<pre>' + (a.error.stack || a.error) + '</pre>');
20032007
li.className = 'fail';
20042008
}
20052009
else {

lib/reporters/browser.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ exports.info = "Browser-based test reporter";
3131
*/
3232

3333
exports.run = function (modules, options, callback) {
34-
var start = new Date().getTime(), div;
35-
options = options || {};
36-
div = options.div || document.body;
34+
var start = new Date().getTime(), div, textareas, displayErrorsByDefault;
35+
options = options || {};
36+
div = options.div || document.body;
37+
textareas = options.textareas;
38+
displayErrorsByDefault = options.displayErrorsByDefault;
3739

3840
function setText(el, txt) {
3941
if ('innerText' in el) {
@@ -82,8 +84,8 @@ exports.run = function (modules, options, callback) {
8284
test.appendChild(strong);
8385

8486
var aList = document.createElement('ol');
85-
aList.style.display = 'none';
86-
test.onclick = function () {
87+
aList.style.display = displayErrorsByDefault ? 'block' : 'none';
88+
(displayErrorsByDefault ? strong : test).onclick = function () {
8789
var d = aList.style.display;
8890
aList.style.display = (d == 'none') ? 'block': 'none';
8991
};
@@ -92,7 +94,9 @@ exports.run = function (modules, options, callback) {
9294
var a = assertions[i];
9395
if (a.failed()) {
9496
li.innerHTML = (a.message || a.method || 'no message') +
95-
'<pre>' + (a.error.stack || a.error) + '</pre>';
97+
(textareas ?
98+
'<textarea rows="20" cols="100">' + (a.error.stack || a.error) + '</textarea>' :
99+
'<pre>' + (a.error.stack || a.error) + '</pre>');
96100
li.className = 'fail';
97101
}
98102
else {

0 commit comments

Comments
 (0)