Skip to content

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

Open
@josh-cloudscape

Description

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

Metadata

Assignees

No one assigned

    Labels

    status: accepting prsMocha can use your help with this one!type: buga defect, confirmed by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions