Skip to content

Commit 7d41462

Browse files
committedMar 4, 2024
Refactor: replace progress canvas with text
1 parent 747d336 commit 7d41462

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed
 

‎lib/reporters/html.js

+4-23
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
var Base = require('./base');
1212
var utils = require('../utils');
13-
var Progress = require('../browser/progress');
1413
var escapeRe = require('escape-string-regexp');
1514
var constants = require('../runner').constants;
1615
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
@@ -38,7 +37,7 @@ exports = module.exports = HTML;
3837

3938
var statsTemplate =
4039
'<ul id="mocha-stats">' +
41-
'<li class="progress"><canvas width="40" height="40"></canvas></li>' +
40+
'<li class="progress"></li>' +
4241
'<li class="passes"><a href="javascript:void(0);">passes:</a> <em>0</em></li>' +
4342
'<li class="failures"><a href="javascript:void(0);">failures:</a> <em>0</em></li>' +
4443
'<li class="duration">duration: <em>0</em>s</li>' +
@@ -68,26 +67,14 @@ function HTML(runner, options) {
6867
var failures = items[2].getElementsByTagName('em')[0];
6968
var failuresLink = items[2].getElementsByTagName('a')[0];
7069
var duration = items[3].getElementsByTagName('em')[0];
71-
var canvas = stat.getElementsByTagName('canvas')[0];
7270
var report = fragment('<ul id="mocha-report"></ul>');
7371
var stack = [report];
74-
var progress;
75-
var ctx;
7672
var progressText;
7773
var root = document.getElementById('mocha');
7874

79-
if (canvas.getContext) {
80-
var ratio = window.devicePixelRatio || 1;
81-
canvas.style.width = canvas.width;
82-
canvas.style.height = canvas.height;
83-
canvas.width *= ratio;
84-
canvas.height *= ratio;
85-
ctx = canvas.getContext('2d');
86-
ctx.scale(ratio, ratio);
87-
progress = new Progress();
88-
} else {
75+
{
8976
// On some broswers, canvas might be unavailable for whatever reason.
90-
// As such, we need a text version as a fallback
77+
// As such, we need text and progress
9178
var progressTextFallback = fragment('<li class="progress-text">progress: <em>0</em>%</li>');
9279
progressText = progressTextFallback.getElementsByTagName('em')[0];
9380
items[0].replaceWith(progressTextFallback);
@@ -122,10 +109,6 @@ function HTML(runner, options) {
122109
root.appendChild(stat);
123110
root.appendChild(report);
124111

125-
if (progress) {
126-
progress.size(40);
127-
}
128-
129112
runner.on(EVENT_SUITE_BEGIN, function (suite) {
130113
if (suite.root) {
131114
return;
@@ -241,9 +224,7 @@ function HTML(runner, options) {
241224
function updateStats() {
242225
// TODO: add to stats
243226
var percent = ((stats.tests / runner.total) * 100) | 0;
244-
if (progress) {
245-
progress.update(percent).draw(ctx);
246-
} else if (progressText) {
227+
if (progressText) {
247228
// setting a toFixed that is too low, makes small changes to progress not shown
248229
// setting it too high, makes the progress text longer then it needs to
249230
// to address this, calculate the toFixed based on the magnitude of total

0 commit comments

Comments
 (0)