Skip to content

Commit

Permalink
Refactor: replace progress canvas with text
Browse files Browse the repository at this point in the history
  • Loading branch information
yourWaifu committed Mar 4, 2024
1 parent 747d336 commit 7d41462
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions lib/reporters/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

var Base = require('./base');
var utils = require('../utils');
var Progress = require('../browser/progress');
var escapeRe = require('escape-string-regexp');
var constants = require('../runner').constants;
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
Expand Down Expand Up @@ -38,7 +37,7 @@ exports = module.exports = HTML;

var statsTemplate =
'<ul id="mocha-stats">' +
'<li class="progress"><canvas width="40" height="40"></canvas></li>' +
'<li class="progress"></li>' +
'<li class="passes"><a href="javascript:void(0);">passes:</a> <em>0</em></li>' +
'<li class="failures"><a href="javascript:void(0);">failures:</a> <em>0</em></li>' +
'<li class="duration">duration: <em>0</em>s</li>' +
Expand Down Expand Up @@ -68,26 +67,14 @@ function HTML(runner, options) {
var failures = items[2].getElementsByTagName('em')[0];
var failuresLink = items[2].getElementsByTagName('a')[0];
var duration = items[3].getElementsByTagName('em')[0];
var canvas = stat.getElementsByTagName('canvas')[0];
var report = fragment('<ul id="mocha-report"></ul>');
var stack = [report];
var progress;
var ctx;
var progressText;
var root = document.getElementById('mocha');

if (canvas.getContext) {
var ratio = window.devicePixelRatio || 1;
canvas.style.width = canvas.width;
canvas.style.height = canvas.height;
canvas.width *= ratio;
canvas.height *= ratio;
ctx = canvas.getContext('2d');
ctx.scale(ratio, ratio);
progress = new Progress();
} else {
{
// On some broswers, canvas might be unavailable for whatever reason.
// As such, we need a text version as a fallback
// As such, we need text and progress
var progressTextFallback = fragment('<li class="progress-text">progress: <em>0</em>%</li>');
progressText = progressTextFallback.getElementsByTagName('em')[0];
items[0].replaceWith(progressTextFallback);
Expand Down Expand Up @@ -122,10 +109,6 @@ function HTML(runner, options) {
root.appendChild(stat);
root.appendChild(report);

if (progress) {
progress.size(40);
}

runner.on(EVENT_SUITE_BEGIN, function (suite) {
if (suite.root) {
return;
Expand Down Expand Up @@ -241,9 +224,7 @@ function HTML(runner, options) {
function updateStats() {
// TODO: add to stats
var percent = ((stats.tests / runner.total) * 100) | 0;
if (progress) {
progress.update(percent).draw(ctx);
} else if (progressText) {
if (progressText) {
// setting a toFixed that is too low, makes small changes to progress not shown
// setting it too high, makes the progress text longer then it needs to
// to address this, calculate the toFixed based on the magnitude of total
Expand Down

0 comments on commit 7d41462

Please sign in to comment.