Skip to content

Conversation

@kraenhansen
Copy link
Collaborator

The metro require function was catching and reporting uncaught errors instead of propagating them to the caller of require. This was messing up out node-tests.

Merging this PR will:

  • Replace the initialization of the module in the test bundles and defer this to the the test function controlled by Mocha.

@kraenhansen kraenhansen self-assigned this Oct 21, 2025
@kraenhansen kraenhansen added the bug Something isn't working label Oct 21, 2025
@cursor
Copy link

cursor bot commented Oct 21, 2025

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on November 2.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@kraenhansen kraenhansen requested a review from Copilot October 21, 2025 08:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes error propagation in the node-tests package by preventing Metro's guardedLoadModule from swallowing errors during module initialization. The solution defers module initialization from require-time to test execution time.

Key changes:

  • Modified test entrypoint generation to export test functions directly instead of wrapping them in arrow functions
  • Added a Rolldown plugin to replace the default export pattern, converting immediate function invocation to function references
  • Added a convenience npm script for running Mocha with Metro

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/node-tests/scripts/generate-entrypoint.mts Removes arrow function wrapper from test suite generation to defer module initialization
packages/node-tests/rolldown.config.mts Adds replace plugin to convert require_test() invocations to require_test references, deferring execution
apps/test-app/package.json Adds mocha-and-metro npm script for convenient test execution

// Replace the default export to return a function instead of initializing the addon immediately
// This allows the test runner to intercept any errors which would normally be thrown when importing
// to work around Metro's `guardedLoadModule` swallowing errors during module initialization
// See https://github.com/facebook/metro/blob/34bb8913ec4b5b02690b39d2246599faf094f721/packages/metro-runtime/src/polyfills/require.js#L348-L353
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The comment references a specific GitHub commit hash in the Metro repository that may become outdated. Consider adding a version number or date reference (e.g., 'Metro v0.80.x as of Oct 2024') alongside the commit hash to provide more context about when this workaround was needed.

Suggested change
// See https://github.com/facebook/metro/blob/34bb8913ec4b5b02690b39d2246599faf094f721/packages/metro-runtime/src/polyfills/require.js#L348-L353
// See https://github.com/facebook/metro/blob/34bb8913ec4b5b02690b39d2246599faf094f721/packages/metro-runtime/src/polyfills/require.js#L348-L353
// (Metro v0.80.x as of Oct 2024)

Copilot uses AI. Check for mistakes.
@kraenhansen kraenhansen merged commit 9640d63 into main Oct 21, 2025
6 checks passed
@kraenhansen kraenhansen deleted the kh/node-tests-fix branch October 21, 2025 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants