mochajs / mocha

β˜•οΈ simple, flexible, fun javascript test framework for node.js & the browser

Home Page:https://mochajs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ› Bug: Error in mochaGlobalTeardown is swallowed and exits with code 0

josh-cloudscape opened this issue Β· comments

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