diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md index 93aef1d0cf..d4d5a7ab06 100644 --- a/.github/CODE_OF_CONDUCT.md +++ b/.github/CODE_OF_CONDUCT.md @@ -100,4 +100,4 @@ This is a foundation-wide team established to manage escalation when a reporter In order to escalate to the CoCP send an email to `"coc-escalation@lists.openjsf.org`. For more information, refer to the full -[Code of Conduct governance document](https://github.com/openjs-foundation/cross-project-council/blob/master/FOUNDATION_CODE_OF_CONDUCT_REQUIREMENTS.md). +[Code of Conduct governance document](https://github.com/openjs-foundation/cross-project-council/tree/main/proposals/approved/CODE_OF_CONDUCT). diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 8a9fa714b9..6a60026936 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -99,11 +99,11 @@ Then: - Add detail in subsequent lines. - A pre-commit hook will run which automatically formats your staged changes (and fixes any problems it can) with ESLint and Prettier. If ESLint fails to fix an issue, your commit will fail and you will need to manually correct the problem. -1. (Optional) Ensure you are up-to-date with Mocha's `master` branch: +1. (Optional) Ensure you are up-to-date with Mocha's `main` branch: - You can add an "upstream" remote repo using `git remote add upstream https://github.com/mochajs/mocha.git && git fetch upstream`. - - Navigate to your `master` branch using `git checkout master`. - - Pull changes from `upstream` using `git pull upstream master`. - - If any changes were pulled in, update your branch from `master` by switching back to your branch (`git checkout `) then merging using `git merge master`. + - Navigate to your `main` branch using `git checkout main`. + - Pull changes from `upstream` using `git pull upstream main`. + - If any changes were pulled in, update your branch from `main` by switching back to your branch (`git checkout `) then merging using `git merge main`. 1. Push your changes to your fork; `git push origin`. 1. In your browser, navigate to [mochajs/mocha](https://github.com/mochajs/mocha). You should see a notification about your recent changes in your fork's branch, with a (green?) button to create a pull request. @@ -126,7 +126,7 @@ Now that the pull request exists, some tasks will be run on it: 1. Be patient while your PR is reviewed. This can take a while. We may request changes, but don't be afraid to question them. -1. Your PR might become conflicted with the code in `master`. +1. Your PR might become conflicted with the code in `main`. If this is the case, you will need to [update your PR](#up-to-date) and resolve your conflicts. 1. You don't need to make a new PR to any needed changes. Instead, commit on top of your changes, and push these to your fork's branch. diff --git a/.github/ISSUE_TEMPLATE/01-bug.yml b/.github/ISSUE_TEMPLATE/01-bug.yml index fc43efff3f..b46ae9d9b3 100644 --- a/.github/ISSUE_TEMPLATE/01-bug.yml +++ b/.github/ISSUE_TEMPLATE/01-bug.yml @@ -3,7 +3,7 @@ body: description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you! label: Bug Report Checklist options: - - label: I have read and agree to Mocha's [Code of Conduct](https://github.com/mochajs/mocha/blob/master/.github/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/mochajs/mocha/blob/master/.github/CONTRIBUTING.md) + - label: I have read and agree to Mocha's [Code of Conduct](https://github.com/mochajs/mocha/blob/main/.github/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/mochajs/mocha/blob/main/.github/CONTRIBUTING.md) required: true - label: I have searched for [related issues](https://github.com/mochajs/mocha/issues?q=is%3Aissue) and [issues with the `faq` label](https://github.com/mochajs/mocha/issues?utf8=%E2%9C%93&q=is%3Aissue%20label%3Afaq%20), but none matched my issue. required: true diff --git a/.github/ISSUE_TEMPLATE/02-documentation.yml b/.github/ISSUE_TEMPLATE/02-documentation.yml index 09517048ac..0a98e59f35 100644 --- a/.github/ISSUE_TEMPLATE/02-documentation.yml +++ b/.github/ISSUE_TEMPLATE/02-documentation.yml @@ -3,7 +3,7 @@ body: description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you! label: Documentation Request Checklist options: - - label: I have read and agree to Mocha's [Code of Conduct](https://github.com/mochajs/mocha/blob/master/.github/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/mochajs/mocha/blob/master/.github/CONTRIBUTING.md) + - label: I have read and agree to Mocha's [Code of Conduct](https://github.com/mochajs/mocha/blob/main/.github/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/mochajs/mocha/blob/main/.github/CONTRIBUTING.md) required: true - label: I have searched for [related issues](https://github.com/mochajs/mocha/issues?q=is%3Aissue) and [issues with the `faq` label](https://github.com/mochajs/mocha/issues?utf8=%E2%9C%93&q=is%3Aissue%20label%3Afaq%20), but none matched my issue. required: true diff --git a/.github/ISSUE_TEMPLATE/03-feature-request.yml b/.github/ISSUE_TEMPLATE/03-feature-request.yml index 00778f454a..c37843969e 100644 --- a/.github/ISSUE_TEMPLATE/03-feature-request.yml +++ b/.github/ISSUE_TEMPLATE/03-feature-request.yml @@ -3,7 +3,7 @@ body: description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you! label: Feature Request Checklist options: - - label: I have read and agree to Mocha's [Code of Conduct](https://github.com/mochajs/mocha/blob/master/.github/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/mochajs/mocha/blob/master/.github/CONTRIBUTING.md) + - label: I have read and agree to Mocha's [Code of Conduct](https://github.com/mochajs/mocha/blob/main/.github/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/mochajs/mocha/blob/main/.github/CONTRIBUTING.md) required: true - label: I have searched for [related issues](https://github.com/mochajs/mocha/issues?q=is%3Aissue) and [issues with the `faq` label](https://github.com/mochajs/mocha/issues?utf8=%E2%9C%93&q=is%3Aissue%20label%3Afaq%20), but none matched my issue. required: true diff --git a/.github/ISSUE_TEMPLATE/04-repository-tooling.yml b/.github/ISSUE_TEMPLATE/04-repository-tooling.yml index 3d3908fa31..7e6c6a57f1 100644 --- a/.github/ISSUE_TEMPLATE/04-repository-tooling.yml +++ b/.github/ISSUE_TEMPLATE/04-repository-tooling.yml @@ -5,9 +5,9 @@ body: options: - label: I have tried restarting my IDE and the issue persists. required: true - - label: I have pulled the latest `master` branch of the repository. + - label: I have pulled the latest `main` branch of the repository. required: true - - label: I have read and agree to Mocha's [Code of Conduct](https://github.com/mochajs/mocha/blob/master/.github/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/mochajs/mocha/blob/master/.github/CONTRIBUTING.md) + - label: I have read and agree to Mocha's [Code of Conduct](https://github.com/mochajs/mocha/blob/main/.github/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/mochajs/mocha/blob/main/.github/CONTRIBUTING.md) required: true - label: I have searched for [related issues](https://github.com/mochajs/mocha/issues?q=is%3Aissue) and [issues with the `faq` label](https://github.com/mochajs/mocha/issues?utf8=%E2%9C%93&q=is%3Aissue%20label%3Afaq%20), but none matched my issue. required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index dbdd514b0c..14346bf54f 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,4 +1,4 @@ -blank_issues_enabled: false +blank_issues_enabled: true contact_links: - name: Documentation Website about: Please read our documentation website before filing new issues. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 20df860769..9f8ff8ca6a 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -6,7 +6,7 @@ Otherwise we may not be able to review your PR. --> - [ ] Addresses an existing open issue: fixes #000 - [ ] That issue was marked as [`status: accepting prs`](https://github.com/mochajs/mocha/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) -- [ ] Steps in [CONTRIBUTING.md](https://github.com/mochajs/mocha/blob/master/.github/CONTRIBUTING.md) were taken +- [ ] Steps in [CONTRIBUTING.md](https://github.com/mochajs/mocha/blob/main/.github/CONTRIBUTING.md) were taken ## Overview diff --git a/.github/workflows/compliance.yml b/.github/workflows/compliance.yml index 70d9714e5f..99afe754fa 100644 --- a/.github/workflows/compliance.yml +++ b/.github/workflows/compliance.yml @@ -12,7 +12,7 @@ name: Compliance on: pull_request: branches: - - master + - main types: - edited - opened diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 16b4463dd8..308ba603f1 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -25,7 +25,7 @@ A "user" for the purpose of this document is any _individual developer_ who cons A user interacts with contributors. A user interacts with the software, web site, documentation, etc., which these contributors provide. -As a user, you're expected to follow the [code of conduct](https://github.com/mochajs/mocha/blob/master/.github/CODE_OF_CONDUCT.md) when interacting in Mocha's "official" social spaces. +As a user, you're expected to follow the [code of conduct](https://github.com/mochajs/mocha/blob/main/.github/CODE_OF_CONDUCT.md) when interacting in Mocha's "official" social spaces. This includes: - Any channel under the `mochajs` Discord @@ -54,7 +54,7 @@ Contributions include (but are not limited to): 1. Researching the user base, getting feedback, etc. Don't spam. A contributor is _usually_ a user as well, but this isn't a hard-and-fast rule. -A contributor is also expected to adhere to the [code of conduct](https://github.com/mochajs/mocha/blob/master/.github/CODE_OF_CONDUCT.md) as a user would. +A contributor is also expected to adhere to the [code of conduct](https://github.com/mochajs/mocha/blob/main/.github/CODE_OF_CONDUCT.md) as a user would. As you can see, it's wide open! Think of it another way: if you are _adding value to Mocha_, then you are a contributor. @@ -123,7 +123,7 @@ You may choose to do zero or more of these _at their discretion_: - Add new maintainers to the team - Tag releases and publish Mocha to npm -> While maintainers have the ability to commit directly to the `master` branch, _this is to be avoided_ if any other maintainer could reasonably take issue with the change, or the change affects Mocha's API or output. +> While maintainers have the ability to commit directly to the `main` branch, _this is to be avoided_ if any other maintainer could reasonably take issue with the change, or the change affects Mocha's API or output. > For example, a spelling correction in `CHANGELOG.md` may not require a pull request. > A change to a reporter's output most certainly would! Maintainers are trusted to use their best judgement; if unsure, err on the side of caution. @@ -347,8 +347,8 @@ Here are some suggestions: ## Branches -`master` is the only maintained branch in `mochajs/mocha` or any of the other repos. -**`master` is the only branch to which force-pushing is disallowed.** +`main` is the only maintained branch in `mochajs/mocha` or any of the other repos. +**`main` is the only branch to which force-pushing is disallowed.** Maintainers may push new branches to a repo, as long as they remove them when finished (merging a PR will prompt to do so). @@ -371,7 +371,7 @@ Likewise, if the PR is `semver-minor`, create or use a new milestone correlating If it's unclear what the next milestone will be, use or create a milestone named `next`. This milestone will be renamed to the new version at release time. -By using milestones, we can cherry-pick non-breaking changes into minor or patch releases, and keep `master` as the latest version. +By using milestones, we can cherry-pick non-breaking changes into minor or patch releases, and keep `main` as the latest version. **This is subject to change, hopefully.** @@ -380,7 +380,7 @@ By using milestones, we can cherry-pick non-breaking changes into minor or patch _It's easier to release often._ 1. Decide whether this is a `patch`, `minor`, or `major` release. -1. Checkout `master` in your working copy & pull. +1. Checkout `main` in your working copy & pull. 1. Modify `CHANGELOG.md`; follow the existing conventions in that file. Use the "pull request" number, unless there isn't one. _You do not need to add Markdown links; this is done automatically._ @@ -391,15 +391,15 @@ _It's easier to release often._ (Hint--use `-m`: e.g., `npm version patch -m 'Release v%s'`) 1. This command will update the list of authors (from the Git history) in `AUTHORS`, and add GitHub links to `CHANGELOG.md`. 1. These changes are then added to the Git "stage" and will be added to the commit. -1. Push `master` to `origin` with your new tag; e.g. `git push origin master --tags` +1. Push `main` to `origin` with your new tag; e.g. `git push origin main --tags` 1. Copy & paste the `CHANGELOG.md` lines to a new GitHub "release". Save release as draft. 1. Meanwhile, you can check [the build](https://travis-ci.org/mochajs/mocha) on Travis-CI and [GitHub Actions](https://github.com/mochajs/mocha/actions?query=workflow%3A%22Windows+CI%22). 1. Once the build is green, you'll want to trigger an update of `mochajs.org`: - 1. _If you're doing a prerelease_, fast-forward the `next` branch to `master`, and push it. + 1. _If you're doing a prerelease_, fast-forward the `next` branch to `main`, and push it. This updates [https://next.mochajs.org](https://next.mochajs.org). That's all. - 1. _If this is NOT a prerelease_, fast-forward the `mochajs.org` branch to `master` and push it. + 1. _If this is NOT a prerelease_, fast-forward the `mochajs.org` branch to `main` and push it. This updates [https://mochajs.org](https://mochajs.org). 1. _If this is a "final" release_ (the first release of a major _after_ one or more prereleases) then remove the `next` tag from npm via `npm dist-tag rm next`. 1. Finally, you're satisfied with the release notes, open your draft release on GitHub, then click "publish." diff --git a/PROJECT_CHARTER.md b/PROJECT_CHARTER.md index 1f3e92e943..3505acb8e4 100644 --- a/PROJECT_CHARTER.md +++ b/PROJECT_CHARTER.md @@ -32,7 +32,7 @@ The **Mocha** project is part of the [OpenJS Foundation], which operates transpa - Command-line execution and options - Browser-based execution and options - [Project administration](https://github.com/mochajs/admin) - - [Contribution guide](https://github.com/mochajs/mocha/blob/master/.github/CONTRIBUTING.md) + - [Contribution guide](https://github.com/mochajs/mocha/blob/main/.github/CONTRIBUTING.md) - General support for multiple levels of tests, including (but not limited to): - Unit tests - Integration tests @@ -72,7 +72,7 @@ Changes to the following **cannot** unilaterally be applied by project leadershi - Mocha's Project Charter (this document) - Mocha's [Code of Conduct] -- Mocha's licenses: [MIT](https://github.com/mochajs/mocha/blob/master/LICENSE) (for code) and [CC-BY-4.0](https://github.com/mochajs/mocha/blob/master/docs/LICENSE-CC-BY-4.0) (for documentation/website) +- Mocha's licenses: [MIT](https://github.com/mochajs/mocha/blob/main/LICENSE) (for code) and [CC-BY-4.0](https://github.com/mochajs/mocha/blob/main/docs/LICENSE-CC-BY-4.0) (for documentation/website) ### §3.1: Other Formal Project Relationships @@ -103,5 +103,5 @@ Section Intentionally Left Blank Section Intentionally Left Blank [openjs foundation]: https://openjsf.org -[maintainers.md]: https://github.com/mochajs/mocha/blob/master/MAINTAINERS.md -[code of conduct]: https://github.com/mochajs/mocha/blob/master/.github/CODE_OF_CONDUCT.md +[maintainers.md]: https://github.com/mochajs/mocha/blob/main/MAINTAINERS.md +[code of conduct]: https://github.com/mochajs/mocha/blob/main/.github/CODE_OF_CONDUCT.md diff --git a/README.md b/README.md index 3545f7a721..ca740e1715 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@

☕️ Simple, flexible, fun JavaScript test framework for Node.js & The Browser ☕️

-GitHub Actions Build Status +GitHub Actions Build Status Coverage Status FOSSA Status Chat - Discord @@ -23,10 +23,10 @@ ## Links - **[Documentation](https://mochajs.org)** -- **[Release Notes / History / Changes](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)** -- [Code of Conduct](https://github.com/mochajs/mocha/blob/master/.github/CODE_OF_CONDUCT.md) -- [Contributing](https://github.com/mochajs/mocha/blob/master/.github/CONTRIBUTING.md) -- [Development](https://github.com/mochajs/mocha/blob/master/.github/DEVELOPMENT.md) +- **[Release Notes / History / Changes](https://github.com/mochajs/mocha/blob/main/CHANGELOG.md)** +- [Code of Conduct](https://github.com/mochajs/mocha/blob/main/.github/CODE_OF_CONDUCT.md) +- [Contributing](https://github.com/mochajs/mocha/blob/main/.github/CONTRIBUTING.md) +- [Development](https://github.com/mochajs/mocha/blob/main/.github/DEVELOPMENT.md) - [Discord](https://discord.gg/KeDn2uXhER) (ask questions here!) - [Issue Tracker](https://github.com/mochajs/mocha/issues) @@ -59,7 +59,7 @@ You might want to help: - New to contributing to Mocha? Check out this list of [good first issues](https://github.com/mochajs/mocha/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) - Mocha could use a hand with [these issues](https://github.com/mochajs/mocha/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) -- The [maintainer's handbook](https://github.com/mochajs/mocha/blob/master/MAINTAINERS.md) explains how things get done +- The [maintainer's handbook](https://github.com/mochajs/mocha/blob/main/MAINTAINERS.md) explains how things get done Finally, come [chat with the maintainers on Discord](https://discord.gg/KeDn2uXhER) if you want to help with: @@ -69,6 +69,6 @@ Finally, come [chat with the maintainers on Discord](https://discord.gg/KeDn2uXh ## License -Copyright 2011-2022 OpenJS Foundation and contributors. Licensed [MIT](https://github.com/mochajs/mocha/blob/master/LICENSE). +Copyright 2011-2022 OpenJS Foundation and contributors. Licensed [MIT](https://github.com/mochajs/mocha/blob/main/LICENSE). [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmochajs%2Fmocha.svg?type=large)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmochajs%2Fmocha?ref=badge_large) diff --git a/browser-entry.js b/browser-entry.js index 67517db357..4e6f9e939a 100644 --- a/browser-entry.js +++ b/browser-entry.js @@ -71,8 +71,8 @@ process.listenerCount = function (name) { process.on = function (e, fn) { if (e === 'uncaughtException') { - global.onerror = function (err, url, line) { - fn(new Error(err + ' (' + url + ':' + line + ')')); + global.onerror = function (msg, url, line, col, err) { + fn(err || new Error(msg + ' (' + url + ':' + line + ':' + col + ')')); return !mocha.options.allowUncaught; }; uncaughtExceptionHandlers.push(fn); diff --git a/docs/API.md b/docs/API.md index 7b63a6b433..a6e17bf284 100644 --- a/docs/API.md +++ b/docs/API.md @@ -13,7 +13,7 @@ Otherwise, **you probably want the [main documentation](https://mochajs.org)**. ## Other Links - **[Main Documentation](https://mochajs.org)** -- **[Release Notes / History / Changes](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)** -- [Code of Conduct](https://github.com/mochajs/mocha/blob/master/.github/CODE_OF_CONDUCT.md) +- **[Release Notes / History / Changes](https://github.com/mochajs/mocha/blob/main/CHANGELOG.md)** +- [Code of Conduct](https://github.com/mochajs/mocha/blob/main/.github/CODE_OF_CONDUCT.md) - [Discord](https://discord.gg/KeDn2uXhER) (ask questions here!) - [Issue Tracker](https://github.com/mochajs/mocha/issues) diff --git a/docs/README.md b/docs/README.md index f85b53adec..0c3e69e53f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -40,6 +40,6 @@ cp: docs/_dist/_headers: No such file or directory :copyright: 2016-2018 [JS Foundation](https://js.foundation) and contributors. -Content licensed [CC-BY-4.0](https://raw.githubusercontent.com/mochajs/mocha/master/docs/LICENSE-CC-BY-4.0). +Content licensed [CC-BY-4.0](https://raw.githubusercontent.com/mochajs/mocha/main/docs/LICENSE-CC-BY-4.0). -Code licensed [MIT](https://raw.githubusercontent.com/mochajs/mocha/master/LICENSE-MIT). +Code licensed [MIT](https://raw.githubusercontent.com/mochajs/mocha/main/LICENSE-MIT). diff --git a/docs/api-tutorials/custom-reporter.md b/docs/api-tutorials/custom-reporter.md index 99ca9d6d2f..b537fe1ee2 100644 --- a/docs/api-tutorials/custom-reporter.md +++ b/docs/api-tutorials/custom-reporter.md @@ -13,7 +13,7 @@ If you're looking to get started quickly, here's an example of a custom reporter To use this reporter, execute `mocha --reporter /path/to/my-reporter.js`. -For further examples, the built-in reporter implementations are the [best place to look](https://github.com/mochajs/mocha/tree/master/lib/reporters). The [integration tests](https://github.com/mochajs/mocha/tree/master/test/reporters) may also be helpful. +For further examples, the built-in reporter implementations are the [best place to look](https://github.com/mochajs/mocha/tree/main/lib/reporters). The [integration tests](https://github.com/mochajs/mocha/tree/main/test/reporters) may also be helpful. ## The `Base` Reporter Class diff --git a/docs/changelogs/README.md b/docs/changelogs/README.md index 2c059575d2..1f201b251f 100644 --- a/docs/changelogs/README.md +++ b/docs/changelogs/README.md @@ -4,4 +4,4 @@ These are changelogs for (very) old versions of Mocha. These changelogs are _not_ included in the website, and are here only for archival purposes. -_If you're looking for the current changelog, [here is the current changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)._ +_If you're looking for the current changelog, [here is the current changelog](https://github.com/mochajs/mocha/blob/main/CHANGELOG.md)._ diff --git a/docs/css/style.css b/docs/css/style.css index 79dbc261e8..c36f73c85d 100644 --- a/docs/css/style.css +++ b/docs/css/style.css @@ -180,6 +180,9 @@ a.direct-link { ul { box-sizing: content-box; +} + +ul.two-column { column-count: 2; column-gap: 30px; margin-top: 20px; @@ -188,9 +191,8 @@ ul { ul.single-column, ul.single-column > li > ul { - column-count: 1; margin-top: 0; - padding-right: 0; + padding: 0 0 0 15px; } ul li { diff --git a/docs/index.md b/docs/index.md index 997a90e553..2e9313185d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -44,10 +44,12 @@ Mocha is a feature-rich JavaScript test framework running on [Node.js][] and in - [before, after, before each, after each hooks](#hooks) - [arbitrary transpiler support (coffee-script etc)](#-compilers) - [TextMate bundle](#textmate) + {:.two-column} ## Table of Contents {{ toc }} +{:.two-column} ## Installation @@ -2214,11 +2216,22 @@ If no custom path was given, and if there are multiple configuration files in th 1. `.mocharc.jsonc` 1. `.mocharc.json` +### Environment Variables + +The `MOCHA_OPTIONS` environment variable may be used to specify command line arguments. These arguments take priority over those found in configuration files. + +For example, setting the `bail` and `retries` options: + +```bash +$ MOCHA_OPTIONS="--bail --retries 3" mocha +``` + ### Merging Mocha will also _merge_ any options found in `package.json` into its run-time configuration. In case of conflict, the priority is: 1. Arguments specified on command-line +1. Arguments specified in `MOCHA_OPTIONS` environment variable. 1. Configuration file (`.mocharc.js`, `.mocharc.yml`, etc.) 1. `mocha` property of `package.json` @@ -2350,7 +2363,7 @@ $ npm test In addition to chatting with us on [our Discord][discord-mocha], for additional information such as using spies, mocking, and shared behaviours be sure to check out the [Mocha Wiki][mocha-wiki] on GitHub. For a running example of Mocha, view [example/tests.html](example/tests.html). For the JavaScript API, view the [API documentation](api/) -or the [source](https://github.com/mochajs/mocha/blob/master/lib/mocha.js). +or the [source](https://github.com/mochajs/mocha/blob/main/lib/mocha.js). [//]: # 'Cross reference section' [bash-globbing]: https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html @@ -2362,14 +2375,14 @@ or the [source](https://github.com/mochajs/mocha/blob/master/lib/mocha.js). [discord-mocha]: https://discord.gg/KeDn2uXhER [emacs]: https://www.gnu.org/software/emacs/ [emacs-mocha.el]: https://github.com/scottaj/mocha.el -[example-babel]: https://github.com/mochajs/mocha-examples/tree/master/packages/babel +[example-babel]: https://github.com/mochajs/mocha-examples/tree/main/packages/babel [example-connect-test]: https://github.com/senchalabs/connect/tree/master/test [example-express-test]: https://github.com/visionmedia/express/tree/master/test -[example-mocha-test]: https://github.com/mochajs/mocha/tree/master/test -[example-mocha-config]: https://github.com/mochajs/mocha/tree/master/example/config +[example-mocha-test]: https://github.com/mochajs/mocha/tree/main/test +[example-mocha-config]: https://github.com/mochajs/mocha/tree/main/example/config [example-superagent-test]: https://github.com/visionmedia/superagent/tree/master/test/node -[example-third-party-reporter]: https://github.com/mochajs/mocha-examples/tree/master/packages/third-party-reporter -[example-typescript]: https://github.com/mochajs/mocha-examples/tree/master/packages/typescript +[example-third-party-reporter]: https://github.com/mochajs/mocha-examples/tree/main/packages/third-party-reporter +[example-typescript]: https://github.com/mochajs/mocha-examples/tree/main/packages/typescript [example-websocket.io-test]: https://github.com/LearnBoost/websocket.io/tree/master/test [expect.js]: https://github.com/LearnBoost/expect.js [expresso]: https://github.com/tj/expresso diff --git a/lib/cli/options.js b/lib/cli/options.js index 8fa9470e6f..d238737d37 100644 --- a/lib/cli/options.js +++ b/lib/cli/options.js @@ -208,9 +208,10 @@ module.exports.loadPkgRc = loadPkgRc; * Priority list: * * 1. Command-line args - * 2. RC file (`.mocharc.c?js`, `.mocharc.ya?ml`, `mocharc.json`) - * 3. `mocha` prop of `package.json` - * 4. default configuration (`lib/mocharc.json`) + * 2. `MOCHA_OPTIONS` environment variable. + * 3. RC file (`.mocharc.c?js`, `.mocharc.ya?ml`, `mocharc.json`) + * 4. `mocha` prop of `package.json` + * 5. default configuration (`lib/mocharc.json`) * * If a {@link module:lib/cli/one-and-dones.ONE_AND_DONE_ARGS "one-and-done" option} is present in the `argv` array, no external config files will be read. * @summary Parses options read from `.mocharc.*` and `package.json`. @@ -231,6 +232,7 @@ const loadOptions = (argv = []) => { return args; } + const envConfig = parse(process.env.MOCHA_OPTIONS || ''); const rcConfig = loadRc(args); const pkgConfig = loadPkgRc(args); @@ -243,7 +245,14 @@ const loadOptions = (argv = []) => { args._ = args._.concat(pkgConfig._ || []); } - args = parse(args._, mocharc, args, rcConfig || {}, pkgConfig || {}); + args = parse( + args._, + mocharc, + args, + envConfig, + rcConfig || {}, + pkgConfig || {} + ); // recombine positional arguments and "spec" if (args.spec) { diff --git a/package-lock.json b/package-lock.json index 95d2a6e252..b452577bc4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,7 +54,6 @@ "fail-on-errors-webpack-plugin": "^3.0.0", "fs-extra": "^10.0.0", "globals": "^13.24.0", - "husky": "^4.2.5", "hyperlink": "^5.0.4", "jsdoc": "^3.6.7", "jsdoc-ts-utils": "^2.0.1", @@ -4999,12 +4998,6 @@ "integrity": "sha512-3Lc0sTIuX1jmY2K2RrXRJOND6KsRTX2D4v3+eu1PDptsuJZVK4LZc852eZa9I+avj0NrUKlTNgqvccNOH6mbGg==", "dev": true }, - "node_modules/compare-versions": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/compare-versions/-/compare-versions-3.6.0.tgz", - "integrity": "sha512-W6Af2Iw1z4CB7q4uU4hv646dW9GQuBM+YpC0UvUCWSD8w90SJjp+ujJuXaEMtAXBtSqGfMPuFOVn4/+FlaqfBA==", - "dev": true - }, "node_modules/compress-commons": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-4.1.1.tgz", @@ -8094,21 +8087,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/find-versions": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/find-versions/-/find-versions-4.0.0.tgz", - "integrity": "sha512-wgpWy002tA+wgmO27buH/9KzyEOQnKsG/R0yrcjPT9BOFm0zRBVQbZ95nRGXWMywS8YR5knRbpohio0bcJABxQ==", - "dev": true, - "dependencies": { - "semver-regex": "^3.1.2" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/flat": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", @@ -9292,36 +9270,6 @@ "node": ">=8.12.0" } }, - "node_modules/husky": { - "version": "4.3.8", - "resolved": "https://registry.npmjs.org/husky/-/husky-4.3.8.tgz", - "integrity": "sha512-LCqqsB0PzJQ/AlCgfrfzRe3e3+NvmefAdKQhRYpxS4u6clblBoDdzzvHi8fmxKRzvMxPY/1WZWzomPZww0Anow==", - "dev": true, - "hasInstallScript": true, - "dependencies": { - "chalk": "^4.0.0", - "ci-info": "^2.0.0", - "compare-versions": "^3.6.0", - "cosmiconfig": "^7.0.0", - "find-versions": "^4.0.0", - "opencollective-postinstall": "^2.0.2", - "pkg-dir": "^5.0.0", - "please-upgrade-node": "^3.2.0", - "slash": "^3.0.0", - "which-pm-runs": "^1.0.0" - }, - "bin": { - "husky-run": "bin/run.js", - "husky-upgrade": "lib/upgrader/bin.js" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/husky" - } - }, "node_modules/hyperlink": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/hyperlink/-/hyperlink-5.0.4.tgz", @@ -14619,15 +14567,6 @@ "node": ">=8" } }, - "node_modules/opencollective-postinstall": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz", - "integrity": "sha512-8AV/sCtuzUeTo8gQK5qDZzARrulB3egtLzFgteqB2tcT4Mw7B8Kt7JcDHmltjz6FOAHsvTevk70gZEbhM4ZS9Q==", - "dev": true, - "bin": { - "opencollective-postinstall": "index.js" - } - }, "node_modules/openurl": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/openurl/-/openurl-1.1.1.tgz", @@ -15350,18 +15289,6 @@ "node": ">=0.10.0" } }, - "node_modules/pkg-dir": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-5.0.0.tgz", - "integrity": "sha512-NPE8TDbzl/3YQYY7CSS228s3g2ollTFnc+Qi3tqmqJp9Vg2ovUpixcJEo2HJScN2Ez+kEaal6y70c0ehqJBJeA==", - "dev": true, - "dependencies": { - "find-up": "^5.0.0" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/please-upgrade-node": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/please-upgrade-node/-/please-upgrade-node-3.2.0.tgz", @@ -18310,18 +18237,6 @@ "semver": "bin/semver.js" } }, - "node_modules/semver-regex": { - "version": "3.1.4", - "resolved": "https://registry.npmjs.org/semver-regex/-/semver-regex-3.1.4.tgz", - "integrity": "sha512-6IiqeZNgq01qGf0TId0t3NvKzSvUsjcpdEO3AQNeIjR6A2+ckTnQlDpl4qu1bjRv0RzN3FP9hzFmws3lKqRWkA==", - "dev": true, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/semver-truncate": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/semver-truncate/-/semver-truncate-1.1.2.tgz", @@ -18826,15 +18741,6 @@ "node": ">=8" } }, - "node_modules/slash": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", - "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/slice-ansi": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-3.0.0.tgz", @@ -21765,15 +21671,6 @@ "integrity": "sha512-B+enWhmw6cjfVC7kS8Pj9pCrKSc5txArRyaYGe088shv/FGWH+0Rjx/xPgtsWfsUtS27FkP697E4DDhgrgoc0Q==", "dev": true }, - "node_modules/which-pm-runs": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/which-pm-runs/-/which-pm-runs-1.1.0.tgz", - "integrity": "sha512-n1brCuqClxfFfq/Rb0ICg9giSZqCS+pLtccdag6C2HyufBrh3fBOiy9nb6ggRMvWOVH5GrdJskj5iGTZNxd7SA==", - "dev": true, - "engines": { - "node": ">=4" - } - }, "node_modules/which-typed-array": { "version": "1.1.9", "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.9.tgz", @@ -26329,12 +26226,6 @@ "integrity": "sha512-3Lc0sTIuX1jmY2K2RrXRJOND6KsRTX2D4v3+eu1PDptsuJZVK4LZc852eZa9I+avj0NrUKlTNgqvccNOH6mbGg==", "dev": true }, - "compare-versions": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/compare-versions/-/compare-versions-3.6.0.tgz", - "integrity": "sha512-W6Af2Iw1z4CB7q4uU4hv646dW9GQuBM+YpC0UvUCWSD8w90SJjp+ujJuXaEMtAXBtSqGfMPuFOVn4/+FlaqfBA==", - "dev": true - }, "compress-commons": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-4.1.1.tgz", @@ -28802,15 +28693,6 @@ "path-exists": "^4.0.0" } }, - "find-versions": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/find-versions/-/find-versions-4.0.0.tgz", - "integrity": "sha512-wgpWy002tA+wgmO27buH/9KzyEOQnKsG/R0yrcjPT9BOFm0zRBVQbZ95nRGXWMywS8YR5knRbpohio0bcJABxQ==", - "dev": true, - "requires": { - "semver-regex": "^3.1.2" - } - }, "flat": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", @@ -29724,24 +29606,6 @@ "integrity": "sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw==", "dev": true }, - "husky": { - "version": "4.3.8", - "resolved": "https://registry.npmjs.org/husky/-/husky-4.3.8.tgz", - "integrity": "sha512-LCqqsB0PzJQ/AlCgfrfzRe3e3+NvmefAdKQhRYpxS4u6clblBoDdzzvHi8fmxKRzvMxPY/1WZWzomPZww0Anow==", - "dev": true, - "requires": { - "chalk": "^4.0.0", - "ci-info": "^2.0.0", - "compare-versions": "^3.6.0", - "cosmiconfig": "^7.0.0", - "find-versions": "^4.0.0", - "opencollective-postinstall": "^2.0.2", - "pkg-dir": "^5.0.0", - "please-upgrade-node": "^3.2.0", - "slash": "^3.0.0", - "which-pm-runs": "^1.0.0" - } - }, "hyperlink": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/hyperlink/-/hyperlink-5.0.4.tgz", @@ -33777,12 +33641,6 @@ } } }, - "opencollective-postinstall": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz", - "integrity": "sha512-8AV/sCtuzUeTo8gQK5qDZzARrulB3egtLzFgteqB2tcT4Mw7B8Kt7JcDHmltjz6FOAHsvTevk70gZEbhM4ZS9Q==", - "dev": true - }, "openurl": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/openurl/-/openurl-1.1.1.tgz", @@ -34339,15 +34197,6 @@ "pinkie": "^2.0.0" } }, - "pkg-dir": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-5.0.0.tgz", - "integrity": "sha512-NPE8TDbzl/3YQYY7CSS228s3g2ollTFnc+Qi3tqmqJp9Vg2ovUpixcJEo2HJScN2Ez+kEaal6y70c0ehqJBJeA==", - "dev": true, - "requires": { - "find-up": "^5.0.0" - } - }, "please-upgrade-node": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/please-upgrade-node/-/please-upgrade-node-3.2.0.tgz", @@ -36598,12 +36447,6 @@ } } }, - "semver-regex": { - "version": "3.1.4", - "resolved": "https://registry.npmjs.org/semver-regex/-/semver-regex-3.1.4.tgz", - "integrity": "sha512-6IiqeZNgq01qGf0TId0t3NvKzSvUsjcpdEO3AQNeIjR6A2+ckTnQlDpl4qu1bjRv0RzN3FP9hzFmws3lKqRWkA==", - "dev": true - }, "semver-truncate": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/semver-truncate/-/semver-truncate-1.1.2.tgz", @@ -37005,12 +36848,6 @@ } } }, - "slash": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", - "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", - "dev": true - }, "slice-ansi": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-3.0.0.tgz", @@ -39283,12 +39120,6 @@ "integrity": "sha512-B+enWhmw6cjfVC7kS8Pj9pCrKSc5txArRyaYGe088shv/FGWH+0Rjx/xPgtsWfsUtS27FkP697E4DDhgrgoc0Q==", "dev": true }, - "which-pm-runs": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/which-pm-runs/-/which-pm-runs-1.1.0.tgz", - "integrity": "sha512-n1brCuqClxfFfq/Rb0ICg9giSZqCS+pLtccdag6C2HyufBrh3fBOiy9nb6ggRMvWOVH5GrdJskj5iGTZNxd7SA==", - "dev": true - }, "which-typed-array": { "version": "1.1.9", "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.9.tgz", diff --git a/package.json b/package.json index ea772f4441..5de69fdd9d 100644 --- a/package.json +++ b/package.json @@ -92,7 +92,6 @@ "fail-on-errors-webpack-plugin": "^3.0.0", "fs-extra": "^10.0.0", "globals": "^13.24.0", - "husky": "^4.2.5", "hyperlink": "^5.0.4", "jsdoc": "^3.6.7", "jsdoc-ts-utils": "^2.0.1", @@ -168,10 +167,5 @@ }, "overrides": { "webdriverio": "^7.33.0" - }, - "husky": { - "hooks": { - "pre-commit": "lint-staged" - } } } diff --git a/test/node-unit/cli/options.spec.js b/test/node-unit/cli/options.spec.js index 0508514cdd..60357d12ae 100644 --- a/test/node-unit/cli/options.spec.js +++ b/test/node-unit/cli/options.spec.js @@ -42,9 +42,10 @@ describe('options', function () { /** * Order of priority: * 1. Command-line args - * 2. RC file (`.mocharc.js`, `.mocharc.ya?ml`, `mocharc.json`) - * 3. `mocha` prop of `package.json` - * 4. default rc + * 2. `MOCHA_OPTIONS` environment variable + * 3. RC file (`.mocharc.js`, `.mocharc.ya?ml`, `mocharc.json`) + * 4. `mocha` prop of `package.json` + * 5. default rc */ describe('loadOptions()', function () { describe('when no parameter provided', function () { @@ -408,6 +409,30 @@ describe('options', function () { }); }); + describe('env options', function () { + it('should parse flags from MOCHA_OPTIONS', function () { + readFileSync = sinon.stub().onFirstCall().returns('{}'); + findConfig = sinon.stub().returns('/some/.mocharc.json'); + loadConfig = sinon.stub().returns({}); + findupSync = sinon.stub().returns('/some/package.json'); + sinon + .stub(process, 'env') + .value({MOCHA_OPTIONS: '--retries 42 --color'}); + + loadOptions = proxyLoadOptions({ + readFileSync, + findConfig, + loadConfig, + findupSync + }); + + expect(loadOptions(), 'to satisfy', { + retries: 42, + color: true + }); + }); + }); + describe('config priority', function () { it('should prioritize package.json over defaults', function () { readFileSync = sinon.stub(); @@ -474,6 +499,27 @@ describe('options', function () { '500' ); }); + + it('should prioritize env over rc file', function () { + readFileSync = sinon.stub(); + readFileSync.onFirstCall().returns('{}'); + readFileSync.onSecondCall().returns(''); + findConfig = sinon.stub().returns('/some/.mocharc.json'); + loadConfig = sinon.stub().returns({retries: 300}); + findupSync = sinon.stub().returns('/some/package.json'); + sinon + .stub(process, 'env') + .value({MOCHA_OPTIONS: '--retries 800 --color'}); + + loadOptions = proxyLoadOptions({ + readFileSync, + findConfig, + loadConfig, + findupSync + }); + + expect(loadOptions(), 'to have property', 'retries', 800); + }); }); describe('when called with a one-and-done arg', function () { diff --git a/test/unit/throw.spec.js b/test/unit/throw.spec.js index ccb7ef6c11..cafadaa4bc 100644 --- a/test/unit/throw.spec.js +++ b/test/unit/throw.spec.js @@ -2,6 +2,7 @@ /* eslint no-throw-literal: off */ +var sinon = require('sinon'); var Mocha = require('../../lib/mocha'); var Suite = Mocha.Suite; var Test = Mocha.Test; @@ -29,6 +30,7 @@ describe('a test that throws', function () { uncaughtHandlers.forEach(function (listener) { process.on('uncaughtException', listener); }); + sinon.restore(); }); describe('non-extensible', function () { @@ -172,4 +174,35 @@ describe('a test that throws', function () { runner.run(); }); }); + + describe('stack', function() { + it('should include the stack when throwing async', function(done) { + var test = new Test('im async and throw null async', function(done2) { + process.nextTick(function throwError() { + throw new Error('test error'); + }); + }); + suite.addTest(test); + runner = new Runner(suite); + sinon.stub(runner, 'fail'); + + runner.on(EVENT_RUN_END, function() { + try { + expect(runner.fail, 'to have all calls satisfying', [ + expect.it('to be a', Runnable), + expect.it('to be an', Error).and('to satisfy', { + message: /test error/i, + stack: /throwError/i, + uncaught: true + }) + ]).and('was called once'); + } catch (err) { + return done(err); + } + + done(); + }); + runner.run(); + }); + }); });