Skip to content

Commit

Permalink
Alternative method to achieve a cleaner syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
AviVahl committed Jun 11, 2016
1 parent 966ab86 commit 85ffb51
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/reporters/html.js
Expand Up @@ -125,7 +125,7 @@ function HTML(runner) {

runner.on('suite end', function(suite) {
if (suite.root) {
updateStats.call(this);
updateStats();
return;
}
stack.shift();
Expand All @@ -138,7 +138,7 @@ function HTML(runner) {
var el = fragment(markup, test.speed, test.title, test.duration, url);
self.addCodeToggle(el, test.body);
appendToStack(el);
updateStats.call(this);
updateStats();
});

runner.on('fail', function(test) {
Expand Down Expand Up @@ -178,13 +178,13 @@ function HTML(runner) {

self.addCodeToggle(el, test.body);
appendToStack(el);
updateStats.call(this);
updateStats();
});

runner.on('pending', function(test) {
var el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
appendToStack(el);
updateStats.call(this);
updateStats();
});

function appendToStack(el) {
Expand All @@ -196,7 +196,7 @@ function HTML(runner) {

function updateStats() {
// TODO: add to stats
var percent = stats.tests / this.total * 100 | 0;
var percent = stats.tests / runner.total * 100 | 0;

This comment has been minimized.

Copy link
@callmevlad

callmevlad Jul 26, 2016

Contributor

Hey @AviVahl, I tried running this code and it looks like the calculation is lightly off - e.g. if you have a test suite of 3 tests, the final number turns out to be 66.6666% percent because stats.test is 0-based (would have values of 0, 1, 2 in each respective iteration, and 2/3 * 100 !== 100. Have you seen this? Can be easy to miss with a lot of tests because 99.9% rounds up to 100% in the UI.

This comment has been minimized.

Copy link
@AviVahl

AviVahl Jul 26, 2016

Author Contributor

Make sure you add the call to updateStats() in the 'suit end' section as well. Another commit in this pull request did that. Look at the following link for the entire diff:
https://github.com/mochajs/mocha/pull/2299/files

This comment has been minimized.

Copy link
@callmevlad

callmevlad Jul 27, 2016

Contributor

Ah, perfect - I was cherry picking since 3.0 isn't on npm yet, but missed the other commit 😬 Thanks for the pointer! 👍

This comment has been minimized.

Copy link
@AviVahl

AviVahl Jul 27, 2016

Author Contributor

Glad to be of help :)
We are eagerly waiting for stable 3.0 to come out for this fix and others (.only, etc...)

if (progress) {
progress.update(percent).draw(ctx);
}
Expand Down

0 comments on commit 85ffb51

Please sign in to comment.