|
10 | 10 |
|
11 | 11 | var Base = require('./base');
|
12 | 12 | var utils = require('../utils');
|
13 |
| -var Progress = require('../browser/progress'); |
14 | 13 | var escapeRe = require('escape-string-regexp');
|
15 | 14 | var constants = require('../runner').constants;
|
16 | 15 | var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
@@ -38,7 +37,7 @@ exports = module.exports = HTML;
|
38 | 37 |
|
39 | 38 | var statsTemplate =
|
40 | 39 | '<ul id="mocha-stats">' +
|
41 |
| - '<li class="progress"><canvas width="40" height="40"></canvas></li>' + |
| 40 | + '<li class="progress-contain"><progress class="progress-element" max="100" value="0"></progress><svg class="progress-ring"><circle class="ring-flatlight" stroke-dasharray="100%,0%"/><circle class="ring-highlight" stroke-dasharray="0%,100%"/></svg><div class="progress-text">0%</div></li>' + |
42 | 41 | '<li class="passes"><a href="javascript:void(0);">passes:</a> <em>0</em></li>' +
|
43 | 42 | '<li class="failures"><a href="javascript:void(0);">failures:</a> <em>0</em></li>' +
|
44 | 43 | '<li class="duration">duration: <em>0</em>s</li>' +
|
@@ -68,24 +67,16 @@ function HTML(runner, options) {
|
68 | 67 | var failures = items[2].getElementsByTagName('em')[0];
|
69 | 68 | var failuresLink = items[2].getElementsByTagName('a')[0];
|
70 | 69 | var duration = items[3].getElementsByTagName('em')[0];
|
71 |
| - var canvas = stat.getElementsByTagName('canvas')[0]; |
72 | 70 | var report = fragment('<ul id="mocha-report"></ul>');
|
73 | 71 | var stack = [report];
|
74 |
| - var progress; |
75 |
| - var ctx; |
| 72 | + var progressText = items[0].getElementsByTagName('div')[0]; |
| 73 | + var progressBar = items[0].getElementsByTagName('progress')[0]; |
| 74 | + var progressRing = [ |
| 75 | + items[0].getElementsByClassName('ring-flatlight')[0], |
| 76 | + items[0].getElementsByClassName('ring-highlight')[0]]; |
| 77 | + var progressRingRadius = null; // computed CSS unavailable now, so set later |
76 | 78 | var root = document.getElementById('mocha');
|
77 | 79 |
|
78 |
| - if (canvas.getContext) { |
79 |
| - var ratio = window.devicePixelRatio || 1; |
80 |
| - canvas.style.width = canvas.width; |
81 |
| - canvas.style.height = canvas.height; |
82 |
| - canvas.width *= ratio; |
83 |
| - canvas.height *= ratio; |
84 |
| - ctx = canvas.getContext('2d'); |
85 |
| - ctx.scale(ratio, ratio); |
86 |
| - progress = new Progress(); |
87 |
| - } |
88 |
| - |
89 | 80 | if (!root) {
|
90 | 81 | return error('#mocha div missing, add it to your document');
|
91 | 82 | }
|
@@ -115,10 +106,6 @@ function HTML(runner, options) {
|
115 | 106 | root.appendChild(stat);
|
116 | 107 | root.appendChild(report);
|
117 | 108 |
|
118 |
| - if (progress) { |
119 |
| - progress.size(40); |
120 |
| - } |
121 |
| - |
122 | 109 | runner.on(EVENT_SUITE_BEGIN, function (suite) {
|
123 | 110 | if (suite.root) {
|
124 | 111 | return;
|
@@ -234,8 +221,26 @@ function HTML(runner, options) {
|
234 | 221 | function updateStats() {
|
235 | 222 | // TODO: add to stats
|
236 | 223 | var percent = ((stats.tests / runner.total) * 100) | 0;
|
237 |
| - if (progress) { |
238 |
| - progress.update(percent).draw(ctx); |
| 224 | + progressBar.value = percent; |
| 225 | + if (progressText) { |
| 226 | + // setting a toFixed that is too low, makes small changes to progress not shown |
| 227 | + // setting it too high, makes the progress text longer then it needs to |
| 228 | + // to address this, calculate the toFixed based on the magnitude of total |
| 229 | + var decimalPlaces = Math.ceil(Math.log10(runner.total / 100)); |
| 230 | + text( |
| 231 | + progressText, |
| 232 | + percent.toFixed(Math.min(Math.max(decimalPlaces, 0), 100)) + '%' |
| 233 | + ); |
| 234 | + } |
| 235 | + if (progressRing) { |
| 236 | + var radius = parseFloat(getComputedStyle(progressRing[0]).getPropertyValue('r')); |
| 237 | + var wholeArc = Math.PI * 2 * radius; |
| 238 | + var highlightArc = percent * (wholeArc / 100); |
| 239 | + // The progress ring is in 2 parts, the flatlight color and highlight color. |
| 240 | + // Rendering both on top of the other, seems to make a 3rd color on the edges. |
| 241 | + // To create 1 whole ring with 2 colors, both parts are inverse of the other. |
| 242 | + progressRing[0].style['stroke-dasharray'] = `0,${highlightArc}px,${wholeArc}px`; |
| 243 | + progressRing[1].style['stroke-dasharray'] = `${highlightArc}px,${wholeArc}px`; |
239 | 244 | }
|
240 | 245 |
|
241 | 246 | // update stats
|
|
0 commit comments