Skip to content

unloadFiles throws MODULE_NOT_FOUND in ESM context for files added with relative path #4548

Open

Description

Prerequisites

  • Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • '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, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

Programmatically using mocha.addFile(file) and mocha.unloadFiles() in an ES module context throws MODULE_NOT_FOUND when mocha.addFile(...) is called with a relative path.

Wrapping the module resolution logic with path.resolve(...) resolves this issue by ensuring the path is absolute.

Steps to Reproduce

https://repl.it/@christiantjl/MochaFileUnloader#fails.js
node succeeds.js shows that an absolute path works without issue, and node fails.js shows that adding with a relative path throws an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    area: node.jscommand-line-or-Node.js-specificstatus: 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