From a2e600d70f4d7ca6ba8741ebe8c70cfec438ef1b Mon Sep 17 00:00:00 2001 From: Lucas Lopes Date: Fri, 8 Mar 2024 10:14:57 -0300 Subject: [PATCH 01/11] fix: closes #5115 (#5116) Eleventy wasn't being able to parse the JSDocs for the returned type on the getFullErrorStack function. Defining it as a new type and then referencing it on the function fixes the issue --- lib/reporters/base.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/reporters/base.js b/lib/reporters/base.js index 5af6e7bd8a..e0ca5f4863 100644 --- a/lib/reporters/base.js +++ b/lib/reporters/base.js @@ -227,7 +227,7 @@ var generateDiff = (exports.generateDiff = function (actual, expected) { * @private * @param {Error} err * @param {Set} [seen] - * @return {{ message: string, msg: string, stack: string }} + * @return {FullErrorStack} */ var getFullErrorStack = function (err, seen) { if (seen && seen.has(err)) { @@ -580,3 +580,12 @@ function sameType(a, b) { Base.consoleLog = consoleLog; Base.abstract = true; + +/** + * An object with all stack traces recursively mounted from each err.cause + * @memberof module:lib/reporters/base + * @typedef {Object} FullErrorStack + * @property {string} message + * @property {string} msg + * @property {string} stack + */ From efbb147590dfd7ff290de40a9930b07334784054 Mon Sep 17 00:00:00 2001 From: Bryan Mishkin <698306+bmish@users.noreply.github.com> Date: Tue, 12 Mar 2024 23:08:19 +0800 Subject: [PATCH 02/11] feat: add file path to xunit reporter (#4985) * feat: add file path to xunit reporter * Update lib/reporters/xunit.js Co-authored-by: Ville Lahdenvuo * Revert "Update lib/reporters/xunit.js" This reverts commit 1245e7e80f3d9faed99d459dcfebdb35d31be370. --------- Co-authored-by: Ville Lahdenvuo --- lib/reporters/xunit.js | 1 + test/reporters/xunit.spec.js | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/reporters/xunit.js b/lib/reporters/xunit.js index ec788c5da0..4e6fe2bcf9 100644 --- a/lib/reporters/xunit.js +++ b/lib/reporters/xunit.js @@ -158,6 +158,7 @@ XUnit.prototype.test = function (test) { var attrs = { classname: test.parent.fullTitle(), name: test.title, + file: test.file, time: test.duration / 1000 || 0 }; diff --git a/test/reporters/xunit.spec.js b/test/reporters/xunit.spec.js index a5e0f1bbeb..4e98cf6002 100644 --- a/test/reporters/xunit.spec.js +++ b/test/reporters/xunit.spec.js @@ -30,6 +30,7 @@ describe('XUnit reporter', function () { var expectedLine = 'some-line'; var expectedClassName = 'fullTitle'; var expectedTitle = 'some title'; + var expectedFile = 'testFile.spec.js'; var expectedMessage = 'some message'; var expectedDiff = '\n + expected - actual\n\n -foo\n +bar\n '; @@ -325,6 +326,7 @@ describe('XUnit reporter', function () { var expectedTest = { state: STATE_FAILED, title: expectedTitle, + file: expectedFile, parent: { fullTitle: function () { return expectedClassName; @@ -347,6 +349,8 @@ describe('XUnit reporter', function () { expectedClassName + '" name="' + expectedTitle + + '" file="' + + expectedFile + '" time="1">' + expectedMessage + '\n' + @@ -365,6 +369,7 @@ describe('XUnit reporter', function () { var expectedTest = { state: STATE_FAILED, title: expectedTitle, + file: expectedFile, parent: { fullTitle: function () { return expectedClassName; @@ -402,6 +407,7 @@ describe('XUnit reporter', function () { return true; }, title: expectedTitle, + file: expectedFile, parent: { fullTitle: function () { return expectedClassName; @@ -418,6 +424,8 @@ describe('XUnit reporter', function () { expectedClassName + '" name="' + expectedTitle + + '" file="' + + expectedFile + '" time="1">'; expect(expectedWrite, 'to be', expectedTag); }); @@ -431,6 +439,7 @@ describe('XUnit reporter', function () { return false; }, title: expectedTitle, + file: expectedFile, parent: { fullTitle: function () { return expectedClassName; @@ -447,6 +456,8 @@ describe('XUnit reporter', function () { expectedClassName + '" name="' + expectedTitle + + '" file="' + + expectedFile + '" time="0"/>'; expect(expectedWrite, 'to be', expectedTag); }); From a5b565289b40a839af086b13fb369e04e205ed4b Mon Sep 17 00:00:00 2001 From: Nathan Phillip Brink Date: Tue, 12 Mar 2024 13:18:58 -0400 Subject: [PATCH 03/11] docs: fix documentation concerning glob expansion on UNIX (#4869) --- docs/index.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/index.md b/docs/index.md index b6a70eba7c..a56b64adde 100644 --- a/docs/index.md +++ b/docs/index.md @@ -2257,10 +2257,11 @@ Some shells support recursive matching by using the globstar (`**`) wildcard. Ba $ mocha "./spec/**/*.js" ``` -[You should _always_ quote your globs in npm scripts][article-globbing]. If you -use double quotes, it's the shell on UNIX that will expand the glob. On the -other hand, if you use single quotes, the [`node-glob`][npm-glob] module will -handle its expansion. +You should _always_ quote your globs in npm scripts. If you +use quotes, the [`node-glob`][npm-glob] module will +handle its expansion. For maximum compatibility, +surround the entire expression with double quotes and refrain +from `$`, `"`, `^`, and `\` within your expression. See this [tutorial][gist-globbing-tutorial] on using globs. @@ -2352,7 +2353,6 @@ For a running example of Mocha, view [example/tests.html](example/tests.html). F or the [source](https://github.com/mochajs/mocha/blob/master/lib/mocha.js). [//]: # 'Cross reference section' -[article-globbing]: https://medium.com/@jakubsynowiec/you-should-always-quote-your-globs-in-npm-scripts-621887a2a784 [bash-globbing]: https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html [better-assert]: https://github.com/visionmedia/better-assert [caniuse-notifications]: https://caniuse.com/#feat=notifications From 6f3f45e587a17463b75047631152429fa14b82a3 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Tue, 26 Mar 2024 18:00:32 +0100 Subject: [PATCH 04/11] fix: xunit integration test (#5122) --- test/integration/reporters.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/reporters.spec.js b/test/integration/reporters.spec.js index cdc15b8233..08fa7f85a3 100644 --- a/test/integration/reporters.spec.js +++ b/test/integration/reporters.spec.js @@ -44,8 +44,8 @@ describe('reporters', function () { 'output=' + tmpFile ]; var expectedOutput = [ - ' * Fix minor typo. * Update lib/cli/run.js Do not change the original functionality. Co-authored-by: Pelle Wessman * Check that the toString method is available on the error. * Opting for a simplified solution * Fix tests --------- Co-authored-by: Pelle Wessman --- lib/cli/run.js | 2 +- test/integration/reporters.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cli/run.js b/lib/cli/run.js index fbbe510e94..66c8cbbb66 100644 --- a/lib/cli/run.js +++ b/lib/cli/run.js @@ -369,7 +369,7 @@ exports.handler = async function (argv) { try { await runMocha(mocha, argv); } catch (err) { - console.error('\n' + (err.stack || `Error: ${err.message || err}`)); + console.error('\n Exception during run:', err); process.exit(1); } }; diff --git a/test/integration/reporters.spec.js b/test/integration/reporters.spec.js index 08fa7f85a3..9285dfe80c 100644 --- a/test/integration/reporters.spec.js +++ b/test/integration/reporters.spec.js @@ -211,7 +211,7 @@ describe('reporters', function () { return; } - var pattern = `^Error: invalid or unsupported TAP version: "${invalidTapVersion}"`; + var pattern = `Error: invalid or unsupported TAP version: "${invalidTapVersion}"`; expect(res, 'to satisfy', { code: 1, output: new RegExp(pattern, 'm') From 7a2781c17d4924c620ce5b31c4aab6c88bed72ef Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Tue, 26 Mar 2024 18:18:05 +0100 Subject: [PATCH 06/11] chore: activate dependabot for workflows (#5123) Related to #5055 --- .github/dependabot.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000000..7220d99409 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: 'github-actions' + directory: '/' + schedule: + interval: 'weekly' + groups: + github-actions: + patterns: + - '*' From 7ac67f3735b1ba6b1e1565ab9136d83c50f58abf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 26 Mar 2024 18:27:15 +0100 Subject: [PATCH 07/11] build(deps): bump the github-actions group with 2 updates (#5125) Bumps the github-actions group with 2 updates: [actions/cache](https://github.com/actions/cache) and [buildsville/add-remove-label](https://github.com/buildsville/add-remove-label). Updates `actions/cache` from 3 to 4 - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v3...v4) Updates `buildsville/add-remove-label` from 2.0.0 to 2.0.1 - [Release notes](https://github.com/buildsville/add-remove-label/releases) - [Commits](https://github.com/buildsville/add-remove-label/compare/v2.0.0...v2.0.1) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: buildsville/add-remove-label dependency-type: direct:production update-type: version-update:semver-patch dependency-group: github-actions ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/browser-test.yml | 4 ++-- .github/workflows/mocha.yml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/browser-test.yml b/.github/workflows/browser-test.yml index a037f6cc56..890769437f 100644 --- a/.github/workflows/browser-test.yml +++ b/.github/workflows/browser-test.yml @@ -20,7 +20,7 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} persist-credentials: false - name: 'Cache node_modules' - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: '~/.npm' key: "ubuntu-latest-node-full-lts-${{ hashFiles('**/package-lock.json') }}" @@ -32,7 +32,7 @@ jobs: SAUCE_USERNAME: '${{secrets.SAUCE_USERNAME}}' SAUCE_ACCESS_KEY: '${{secrets.SAUCE_ACCESS_KEY}}' - name: remove 'run-browser-test' label - uses: buildsville/add-remove-label@v2.0.0 + uses: buildsville/add-remove-label@v2.0.1 if: ${{ always() }} with: token: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/mocha.yml b/.github/workflows/mocha.yml index a71d47804e..33e357fd9a 100644 --- a/.github/workflows/mocha.yml +++ b/.github/workflows/mocha.yml @@ -70,7 +70,7 @@ jobs: with: persist-credentials: false - name: 'Cache node_modules' - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: '~/.npm' key: "ubuntu-latest-node-lts-${{ hashFiles('**/package-lock.json') }}" @@ -113,7 +113,7 @@ jobs: run: | echo "dir=$(npm config get cache)" >> $env:GITHUB_OUTPUT - name: 'Cache node_modules' - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ matrix.os == 'ubuntu-latest' && '~/.npm' || steps.npm-cache.outputs.dir }} key: "${{ matrix.os }}-node-v${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}" @@ -152,7 +152,7 @@ jobs: with: persist-credentials: false - name: 'Cache node_modules' - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: '~/.npm' # this key is different than above, since we are running scripts @@ -189,7 +189,7 @@ jobs: with: persist-credentials: false - name: 'Cache node_modules' - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: '~/.npm' # this key is different than above, since we are running scripts From ffd9557ee291047f7beef71a24796ea2da256614 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Tue, 26 Mar 2024 19:10:49 +0100 Subject: [PATCH 08/11] Release v10.4.0 --- AUTHORS | 7 +++++++ CHANGELOG.md | 27 +++++++++++++++++++++++++++ package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/AUTHORS b/AUTHORS index 5c1b272542..17d79bd2be 100644 --- a/AUTHORS +++ b/AUTHORS @@ -547,5 +547,12 @@ Aras Abbasi Spencer <16455389+Spencer-Doak@users.noreply.github.com> Feng Yu Pelle Wessman +Orgad Shaneh +Lucas Lopes +Bryan Mishkin <698306+bmish@users.noreply.github.com> +Ville Lahdenvuo +Nathan Phillip Brink +Ståle Tomten +dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> # Generated by scripts/update-authors.js diff --git a/CHANGELOG.md b/CHANGELOG.md index d6938d051b..62a37eb7a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,32 @@ # Changelog +## 10.4.0 / 2024-03-26 + +### :tada: Enhancements + +- [#4829](https://github.com/mochajs/mocha/pull/4829) feat: include `.cause` stacks in the error stack traces ([**@voxpelli**](https://github.com/voxpelli)) +- [#4985](https://github.com/mochajs/mocha/pull/4985) feat: add file path to xunit reporter ([**@bmish**](https://github.com/bmish)) + +### :bug: Fixes + +- [#5074](https://github.com/mochajs/mocha/pull/5074) fix: harden error handling in `lib/cli/run.js` ([**@stalet**](https://github.com/stalet)) + +### :nut_and_bolt: Other + +- [#5077](https://github.com/mochajs/mocha/pull/5077) chore: add mtfoley/pr-compliance-action ([**@JoshuaKGoldberg**](https://github.com/JoshuaKGoldberg)) +- [#5060](https://github.com/mochajs/mocha/pull/5060) chore: migrate ESLint config to flat config ([**@JoshuaKGoldberg**](https://github.com/JoshuaKGoldberg)) +- [#5095](https://github.com/mochajs/mocha/pull/5095) chore: revert [#5069](https://github.com/mochajs/mocha/pull/5069) to restore Netlify builds ([**@voxpelli**](https://github.com/voxpelli)) +- [#5097](https://github.com/mochajs/mocha/pull/5097) docs: add sponsored to sponsorship link rels ([**@JoshuaKGoldberg**](https://github.com/JoshuaKGoldberg)) +- [#5093](https://github.com/mochajs/mocha/pull/5093) chore: add 'status: in triage' label to issue templates and docs ([**@JoshuaKGoldberg**](https://github.com/JoshuaKGoldberg)) +- [#5083](https://github.com/mochajs/mocha/pull/5083) docs: fix CHANGELOG.md headings to start with a root-level h1 ([**@JoshuaKGoldberg**](https://github.com/JoshuaKGoldberg)) +- [#5100](https://github.com/mochajs/mocha/pull/5100) chore: fix header generation and production build crashes ([**@JoshuaKGoldberg**](https://github.com/JoshuaKGoldberg)) +- [#5104](https://github.com/mochajs/mocha/pull/5104) chore: bump ESLint ecmaVersion to 2020 ([**@JoshuaKGoldberg**](https://github.com/JoshuaKGoldberg)) +- [#5116](https://github.com/mochajs/mocha/pull/5116) fix: eleventy template builds crash with 'unexpected token at ": string, msg..."' ([**@LcsK**](https://github.com/LcsK)) +- [#4869](https://github.com/mochajs/mocha/pull/4869) docs: fix documentation concerning glob expansion on UNIX ([**@binki**](https://github.com/binki)) +- [#5122](https://github.com/mochajs/mocha/pull/5122) test: fix xunit integration test ([**@voxpelli**](https://github.com/voxpelli)) +- [#5123](https://github.com/mochajs/mocha/pull/5123) chore: activate dependabot for workflows ([**@voxpelli**](https://github.com/voxpelli)) +- [#5125](https://github.com/mochajs/mocha/pull/5125) build(deps): bump the github-actions group with 2 updates ([**@dependabot**](https://github.com/dependabot)) + ## 10.3.0 / 2024-02-08 This is a stable release equivalent to [10.30.0-prerelease](#1030-prerelease--2024-01-18). diff --git a/package-lock.json b/package-lock.json index f69412b755..3dad2b0e46 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mocha", - "version": "10.3.0", + "version": "10.4.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mocha", - "version": "10.3.0", + "version": "10.4.0", "license": "MIT", "dependencies": { "ansi-colors": "4.1.1", diff --git a/package.json b/package.json index 1408b8715c..ed5d6ea47e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mocha", - "version": "10.3.0", + "version": "10.4.0", "type": "commonjs", "description": "simple, flexible, fun test framework", "keywords": [ From e263c7a722b8c2fcbe83596836653896a9e0258b Mon Sep 17 00:00:00 2001 From: Sleepy Flower Date: Wed, 27 Mar 2024 08:07:24 -0400 Subject: [PATCH 09/11] feat: use and for browser progress indicator instead of (#5015) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fallback for progress when canvas isn't available * Fix bugs preventing progress text from being updated * Use a different class for progress text fallback * Refactor: replace progress canvas with text * refactor: add progress bar * Refactor: Remove unused progress code * Match progress design hide progress bar and use SVG to recreate the ring bar * Refactor: use css variables for ring size and color values removed more canvas related code removed an em * Mirror styles changes to progress ring renamed ring-whole to ring-flatlight and have ring highlight and flatlight be the inverse of each other fix spelling error with decimalPlaces use getComputedStyle for get the radius of the ring defined in CSS use :is() CSS to simplify CSS code Change stroke thickness math to better match previous look * Trying to match progress canvas look on progress ring --------- Co-authored-by: Josh Goldberg ✨ --- lib/browser/progress.js | 138 ---------------------------------------- lib/reporters/html.js | 49 +++++++------- mocha.css | 71 ++++++++++++++++----- 3 files changed, 81 insertions(+), 177 deletions(-) delete mode 100644 lib/browser/progress.js diff --git a/lib/browser/progress.js b/lib/browser/progress.js deleted file mode 100644 index c82bc0824e..0000000000 --- a/lib/browser/progress.js +++ /dev/null @@ -1,138 +0,0 @@ -'use strict'; - -/** - @module browser/Progress -*/ - -/** - * Expose `Progress`. - */ - -module.exports = Progress; - -/** - * Initialize a new `Progress` indicator. - */ -function Progress() { - this.percent = 0; - this.size(0); - this.fontSize(11); - this.font('helvetica, arial, sans-serif'); -} - -/** - * Set progress size to `size`. - * - * @public - * @param {number} size - * @return {Progress} Progress instance. - */ -Progress.prototype.size = function (size) { - this._size = size; - return this; -}; - -/** - * Set text to `text`. - * - * @public - * @param {string} text - * @return {Progress} Progress instance. - */ -Progress.prototype.text = function (text) { - this._text = text; - return this; -}; - -/** - * Set font size to `size`. - * - * @public - * @param {number} size - * @return {Progress} Progress instance. - */ -Progress.prototype.fontSize = function (size) { - this._fontSize = size; - return this; -}; - -/** - * Set font to `family`. - * - * @param {string} family - * @return {Progress} Progress instance. - */ -Progress.prototype.font = function (family) { - this._font = family; - return this; -}; - -/** - * Update percentage to `n`. - * - * @param {number} n - * @return {Progress} Progress instance. - */ -Progress.prototype.update = function (n) { - this.percent = n; - return this; -}; - -/** - * Draw on `ctx`. - * - * @param {CanvasRenderingContext2d} ctx - * @return {Progress} Progress instance. - */ -Progress.prototype.draw = function (ctx) { - try { - var darkMatcher = window.matchMedia('(prefers-color-scheme: dark)'); - var isDarkMode = !!darkMatcher.matches; - var lightColors = { - outerCircle: '#9f9f9f', - innerCircle: '#eee', - text: '#000' - }; - var darkColors = { - outerCircle: '#888', - innerCircle: '#444', - text: '#fff' - }; - var colors = isDarkMode ? darkColors : lightColors; - - var percent = Math.min(this.percent, 100); - var size = this._size; - var half = size / 2; - var x = half; - var y = half; - var rad = half - 1; - var fontSize = this._fontSize; - - ctx.font = fontSize + 'px ' + this._font; - - var angle = Math.PI * 2 * (percent / 100); - ctx.clearRect(0, 0, size, size); - - // outer circle - ctx.strokeStyle = colors.outerCircle; - ctx.beginPath(); - ctx.arc(x, y, rad, 0, angle, false); - ctx.stroke(); - - // inner circle - ctx.strokeStyle = colors.innerCircle; - ctx.beginPath(); - ctx.arc(x, y, rad - 1, 0, angle, true); - ctx.stroke(); - - // text - var text = this._text || (percent | 0) + '%'; - var w = ctx.measureText(text).width; - - ctx.fillStyle = colors.text; - ctx.fillText(text, x - w / 2 + 1, y + fontSize / 2 - 1); - } catch (ignore) { - // don't fail if we can't render progress - } - return this; -}; diff --git a/lib/reporters/html.js b/lib/reporters/html.js index 034fb07f01..ae4a4546f8 100644 --- a/lib/reporters/html.js +++ b/lib/reporters/html.js @@ -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; @@ -38,7 +37,7 @@ exports = module.exports = HTML; var statsTemplate = '
    ' + - '
  • ' + + '
  • 0%
  • ' + '
  • passes: 0
  • ' + '
  • failures: 0
  • ' + '
  • duration: 0s
  • ' + @@ -68,24 +67,16 @@ 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('
      '); var stack = [report]; - var progress; - var ctx; + var progressText = items[0].getElementsByTagName('div')[0]; + var progressBar = items[0].getElementsByTagName('progress')[0]; + var progressRing = [ + items[0].getElementsByClassName('ring-flatlight')[0], + items[0].getElementsByClassName('ring-highlight')[0]]; + var progressRingRadius = null; // computed CSS unavailable now, so set later 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(); - } - if (!root) { return error('#mocha div missing, add it to your document'); } @@ -115,10 +106,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; @@ -234,8 +221,26 @@ 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); + progressBar.value = percent; + 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 + var decimalPlaces = Math.ceil(Math.log10(runner.total / 100)); + text( + progressText, + percent.toFixed(Math.min(Math.max(decimalPlaces, 0), 100)) + '%' + ); + } + if (progressRing) { + var radius = parseFloat(getComputedStyle(progressRing[0]).getPropertyValue('r')); + var wholeArc = Math.PI * 2 * radius; + var highlightArc = percent * (wholeArc / 100); + // The progress ring is in 2 parts, the flatlight color and highlight color. + // Rendering both on top of the other, seems to make a 3rd color on the edges. + // To create 1 whole ring with 2 colors, both parts are inverse of the other. + progressRing[0].style['stroke-dasharray'] = `0,${highlightArc}px,${wholeArc}px`; + progressRing[1].style['stroke-dasharray'] = `${highlightArc}px,${wholeArc}px`; } // update stats diff --git a/mocha.css b/mocha.css index b4d7e5b207..1e0d22249a 100644 --- a/mocha.css +++ b/mocha.css @@ -22,6 +22,9 @@ --mocha-stats-color: #888; --mocha-stats-em-color: #000; --mocha-stats-hover-color: #eee; + --mocha-progress-ring-color: #eee; + --mocha-progress-ring-highlight-color: #9f9f9f; + --mocha-progress-text-color: #000; --mocha-error-color: #c00; --mocha-code-comment: #ddd; @@ -54,6 +57,9 @@ --mocha-stats-color: #aaa; --mocha-stats-em-color: #fff; --mocha-stats-hover-color: #444; + --mocha-progress-ring-color: #444; + --mocha-progress-ring-highlight-color: #888; + --mocha-progress-text-color: #fff; --mocha-error-color: #f44; --mocha-code-comment: #ddd; @@ -325,6 +331,10 @@ body { } #mocha-stats { + --ring-container-size: 40px; + --ring-size: 39px; + --ring-radius: calc(var(--ring-size) / 2); + position: fixed; top: 15px; right: 10px; @@ -334,20 +344,52 @@ body { z-index: 1; } -#mocha-stats .progress { +#mocha-stats .progress-contain { float: right; - padding-top: 0; + padding: 0; +} + +#mocha-stats :is(.progress-element, .progress-text) { + width: var(--ring-container-size); + display: block; + top: 12px; + position: absolute; +} + +#mocha-stats .progress-element { + visibility: hidden; + height: calc(var(--ring-container-size) / 2); +} + +#mocha-stats .progress-text { + text-align: center; + text-overflow: clip; + overflow: hidden; + color: var(--mocha-stats-em-color); + font-size: 11px; +} - /** - * Set safe initial values, so mochas .progress does not inherit these - * properties from Bootstrap .progress (which causes .progress height to - * equal line height set in Bootstrap). - */ - height: auto; - -webkit-box-shadow: none; - -moz-box-shadow: none; - box-shadow: none; - background-color: initial; +#mocha-stats .progress-ring { + width: var(--ring-container-size); + height: var(--ring-container-size); +} + +#mocha-stats :is(.ring-flatlight, .ring-highlight) { + --stroke-thickness: 1.65px; + --center: calc(var(--ring-container-size) / 2); + cx: var(--center); + cy: var(--center); + r: calc(var(--ring-radius) - calc(var(--stroke-thickness) / 2)); + fill: hsla(0, 0%, 0%, 0); + stroke-width: var(--stroke-thickness); +} + +#mocha-stats .ring-flatlight { + stroke: var(--mocha-progress-ring-color); +} + +#mocha-stats .ring-highlight { + stroke: var(--mocha-progress-ring-highlight-color); } #mocha-stats em { @@ -370,11 +412,6 @@ body { padding-top: 11px; } -#mocha-stats canvas { - width: 40px; - height: 40px; -} - #mocha code .comment { color: var(--mocha-code-comment); } #mocha code .init { color: var(--mocha-code-init); } #mocha code .string { color: var(--mocha-code-string); } From 99601da68d59572b6aa931e9416002bcb5b3e19d Mon Sep 17 00:00:00 2001 From: StevenMia <166844090+StevenMia@users.noreply.github.com> Date: Tue, 23 Apr 2024 23:07:43 +0800 Subject: [PATCH 10/11] chore: fix some typos in comments (#5135) Signed-off-by: StevenMia --- docs/changelogs/CHANGELOG_V3_older.md | 2 +- docs/index.md | 2 +- lib/nodejs/reporters/parallel-buffered.js | 2 +- lib/nodejs/serializer.js | 2 +- package-scripts.js | 2 +- test/integration/README.md | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/changelogs/CHANGELOG_V3_older.md b/docs/changelogs/CHANGELOG_V3_older.md index d9ca257f05..a3b6dfd503 100644 --- a/docs/changelogs/CHANGELOG_V3_older.md +++ b/docs/changelogs/CHANGELOG_V3_older.md @@ -789,7 +789,7 @@ Thanks to everyone who contributed, and our fabulous [sponsors and backers](http # 1.10.0 / 2013-05-21 -- add add better globbing support for windows via `glob` module +- add better globbing support for windows via `glob` module - add support to pass through flags such as --debug-brk=1234. Closes [#852](https://github.com/mochajs/mocha/issues/852) - add test.only, test.skip to qunit interface - change to always use word-based diffs for now. Closes [#733](https://github.com/mochajs/mocha/issues/733) diff --git a/docs/index.md b/docs/index.md index a56b64adde..997a90e553 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1458,7 +1458,7 @@ Available root hooks and their behavior: > _Tip: If you need to ensure code runs once and only once in any mode, use [global fixtures](#global-fixtures)._ -As with other hooks, `this` refers to to the current context object: +As with other hooks, `this` refers to the current context object: ```js // test/hooks.mjs diff --git a/lib/nodejs/reporters/parallel-buffered.js b/lib/nodejs/reporters/parallel-buffered.js index 840d718ed8..b697312e62 100644 --- a/lib/nodejs/reporters/parallel-buffered.js +++ b/lib/nodejs/reporters/parallel-buffered.js @@ -54,7 +54,7 @@ const ONCE_EVENT_NAMES = [EVENT_DELAY_BEGIN, EVENT_DELAY_END]; /** * The `ParallelBuffered` reporter is used by each worker process in "parallel" - * mode, by default. Instead of reporting to to `STDOUT`, etc., it retains a + * mode, by default. Instead of reporting to `STDOUT`, etc., it retains a * list of events it receives and hands these off to the callback passed into * {@link Mocha#run}. That callback will then return the data to the main * process. diff --git a/lib/nodejs/serializer.js b/lib/nodejs/serializer.js index b25c493bf0..cfdd3a69fd 100644 --- a/lib/nodejs/serializer.js +++ b/lib/nodejs/serializer.js @@ -117,7 +117,7 @@ class SerializableEvent { /** * Constructs a `SerializableEvent`, throwing if we receive unexpected data. * - * Practically, events emitted from `Runner` have a minumum of zero (0) + * Practically, events emitted from `Runner` have a minimum of zero (0) * arguments-- (for example, {@link Runnable.constants.EVENT_RUN_BEGIN}) and a * maximum of two (2) (for example, * {@link Runnable.constants.EVENT_TEST_FAIL}, where the second argument is an diff --git a/package-scripts.js b/package-scripts.js index 1e4c072973..3ffd751811 100644 --- a/package-scripts.js +++ b/package-scripts.js @@ -110,7 +110,7 @@ module.exports = { }, qunit: { script: test('qunit', '--ui qunit test/interfaces/qunit.spec'), - description: 'Run Node.js QUnit interace tests', + description: 'Run Node.js QUnit interface tests', hiddenFromHelp: true }, exports: { diff --git a/test/integration/README.md b/test/integration/README.md index 5b2e84d750..dd7fa87f77 100644 --- a/test/integration/README.md +++ b/test/integration/README.md @@ -31,7 +31,7 @@ The `helpers.js` module contains many functions to handle the common cases of sp By default, all of these helpers run with the following options: - `--no-color`: it's easier to make assertions about output w/o having to deal w/ ANSI escape codes -- `--no-bail`: overrides a configuration file w/ `bail: true`; providing `--bail` to the arguments list will supress this (useful when testing `--bail`!) +- `--no-bail`: overrides a configuration file w/ `bail: true`; providing `--bail` to the arguments list will suppress this (useful when testing `--bail`!) - `--no-parallel`: overrides a configuration file w/ `parallel: true`; providing `--parallel` to the arguments list will suppress this ## Environment Variables Which Do Stuff From 472a8be14f9b578c8b1ef3e6ae05d06fc2d9891b Mon Sep 17 00:00:00 2001 From: Simon Hanna <33220646+simhnna@users.noreply.github.com> Date: Fri, 24 May 2024 15:01:48 +0200 Subject: [PATCH 11/11] chore: allow using any 3.x chokidar dependencies (#5143) --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3dad2b0e46..1c22fd5d1d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "ansi-colors": "4.1.1", "browser-stdout": "1.3.1", - "chokidar": "3.5.3", + "chokidar": "^3.5.3", "debug": "4.3.4", "diff": "5.0.0", "escape-string-regexp": "4.0.0", diff --git a/package.json b/package.json index ed5d6ea47e..417fe13452 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "dependencies": { "ansi-colors": "4.1.1", "browser-stdout": "1.3.1", - "chokidar": "3.5.3", + "chokidar": "^3.5.3", "debug": "4.3.4", "diff": "5.0.0", "escape-string-regexp": "4.0.0",