Skip to content

fix: resolve unloadFile paths from cwd - #6259

Closed
wangxpych wants to merge 1 commit into
mochajs:mainfrom
wangxpych:fix/unload-files-relative-path
Closed

wangxpych wants to merge 1 commit into
mochajs:mainfrom
wangxpych:fix/unload-files-relative-path

Conversation

@wangxpych

Copy link
Copy Markdown

PR Checklist

Overview

addFile() keeps paths exactly as supplied, and Mocha loads relative paths from the current working directory. unloadFile() instead passed those paths directly to require.resolve(), which resolved them relative to lib/nodejs/file-unloader.cjs and threw MODULE_NOT_FOUND.

Resolve the file path from the current working directory before looking up its cache key. The regression test loads a fixture, adds it using a cwd-relative path, and verifies that unloadFiles() removes it from require.cache.

The commit includes co-author attribution for the original implementation in #4549.

Validation

  • npm run test-node:unit — 1220 passing, 3 pending
  • integration suite — 374 passing, 1 pending
  • remaining Node interface, JS API, only, reporter, and require suites — passing
  • Playwright browser suite — 4 passing
  • Webpack compatibility build — passing
  • formatting, ESLint, Knip, TypeScript, and smoke checks — passing

Fixes #4548

Co-authored-by: Christian Lewis <ctjl96@gmail.com>
@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: wangxpych / name: xuping.wang (45ea4ca)

@wangxpych

Copy link
Copy Markdown
Author

Closing because I’m stepping back from maintaining this contribution. Thanks for your time.

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

1 participant