fix: resolve Mocha reporter from consuming package - #28053
fix: resolve Mocha reporter from consuming package#28053Craig Macomber (Microsoft) (CraigMacomber) wants to merge 1 commit into
Conversation
|
Hi! Thank you for opening this PR. Want me to review it? Based on the diff (3 lines, 1 files), I've queued these reviewers:
How this works
|
There was a problem hiding this comment.
Pull request overview
Update Fluid’s shared Mocha config helper so mocha-multi-reporters is resolved from the consuming package rather than from Mocha’s own installation, avoiding pnpm isolated-layout resolution failures (ERR_MOCHA_INVALID_REPORTER).
Changes:
- Resolve
mocha-multi-reportersviacreateRequire(packageJsonPath).resolve(...)anchored at the consuming package’spackage.json.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| const packageJsonPath = path.join(packageDir, "package.json"); | ||
| const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8")) as { | ||
| name: string; | ||
| }; | ||
| config.reporter = `mocha-multi-reporters`; | ||
| config.reporter = createRequire(packageJsonPath).resolve("mocha-multi-reporters"); |
Bundle size comparisonBase commit: Notable changesNo bundles changed by ≥ 500 bytes parsed. Per-bundle deltas
|
Description
Resolve
mocha-multi-reportersfrom each consuming package before passing it to Mocha.Mocha resolves a bare reporter name relative to its own installation. With pnpm's isolated dependency layout, the reporter can be available to the package running tests but unavailable from Mocha's virtual-store location, causing
ERR_MOCHA_INVALID_REPORTER.Resolving the reporter from the consuming package's
package.jsonpreserves package dependency ownership while making reporter loading independent of pnpm hoisting.This error can also coincide with stale peer links in
node_modules/.pnpm, particularly after dependency graph or peer-context changes. In the observed case,pnpm install --forcedid not repair the stale link. If reporter loading succeeds but another dependency fails withMODULE_NOT_FOUND, regenerate the installation from the repository root:This PR prevents reporter resolution from depending on pnpm's physical layout; it does not repair stale pnpm virtual-store links.
We do not know the source of the node_modules corruption, and it isn't repaired by
pnpm install --forcein pnpm 11 (but it is in the upcoming 12 release, though only when using --force, see pnpm/pnpm#9758 (comment))Reviewer Guidance
The review process is outlined in the pull request guidelines.