Skip to content

Commit 52dcc3f

Browse files
committed
Rebuild mocha.js
1 parent 7496c14 commit 52dcc3f

File tree

1 file changed

+83
-69
lines changed

1 file changed

+83
-69
lines changed

mocha.js

Lines changed: 83 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,7 +2559,8 @@ function HTML(runner) {
25592559
}
25602560

25612561
// pass toggle
2562-
on(passesLink, 'click', function() {
2562+
on(passesLink, 'click', function(evt) {
2563+
evt.preventDefault();
25632564
unhide();
25642565
var name = (/pass/).test(report.className) ? '' : ' pass';
25652566
report.className = report.className.replace(/fail|pass/g, '') + name;
@@ -2569,7 +2570,8 @@ function HTML(runner) {
25692570
});
25702571

25712572
// failure toggle
2572-
on(failuresLink, 'click', function() {
2573+
on(failuresLink, 'click', function(evt) {
2574+
evt.preventDefault();
25732575
unhide();
25742576
var name = (/fail/).test(report.className) ? '' : ' fail';
25752577
report.className = report.className.replace(/fail|pass/g, '') + name;
@@ -2607,88 +2609,82 @@ function HTML(runner) {
26072609
stack.shift();
26082610
});
26092611

2610-
runner.on('fail', function(test) {
2611-
// For type = 'test' its possible that the test failed due to multiple
2612-
// done() calls. So report the issue here.
2613-
if (test.type === 'hook'
2614-
|| test.type === 'test') {
2615-
runner.emit('test end', test);
2616-
}
2612+
runner.on('pass', function(test) {
2613+
var url = self.testURL(test);
2614+
var markup = '<li class="test pass %e"><h2>%e<span class="duration">%ems</span> '
2615+
+ '<a href="%s" class="replay">‣</a></h2></li>';
2616+
var el = fragment(markup, test.speed, test.title, test.duration, url);
2617+
self.addCodeToggle(el, test.body);
2618+
appendToStack(el);
2619+
updateStats();
26172620
});
26182621

2619-
runner.on('test end', function(test) {
2620-
// TODO: add to stats
2621-
var percent = stats.tests / this.total * 100 | 0;
2622-
if (progress) {
2623-
progress.update(percent).draw(ctx);
2624-
}
2625-
2626-
// update stats
2627-
var ms = new Date() - stats.start;
2628-
text(passes, stats.passes);
2629-
text(failures, stats.failures);
2630-
text(duration, (ms / 1000).toFixed(2));
2631-
2632-
// test
2633-
var el;
2634-
if (test.state === 'passed') {
2635-
var url = self.testURL(test);
2636-
el = fragment('<li class="test pass %e"><h2>%e<span class="duration">%ems</span> <a href="%s" class="replay">‣</a></h2></li>', test.speed, test.title, test.duration, url);
2637-
} else if (test.isPending()) {
2638-
el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
2639-
} else {
2640-
el = fragment('<li class="test fail"><h2>%e <a href="%e" class="replay">‣</a></h2></li>', test.title, self.testURL(test));
2641-
var stackString; // Note: Includes leading newline
2642-
var message = test.err.toString();
2643-
2644-
// <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
2645-
// check for the result of the stringifying.
2646-
if (message === '[object Error]') {
2647-
message = test.err.message;
2648-
}
2649-
2650-
if (test.err.stack) {
2651-
var indexOfMessage = test.err.stack.indexOf(test.err.message);
2652-
if (indexOfMessage === -1) {
2653-
stackString = test.err.stack;
2654-
} else {
2655-
stackString = test.err.stack.substr(test.err.message.length + indexOfMessage);
2656-
}
2657-
} else if (test.err.sourceURL && test.err.line !== undefined) {
2658-
// Safari doesn't give you a stack. Let's at least provide a source line.
2659-
stackString = '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
2660-
}
2622+
runner.on('fail', function(test) {
2623+
var el = fragment('<li class="test fail"><h2>%e <a href="%e" class="replay">‣</a></h2></li>',
2624+
test.title, self.testURL(test));
2625+
var stackString; // Note: Includes leading newline
2626+
var message = test.err.toString();
26612627

2662-
stackString = stackString || '';
2628+
// <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
2629+
// check for the result of the stringifying.
2630+
if (message === '[object Error]') {
2631+
message = test.err.message;
2632+
}
26632633

2664-
if (test.err.htmlMessage && stackString) {
2665-
el.appendChild(fragment('<div class="html-error">%s\n<pre class="error">%e</pre></div>', test.err.htmlMessage, stackString));
2666-
} else if (test.err.htmlMessage) {
2667-
el.appendChild(fragment('<div class="html-error">%s</div>', test.err.htmlMessage));
2634+
if (test.err.stack) {
2635+
var indexOfMessage = test.err.stack.indexOf(test.err.message);
2636+
if (indexOfMessage === -1) {
2637+
stackString = test.err.stack;
26682638
} else {
2669-
el.appendChild(fragment('<pre class="error">%e%e</pre>', message, stackString));
2639+
stackString = test.err.stack.substr(test.err.message.length + indexOfMessage);
26702640
}
2641+
} else if (test.err.sourceURL && test.err.line !== undefined) {
2642+
// Safari doesn't give you a stack. Let's at least provide a source line.
2643+
stackString = '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
26712644
}
26722645

2673-
// toggle code
2674-
// TODO: defer
2675-
if (!test.isPending()) {
2676-
var h2 = el.getElementsByTagName('h2')[0];
2646+
stackString = stackString || '';
26772647

2678-
on(h2, 'click', function() {
2679-
pre.style.display = pre.style.display === 'none' ? 'block' : 'none';
2680-
});
2681-
2682-
var pre = fragment('<pre><code>%e</code></pre>', utils.clean(test.body));
2683-
el.appendChild(pre);
2684-
pre.style.display = 'none';
2648+
if (test.err.htmlMessage && stackString) {
2649+
el.appendChild(fragment('<div class="html-error">%s\n<pre class="error">%e</pre></div>',
2650+
test.err.htmlMessage, stackString));
2651+
} else if (test.err.htmlMessage) {
2652+
el.appendChild(fragment('<div class="html-error">%s</div>', test.err.htmlMessage));
2653+
} else {
2654+
el.appendChild(fragment('<pre class="error">%e%e</pre>', message, stackString));
26852655
}
26862656

2657+
self.addCodeToggle(el, test.body);
2658+
appendToStack(el);
2659+
updateStats();
2660+
});
2661+
2662+
runner.on('pending', function(test) {
2663+
var el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
2664+
appendToStack(el);
2665+
updateStats();
2666+
});
2667+
2668+
function appendToStack(el) {
26872669
// Don't call .appendChild if #mocha-report was already .shift()'ed off the stack.
26882670
if (stack[0]) {
26892671
stack[0].appendChild(el);
26902672
}
2691-
});
2673+
}
2674+
2675+
function updateStats() {
2676+
// TODO: add to stats
2677+
var percent = stats.tests / this.total * 100 | 0;
2678+
if (progress) {
2679+
progress.update(percent).draw(ctx);
2680+
}
2681+
2682+
// update stats
2683+
var ms = new Date() - stats.start;
2684+
text(passes, stats.passes);
2685+
text(failures, stats.failures);
2686+
text(duration, (ms / 1000).toFixed(2));
2687+
}
26922688
}
26932689

26942690
/**
@@ -2726,6 +2722,24 @@ HTML.prototype.testURL = function(test) {
27262722
return makeUrl(test.fullTitle());
27272723
};
27282724

2725+
/**
2726+
* Adds code toggle functionality for the provided test's list element.
2727+
*
2728+
* @param {HTMLLIElement} el
2729+
* @param {string} contents
2730+
*/
2731+
HTML.prototype.addCodeToggle = function(el, contents) {
2732+
var h2 = el.getElementsByTagName('h2')[0];
2733+
2734+
on(h2, 'click', function() {
2735+
pre.style.display = pre.style.display === 'none' ? 'block' : 'none';
2736+
});
2737+
2738+
var pre = fragment('<pre><code>%e</code></pre>', utils.clean(contents));
2739+
el.appendChild(pre);
2740+
pre.style.display = 'none';
2741+
};
2742+
27292743
/**
27302744
* Display error `msg`.
27312745
*

0 commit comments

Comments
 (0)