Skip to content

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

Open
@josh-cloudscape

Description

@josh-cloudscape

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

Activity

added
status: in triagea maintainer should (re-)triage (review) this issue
type: buga defect, confirmed by a maintainer
on Sep 5, 2024
JoshuaKGoldberg

JoshuaKGoldberg commented on Oct 8, 2024

@JoshuaKGoldberg
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.

added and removed
status: in triagea maintainer should (re-)triage (review) this issue
on Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

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

      🐛 Bug: Error in mochaGlobalTeardown is swallowed and exits with code 0 · Issue #5208 · mochajs/mocha