Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Bug: Error in mochaGlobalTeardown is swallowed and exits with code 0 #5208

Open
3 of 4 tasks
josh-cloudscape opened this issue Sep 5, 2024 · 1 comment
Open
3 of 4 tasks
Labels
status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer

Comments

@josh-cloudscape
Copy link

Bug Report Checklist

  • I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
  • I have searched for related issues and issues with the faq label, but none matched my issue.
  • I have 'smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, my usage of Mocha, or Mocha itself.
  • I want to provide a PR to resolve this

Expected

The error should be logged and the tests should exit with a non-zero exit code

Actual

The error is swallowed and the tests always exit with a 0 exit code (even if some tests failed)

Minimal, Reproducible Example

// test.js
const { it } = require("mocha");

it("should work", () => {
  throw new Error("It doesn't work");
});
// setup.js
exports.mochaGlobalTeardown = async function () {
  throw new Error("Teardown problem");
};
$ npx mocha -r setup.js test.js

Versions

Mocha v10.7.3, Node v20.15.1

Additional Info

No response

@josh-cloudscape josh-cloudscape added status: in triage a maintainer should (re-)triage (review) this issue type: bug a defect, confirmed by a maintainer labels Sep 5, 2024
@JoshuaKGoldberg
Copy link
Member

👍 Agreed, this is a bug. I reproduced it by adding the throw new Error("Teardown problem"); to the exports.mochaGlobalTeardown in mochajs/mocha-examples#101.

@JoshuaKGoldberg JoshuaKGoldberg added status: accepting prs Mocha can use your help with this one! and removed status: in triage a maintainer should (re-)triage (review) this issue labels Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

No branches or pull requests

2 participants