Skip to content

Commit

Permalink
Merge branch 'master' into issue/4047
Browse files Browse the repository at this point in the history
  • Loading branch information
khoaHyh committed Mar 24, 2024
2 parents f8aedff + a5b5652 commit a6bdef4
Show file tree
Hide file tree
Showing 18 changed files with 456 additions and 376 deletions.
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ Then:

### 🎋 Initial Creation

1. Make sure the issue is labeled with [`status: accepting prs`](https://github.com/mochajs/mocha/issues?q=is%3Aissue+is%3Aopen+label%3A%22status%3A+accepting+prs%22)
1. Create a new branch in your working copy.
Give your branch a descriptive name, such as `issue/12345`: `git checkout -b issue/12345`.
1. Make your changes and add them via `git add`.
- Your changes will likely be somewhere in `lib/`, `bin/` or `browser-entry.js` (if your changes are browser-specific).
- Your changes will likely be somewhere in `lib/`, `bin/`, or (if your changes are browser-specific) `browser-entry.js`.
- Unit and/or integration **tests are required** for any code change.
These live in `test/`.
- **Do not modify** the root `mocha.js` file directly; it is automatically generated.
Expand Down
5 changes: 3 additions & 2 deletions .github/ISSUE_TEMPLATE/01-bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ body:
type: textarea
description: Report a bug trying to run the code
labels:
- "type: bug"
- 'status: in triage'
- 'type: bug'
name: 🐛 Bug
title: "🐛 Bug: <short description of the bug>"
title: '🐛 Bug: <short description of the bug>'
5 changes: 3 additions & 2 deletions .github/ISSUE_TEMPLATE/02-documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ body:
type: textarea
description: Report a typo or missing area of documentation
labels:
- "area: documentation"
- 'area: documentation'
- 'status: in triage'
name: 📝 Docs
title: "📝 Docs: <short description of the request>"
title: '📝 Docs: <short description of the request>'
5 changes: 3 additions & 2 deletions .github/ISSUE_TEMPLATE/03-feature-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ body:
type: textarea
description: Request that a new feature be added or an existing feature improved
labels:
- "type: feature"
- 'status: in triage'
- 'type: feature'
name: 🚀 Feature
title: "🚀 Feature: <short description of the feature>"
title: '🚀 Feature: <short description of the feature>'
5 changes: 3 additions & 2 deletions .github/ISSUE_TEMPLATE/04-repository-tooling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ body:
type: textarea
description: Report a bug or request an enhancement in the Mocha repository's internal tooling
labels:
- "area: repository tooling"
- 'area: repository tooling'
- 'status: in triage'
name: 🛠 Repository Tooling
title: "🛠 Repo: <short description of the change>"
title: '🛠 Repo: <short description of the change>'
400 changes: 201 additions & 199 deletions CHANGELOG.md

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ For all issues, apply the following labels based on which area(s) the issue pert
- `area: async`: Issues around Mocha's asynchronous usage
- `area: browser`: Issues unique to a browser environment
- `area: parallel`: Issues around Mocha's parallel mode
- `area: qa`: Issues around Mocha's own test suite
- `area: reporter`: Usually concerning Mocha's output
- `area: repository tooling`: Issues around Mocha's CI, own test suite, or other internal tooling
- `area: security`: Involving vulnerabilities, actual or potential
- `area: windows`: Windows-specific issues, particularly around path discrepancies

Expand All @@ -221,13 +221,14 @@ Additionally:
- `good first issue`: If the implementation is likely doable by someone who's never contributed to Mocha (or potentially any other open source project) before
- `status: duplicate`: If an equivalent issue was already filed, add this label, close as not planned, and comment with something like `duplicate of #<other-issue-number>`
- `status: in discussion`: Add this whenever the issue is blocked on community input and/or deeper discussions
- `status: in triage`: Added on new issues; re-add this whenever the issue is awaiting maintainer attention
- `status: waiting for author`: Add this whenever the issue is blocked on something from the author

### 🐛 Bugs

Bug reports should include a way to reproduce the issue that someone who is not deeply familiar with Mocha can work with locally.

Depending on that reproduction, add the following label(s) in addition to the auto-added `type: bug`:
Depending on that reproduction, remove `status: in triage` and add the following label(s) in addition to the auto-added `type: bug`:

- If the bug is valid and reproduction works: add `status: accepting prs`
- If the bug might be valid but the reproduction isn't workable:
Expand All @@ -244,14 +245,14 @@ Depending on that reproduction, add the following label(s) in addition to the au

Documentation reports should clearly indicate a gap or problem that should be addressed in documentation.
Triage documentation issues similar to bugs and/or feature requests - documentation is its own form of product area.
Keep the auto-added `area: documentation` label.
Remove `status: in triage` and keep the auto-added `area: documentation` label.

### 🚀 Features

Feature requests should include a compelling reason why we should spend the maintenance time on the feature.
Given that Mocha is prioritizing stability over growth, this can be a high bar.

Depending on the reasoning, add the following label(s) in addition to the auto-added `type: feature`:
Depending on the reasoning, remove `status: in triage` and add the following label(s) in addition to the auto-added `type: feature`:

- If the reasoning is valid and seems worth the maintenance cost: add `status: accepting prs`
- If the reasoning is unclear:
Expand All @@ -268,12 +269,12 @@ Depending on the reasoning, add the following label(s) in addition to the auto-a

Issues filed about improvements to Mocha's internal development processes.
These can be more informally discussed by maintainers.
Keep the auto-added `area: repository tooling`.
Remove `status: in triage` and keep the auto-added `area: repository tooling`.

### ❓ Questions

Our issue tracker is not the right place to ask questions.
If an issue is filed that seems like it's more of a question, add the `type: question` label, politely direct the user to the [❓ Got a Question?](./.github/CONTRIBUTING.md#❓-got-a-question) section, and close the issue as not planned.
If an issue is filed that seems like it's more of a question, remove `status: in triage`, add the `type: question` label, politely direct the user to the [❓ Got a Question?](./.github/CONTRIBUTING.md#❓-got-a-question) section, and close the issue as not planned.

If it's _not_ a Mocha problem (people tend not to believe this), you may want to show a counter-example.
It's often helpful to direct the issue author to the responsible project, if you can determine what that is.
Expand Down Expand Up @@ -405,7 +406,6 @@ _It's easier to release often._
1. Back in your working copy, run `npm publish`.
_If you're doing a prerelease, ensure that you use `--tag=next`._
1. Announce the update on Twitter or just tell your dog or something.
New releases will be automatically tweeted by [@b0neskull](https://twitter.com/b0neskull) via a feed subscription to Mocha's "releases" page on GitHub.

_Note: there are too many steps above._

Expand Down
4 changes: 2 additions & 2 deletions docs/_includes/supporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Use Mocha at Work? Ask your manager or marketing team if they'd help [support](h
{%- for supporter in supporters.sponsors -%}
<li>
{%- if supporter.website -%}
<a href="{{ supporter.website }}" target="_blank" rel="noopener">
<a href="{{ supporter.website }}" target="_blank" rel="noopener sponsored">
{%- endif -%}
<div class="sponsor" title="{{ supporter.name }}" style="width: {{ supporter.dimensions.width }}px; background-image: url(/images/supporters/{{ supporter.id }}.png?sprite=sponsors)"></div>
{%- if supporter.website -%}
Expand All @@ -24,7 +24,7 @@ Find Mocha helpful? Become a [backer](https://opencollective.com/mochajs#support
{%- for supporter in supporters.backers -%}
<li>
{%- if supporter.website -%}
<a href="{{ supporter.website }}" target="_blank" rel="noopener">
<a href="{{ supporter.website }}" target="_blank" rel="noopener sponsored">
{%- endif -%}
<div class="backer backer-{{ forloop.index }}" title="{{ supporter.name }}" style="background-image: url(/images/supporters/{{ supporter.id }}.png?sprite=backers)"></div>
{%- if supporter.website -%}
Expand Down
10 changes: 5 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = [
{
...js.configs.recommended,
languageOptions: {
ecmaVersion: 2018,
ecmaVersion: 2020,
globals: {
...globals.browser,
...globals.node
Expand Down
79 changes: 60 additions & 19 deletions lib/reporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,56 @@ var generateDiff = (exports.generateDiff = function (actual, expected) {
}
});

/**
* Traverses err.cause and returns all stack traces
*
* @private
* @param {Error} err
* @param {Set<Error>} [seen]
* @return {FullErrorStack}
*/
var getFullErrorStack = function (err, seen) {
if (seen && seen.has(err)) {
return { message: '', msg: '<circular>', stack: '' };
}

var message;

if (typeof err.inspect === 'function') {
message = err.inspect() + '';
} else if (err.message && typeof err.message.toString === 'function') {
message = err.message + '';
} else {
message = '';
}

var msg;
var stack = err.stack || message;
var index = message ? stack.indexOf(message) : -1;

if (index === -1) {
msg = message;
} else {
index += message.length;
msg = stack.slice(0, index);
// remove msg from stack
stack = stack.slice(index + 1);

if (err.cause) {
seen = seen || new Set();
seen.add(err);
const causeStack = getFullErrorStack(err.cause, seen)
stack += '\n Caused by: ' + causeStack.msg + (causeStack.stack ? '\n' + causeStack.stack : '');
}
}

return {
message,
msg,
stack
};
};

/**
* Outputs the given `failures` as a list.
*
Expand All @@ -241,7 +291,6 @@ exports.list = function (failures) {
color('error stack', '\n%s\n');

// msg
var msg;
var err;
if (test.err && test.err.multiple) {
if (multipleTest !== test) {
Expand All @@ -252,25 +301,8 @@ exports.list = function (failures) {
} else {
err = test.err;
}
var message;
if (typeof err.inspect === 'function') {
message = err.inspect() + '';
} else if (err.message && typeof err.message.toString === 'function') {
message = err.message + '';
} else {
message = '';
}
var stack = err.stack || message;
var index = message ? stack.indexOf(message) : -1;

if (index === -1) {
msg = message;
} else {
index += message.length;
msg = stack.slice(0, index);
// remove msg from stack
stack = stack.slice(index + 1);
}
var { message, msg, stack } = getFullErrorStack(err);

// uncaught
if (err.uncaught) {
Expand Down Expand Up @@ -548,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
*/
1 change: 1 addition & 0 deletions lib/reporters/xunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
21 changes: 16 additions & 5 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,22 @@ Runner.prototype.fail = function (test, err, force) {
err = thrown2Error(err);
}

try {
err.stack =
this.fullStackTrace || !err.stack ? err.stack : stackFilter(err.stack);
} catch (ignore) {
// some environments do not take kindly to monkeying with the stack
// Filter the stack traces
if (!this.fullStackTrace) {
const alreadyFiltered = new Set();
let currentErr = err;

while (currentErr && currentErr.stack && !alreadyFiltered.has(currentErr)) {
alreadyFiltered.add(currentErr);

try {
currentErr.stack = stackFilter(currentErr.stack);
} catch (ignore) {
// some environments do not take kindly to monkeying with the stack
}

currentErr = currentErr.cause;
}
}

this.emit(constants.EVENT_TEST_FAIL, test, err);
Expand Down
4 changes: 2 additions & 2 deletions package-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ module.exports = {
docs: {
default: {
script:
'nps docs.clean && nps docs.api && eleventy && nps docs.linkcheck && node scripts/netlify-headers.js docs/_site >> docs/_site/_headers',
'nps docs.clean && nps docs.api && eleventy && nps docs.linkcheck',
description: 'Build documentation'
},
production: {
Expand All @@ -277,7 +277,7 @@ module.exports = {
},
postbuild: {
script:
'buildProduction docs/_site/index.html --outroot docs/_dist --canonicalroot https://mochajs.org/ --optimizeimages --svgo --inlinehtmlimage 9400 --inlinehtmlscript 0 --asyncscripts && cp docs/_headers docs/_dist/_headers && node scripts/netlify-headers.js docs/_dist >> docs/_dist/_headers',
'node node_modules/assetgraph-builder/bin/buildProduction docs/_site/index.html --outroot docs/_dist --canonicalroot https://mochajs.org/ --optimizeimages --svgo --inlinehtmlimage 9400 --inlinehtmlscript 0 --asyncscripts && cp docs/_headers docs/_dist/_headers',
description: 'Post-process docs after build',
hiddenFromHelp: true
},
Expand Down
Loading

0 comments on commit a6bdef4

Please sign in to comment.