From 966ab86017d469332e62aa501d1c8776ed47ef9d Mon Sep 17 00:00:00 2001 From: Avi Vahl Date: Wed, 8 Jun 2016 14:54:29 +0300 Subject: [PATCH 1/2] Fix % always 0 in HTML reporter updateStats() accesses this.total, but this === the global object (window) if not specified explicitly. Also added a missing update when all tests end. --- lib/reporters/html.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/reporters/html.js b/lib/reporters/html.js index 5167d18bfc..e498328145 100644 --- a/lib/reporters/html.js +++ b/lib/reporters/html.js @@ -125,6 +125,7 @@ function HTML(runner) { runner.on('suite end', function(suite) { if (suite.root) { + updateStats.call(this); return; } stack.shift(); @@ -137,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(); + updateStats.call(this); }); runner.on('fail', function(test) { @@ -177,13 +178,13 @@ function HTML(runner) { self.addCodeToggle(el, test.body); appendToStack(el); - updateStats(); + updateStats.call(this); }); runner.on('pending', function(test) { var el = fragment('
  • %e

  • ', test.title); appendToStack(el); - updateStats(); + updateStats.call(this); }); function appendToStack(el) { From 85ffb51cfb0957a485b75d5c1198ecb9e4f33b86 Mon Sep 17 00:00:00 2001 From: Avi Vahl Date: Sun, 12 Jun 2016 00:51:57 +0300 Subject: [PATCH 2/2] Alternative method to achieve a cleaner syntax. --- lib/reporters/html.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/reporters/html.js b/lib/reporters/html.js index e498328145..51ba1ca722 100644 --- a/lib/reporters/html.js +++ b/lib/reporters/html.js @@ -125,7 +125,7 @@ function HTML(runner) { runner.on('suite end', function(suite) { if (suite.root) { - updateStats.call(this); + updateStats(); return; } stack.shift(); @@ -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) { @@ -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('
  • %e

  • ', test.title); appendToStack(el); - updateStats.call(this); + updateStats(); }); function appendToStack(el) { @@ -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; if (progress) { progress.update(percent).draw(ctx); }