Skip to content

Commit

Permalink
Merge branch 'main' into feat/suite/allow-calling-hook-methods
Browse files Browse the repository at this point in the history
  • Loading branch information
perrin4869 authored Oct 30, 2024
2 parents 2b4b3c1 + f054acc commit 060c86d
Show file tree
Hide file tree
Showing 16 changed files with 248 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/release-please/manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{".":"10.7.3"}
{".":"10.8.1"}
2 changes: 1 addition & 1 deletion .github/workflows/nightly-site-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Webhook Action
uses: joelwmale/webhook-action@448a17bf857ead98546cfbdbe3b9d4cf979dda95
uses: joelwmale/webhook-action@cc1a66f987e1591785273fd6f9d2f7a9d8d7c9cd
env:
data: ''
WEBHOOK_URL: ${{ secrets.NETLIFY_NIGHTLY_DEPLOY_URL }}
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
# Changelog

## [10.8.1](https://github.com/mochajs/mocha/compare/v10.8.0...v10.8.1) (2024-10-29)


### 🩹 Fixes

* handle case of invalid package.json with no explicit config ([#5198](https://github.com/mochajs/mocha/issues/5198)) ([f72bc17](https://github.com/mochajs/mocha/commit/f72bc17cb44164bcfff7abc83d0d37d99a061104))
* Typos on mochajs.org ([#5237](https://github.com/mochajs/mocha/issues/5237)) ([d8ca270](https://github.com/mochajs/mocha/commit/d8ca270a960554c9d5c5fbf264e89d668d01ff0d))
* use accurate test links in HTML reporter ([#5228](https://github.com/mochajs/mocha/issues/5228)) ([68803b6](https://github.com/mochajs/mocha/commit/68803b685d55dcccc51fa6ccfd27701cda4e26ed))

## [10.8.0](https://github.com/mochajs/mocha/compare/v10.7.3...v10.8.0) (2024-10-29)


### 🌟 Features

* highlight browser failures ([#5222](https://github.com/mochajs/mocha/issues/5222)) ([8ff4845](https://github.com/mochajs/mocha/commit/8ff48453a8b12d9cacf56b0c0c544c8256af64c7))


### 🩹 Fixes

* remove `:is()` from `mocha.css` to support older browsers ([#5225](https://github.com/mochajs/mocha/issues/5225)) ([#5227](https://github.com/mochajs/mocha/issues/5227)) ([0a24b58](https://github.com/mochajs/mocha/commit/0a24b58477ea8ad146afc798930800b02c08790a))


### 📚 Documentation

* add `SECURITY.md` pointing to Tidelift ([#5210](https://github.com/mochajs/mocha/issues/5210)) ([bd7e63a](https://github.com/mochajs/mocha/commit/bd7e63a1f6d98535ce1ed1ecdb57b3e4db8a33c5))
* adopt Collective Funds Guidelines 0.1 ([#5199](https://github.com/mochajs/mocha/issues/5199)) ([2b03d86](https://github.com/mochajs/mocha/commit/2b03d865eec63d627ff229e07d777f25061260d4))
* update README, LICENSE and fix outdated ([#5197](https://github.com/mochajs/mocha/issues/5197)) ([1203e0e](https://github.com/mochajs/mocha/commit/1203e0ed739bbbf12166078738357fdb29a8c000))


### 🧹 Chores

* fix npm scripts on windows ([#5219](https://github.com/mochajs/mocha/issues/5219)) ([1173da0](https://github.com/mochajs/mocha/commit/1173da0bf614e8d2a826687802ee8cbe8671ccf1))
* remove trailing whitespace in SECURITY.md ([7563e59](https://github.com/mochajs/mocha/commit/7563e59ae3c78ada305d26eadb86998ab54342da))

## [10.7.3](https://github.com/mochajs/mocha/compare/v10.7.2...v10.7.3) (2024-08-09)


Expand Down
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ Cause Mocha to only run tests matching the given `regexp`, which is internally c
Suppose, for example, you have "api" related tests, as well as "app" related tests, as shown in the following snippet; One could use `--grep api` or `--grep app` to run one or the other. The same goes for any other part of a suite or test-case title, `--grep users` would be valid as well, or even `--grep GET`.

And another option with double quotes: `--grep "groupA|groupB"`.<br>
And for more complex criterias: `--grep "/get/i"`. Some shells as e.g. Git-Bash-for-Windows may require: `--grep "'/get/i'"`. Using flags other than the `ignoreCase /i` (especially `/g` and `/y`) may lead to unpredictable results.
And for more complex criteria: `--grep "/get/i"`. Some shells as e.g. Git-Bash-for-Windows may require: `--grep "'/get/i'"`. Using flags other than the `ignoreCase /i` (especially `/g` and `/y`) may lead to unpredictable results.

```js
describe('api', function () {
Expand Down Expand Up @@ -2259,7 +2259,7 @@ Mocha will also _merge_ any options found in `package.json` into its run-time co
1. Configuration file (`.mocharc.js`, `.mocharc.yml`, etc.)
1. `mocha` property of `package.json`

Options which can safely be repeated (e.g., `--require`) will be _concatenated_, with higher-priorty configuration sources appearing earlier in the list. For example, a `.mocharc.json` containing `"require": "bar"`, coupled with execution of `mocha --require foo`, would cause Mocha to require `foo`, then `bar`, in that order.
Options which can safely be repeated (e.g., `--require`) will be _concatenated_, with higher-priority configuration sources appearing earlier in the list. For example, a `.mocharc.json` containing `"require": "bar"`, coupled with execution of `mocha --require foo`, would cause Mocha to require `foo`, then `bar`, in that order.

### Extending Configuration

Expand Down Expand Up @@ -2445,7 +2445,7 @@ or the [source](https://github.com/mochajs/mocha/blob/main/lib/mocha.js).
[qunit]: https://qunitjs.com/
[selenium-webdriver-testing]: https://github.com/SeleniumHQ/selenium/blob/c10e8a955883f004452cdde18096d70738397788/javascript/node/selenium-webdriver/testing/index.js
[should.js]: https://github.com/shouldjs/should.js
[superagent-docs-test]: https://visionmedia.github.io/superagent/docs/test.html
[superagent-docs-test]: https://ladjs.github.io/superagent/docs/test.html
[superagent-makefile]: https://github.com/visionmedia/superagent/blob/master/Makefile
[test-anything-protocol]: https://en.wikipedia.org/wiki/Test_Anything_Protocol
[textmate-mocha]: https://github.com/mochajs/mocha.tmbundle
Expand Down
30 changes: 22 additions & 8 deletions lib/cli/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,36 @@ const loadPkgRc = (args = {}) => {
result = {};
const filepath = args.package || findUp.sync(mocharc.package);
if (filepath) {
let configData;
try {
const pkg = JSON.parse(fs.readFileSync(filepath, 'utf8'));
configData = fs.readFileSync(filepath, 'utf8');
} catch (err) {
// If `args.package` was explicitly specified, throw an error
if (filepath == args.package) {
throw createUnparsableFileError(
`Unable to read ${filepath}: ${err}`,
filepath
);
} else {
debug('failed to read default package.json at %s; ignoring',
filepath);
return result;
}
}
try {
const pkg = JSON.parse(configData);
if (pkg.mocha) {
debug('`mocha` prop of package.json parsed: %O', pkg.mocha);
result = pkg.mocha;
} else {
debug('no config found in %s', filepath);
}
} catch (err) {
if (args.package) {
throw createUnparsableFileError(
`Unable to read/parse ${filepath}: ${err}`,
filepath
);
}
debug('failed to read default package.json at %s; ignoring', filepath);
// If JSON failed to parse, throw an error.
throw createUnparsableFileError(
`Unable to parse ${filepath}: ${err}`,
filepath
);
}
}
return result;
Expand Down
8 changes: 7 additions & 1 deletion lib/nodejs/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,15 @@ class SerializableEvent {
breakCircularDeps(result.error);

const pairs = Object.keys(result).map(key => [result, key]);

const seenPairs = new Set();
let pair;

while ((pair = pairs.shift())) {
if (seenPairs.has(pair[1])) {
continue;
}

seenPairs.add(pair[1]);
SerializableEvent._serialize(pairs, ...pair);
}

Expand Down
61 changes: 43 additions & 18 deletions lib/reporters/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ var Date = global.Date;
exports = module.exports = HTML;

/**
* Stats template.
* Stats template: Result, progress, passes, failures, and duration.
*/

var statsTemplate =
'<ul id="mocha-stats">' +
'<li class="result"></li>' +
'<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>' +
'<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>' +
Expand All @@ -62,18 +63,35 @@ function HTML(runner, options) {
var stats = this.stats;
var stat = fragment(statsTemplate);
var items = stat.getElementsByTagName('li');
var passes = items[1].getElementsByTagName('em')[0];
var passesLink = items[1].getElementsByTagName('a')[0];
var failures = items[2].getElementsByTagName('em')[0];
var failuresLink = items[2].getElementsByTagName('a')[0];
var duration = items[3].getElementsByTagName('em')[0];
const resultIndex = 0;
const progressIndex = 1;
const passesIndex = 2;
const failuresIndex = 3;
const durationIndex = 4;
/** Stat item containing the root suite pass or fail indicator (hasFailures ? '✖' : '✓') */
var resultIndicator = items[resultIndex];
/** Passes text and count */
const passesStat = items[passesIndex];
/** Stat item containing the pass count (not the word, just the number) */
const passesCount = passesStat.getElementsByTagName('em')[0];
/** Stat item linking to filter to show only passing tests */
const passesLink = passesStat.getElementsByTagName('a')[0];
/** Failures text and count */
const failuresStat = items[failuresIndex];
/** Stat item containing the failure count (not the word, just the number) */
const failuresCount = failuresStat.getElementsByTagName('em')[0];
/** Stat item linking to filter to show only failing tests */
const failuresLink = failuresStat.getElementsByTagName('a')[0];
/** Stat item linking to the duration time (not the word or unit, just the number) */
var duration = items[durationIndex].getElementsByTagName('em')[0];
var report = fragment('<ul id="mocha-report"></ul>');
var stack = [report];
var progressText = items[0].getElementsByTagName('div')[0];
var progressBar = items[0].getElementsByTagName('progress')[0];
var progressText = items[progressIndex].getElementsByTagName('div')[0];
var progressBar = items[progressIndex].getElementsByTagName('progress')[0];
var progressRing = [
items[0].getElementsByClassName('ring-flatlight')[0],
items[0].getElementsByClassName('ring-highlight')[0]];
items[progressIndex].getElementsByClassName('ring-flatlight')[0],
items[progressIndex].getElementsByClassName('ring-highlight')[0]
];
var progressRingRadius = null; // computed CSS unavailable now, so set later
var root = document.getElementById('mocha');

Expand Down Expand Up @@ -127,6 +145,10 @@ function HTML(runner, options) {

runner.on(EVENT_SUITE_END, function (suite) {
if (suite.root) {
if (stats.failures === 0) {
text(resultIndicator, '✓');
stat.className += ' pass';
}
updateStats();
return;
}
Expand All @@ -147,6 +169,10 @@ function HTML(runner, options) {
});

runner.on(EVENT_TEST_FAIL, function (test) {
// Update stat items
text(resultIndicator, '✖');
stat.className += ' fail';

var el = fragment(
'<li class="test fail"><h2>%e <a href="%e" class="replay">' +
playIcon +
Expand Down Expand Up @@ -219,7 +245,6 @@ function HTML(runner, options) {
}

function updateStats() {
// TODO: add to stats
var percent = ((stats.tests / runner.total) * 100) | 0;
progressBar.value = percent;
if (progressText) {
Expand All @@ -245,8 +270,8 @@ function HTML(runner, options) {

// update stats
var ms = new Date() - stats.start;
text(passes, stats.passes);
text(failures, stats.failures);
text(passesCount, stats.passes);
text(failuresCount, stats.failures);
text(duration, (ms / 1000).toFixed(2));
}
}
Expand All @@ -260,16 +285,16 @@ function HTML(runner, options) {
function makeUrl(s) {
var search = window.location.search;

// Remove previous grep query parameter if present
// Remove previous {grep, fgrep, invert} query parameters if present
if (search) {
search = search.replace(/[?&]grep=[^&\s]*/g, '').replace(/^&/, '?');
search = search.replace(/[?&](?:f?grep|invert)=[^&\s]*/g, '').replace(/^&/, '?');
}

return (
window.location.pathname +
(search ? search + '&' : '?') +
'grep=' +
encodeURIComponent(escapeRe(s))
encodeURIComponent(s)
);
}

Expand All @@ -279,7 +304,7 @@ function makeUrl(s) {
* @param {Object} [suite]
*/
HTML.prototype.suiteURL = function (suite) {
return makeUrl(suite.fullTitle());
return makeUrl('^' + escapeRe(suite.fullTitle()) + ' ');
};

/**
Expand All @@ -288,7 +313,7 @@ HTML.prototype.suiteURL = function (suite) {
* @param {Object} [test]
*/
HTML.prototype.testURL = function (test) {
return makeUrl(test.fullTitle());
return makeUrl('^' + escapeRe(test.fullTitle()) + '$');
};

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,9 @@ exports.breakCircularDeps = inputObj => {

seen.add(obj);
for (const k in obj) {
if (Object.prototype.hasOwnProperty.call(obj, k)) {
const descriptor = Object.getOwnPropertyDescriptor(obj, k);

if (descriptor && descriptor.writable) {
obj[k] = _breakCircularDeps(obj[k], k);
}
}
Expand Down
58 changes: 41 additions & 17 deletions mocha.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
:root {
--mocha-color: #000;
--mocha-bg-color: #fff;
--mocha-pass-icon-color: #00d6b2;
--mocha-pass-color: #fff;
--mocha-pass-shadow-color: rgba(0,0,0,.2);
--mocha-pass-mediump-color: #c09853;
--mocha-pass-slow-color: #b94a48;
--mocha-test-pass-color: #007f6a;
--mocha-test-pass-duration-color: #fff;
--mocha-test-pass-shadow-color: rgba(0,0,0, 0.2);
--mocha-test-pass-mediump-color: #c09853;
--mocha-test-pass-slow-color: #b94a48;
--mocha-test-pending-color: #0b97c4;
--mocha-test-pending-icon-color: #0b97c4;
--mocha-test-fail-color: #c00;
Expand Down Expand Up @@ -38,11 +38,11 @@
:root {
--mocha-color: #fff;
--mocha-bg-color: #222;
--mocha-pass-icon-color: #00d6b2;
--mocha-pass-color: #222;
--mocha-pass-shadow-color: rgba(255,255,255,.2);
--mocha-pass-mediump-color: #f1be67;
--mocha-pass-slow-color: #f49896;
--mocha-test-pass-color: #00d6b2;
--mocha-test-pass-duration-color: #222;
--mocha-test-pass-shadow-color: rgba(255, 255, 255, 0.2);
--mocha-test-pass-mediump-color: #f1be67;
--mocha-test-pass-slow-color: #f49896;
--mocha-test-pending-color: #0b97c4;
--mocha-test-pending-icon-color: #0b97c4;
--mocha-test-fail-color: #f44;
Expand Down Expand Up @@ -141,11 +141,11 @@ body {
}

#mocha .test.pass.medium .duration {
background: var(--mocha-pass-mediump-color);
background: var(--mocha-test-pass-mediump-color);
}

#mocha .test.pass.slow .duration {
background: var(--mocha-pass-slow-color);
background: var(--mocha-test-pass-slow-color);
}

#mocha .test.pass::before {
Expand All @@ -154,17 +154,17 @@ body {
display: block;
float: left;
margin-right: 5px;
color: var(--mocha-pass-icon-color);
color: var(--mocha-test-pass-color);
}

#mocha .test.pass .duration {
font-size: 9px;
margin-left: 5px;
padding: 2px 5px;
color: var(--mocha-pass-color);
-webkit-box-shadow: inset 0 1px 1px var(--mocha-pass-shadow-color);
-moz-box-shadow: inset 0 1px 1px var(--mocha-pass-shadow-color);
box-shadow: inset 0 1px 1px var(--mocha-pass-shadow-color);
color: var(--mocha-test-pass-duration-color);
-webkit-box-shadow: inset 0 1px 1px var(--mocha-test-pass-shadow-color);
-moz-box-shadow: inset 0 1px 1px var(--mocha-test-pass-shadow-color);
box-shadow: inset 0 1px 1px var(--mocha-test-pass-shadow-color);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-ms-border-radius: 5px;
Expand Down Expand Up @@ -344,6 +344,30 @@ body {
z-index: 1;
}

#mocha-stats.fail li.result {
color: var(--mocha-test-fail-color);
}

#mocha-stats.fail li.failures {
color: var(--mocha-test-fail-color);
}

#mocha-stats.fail li.failures em {
color: var(--mocha-test-fail-color);
}

#mocha-stats.pass li.result {
color: var(--mocha-test-pass-color);
}

#mocha-stats.pass li.passes {
color: var(--mocha-test-pass-color);
}

#mocha-stats.pass li.passes em {
color: var(--mocha-test-pass-color);
}

#mocha-stats .progress-contain {
float: right;
padding: 0;
Expand Down
Loading

0 comments on commit 060c86d

Please sign in to comment.