Skip to content

fix(node:test): preserve mock function metadata - #7099

Merged
proggeramlug merged 2 commits into
PerryTS:mainfrom
proggeramlug:fix/6767-node-test-mock-name-length
Jul 31, 2026
Merged

fix(node:test): preserve mock function metadata#7099
proggeramlug merged 2 commits into
PerryTS:mainfrom
proggeramlug:fix/6767-node-test-mock-name-length

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • preserve the original function name on mock.fn(original) wrappers
  • preserve the original function arity as the mock wrapper length
  • expose Node-compatible configurable name and length descriptors
  • keep all mock construction values rooted across metadata allocations

Refs #6767

Verification

  • cargo check -p perry-runtime
  • cargo test -p perry-runtime mock_function_preserves_original_name_length_and_descriptors -- --nocapture
  • ./run_parity_tests.sh --suite node-suite --module test --filter node-suite/test/mock-fn/name-length (100% parity)

Summary by CodeRabbit

  • Bug Fixes

    • Mock functions now preserve the original function’s name and expected argument count.
    • Mocked name and length properties now retain standard non-writable, non-enumerable, and configurable behavior.
  • Tests

    • Added coverage confirming metadata and property descriptor preservation for mocked functions.
  • Documentation

    • Added a changelog entry describing the improved mock function metadata behavior.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b07984fe-9208-4499-b4a4-afce6130e08c

📥 Commits

Reviewing files that changed from the base of the PR and between c86835f and 0f8cff8.

📒 Files selected for processing (3)
  • changelog.d/7099-node-test-mock-name-length.md
  • crates/perry-runtime/src/node_submodules/test.rs
  • crates/perry-runtime/src/node_submodules/test_metadata_unit_tests.rs

📝 Walkthrough

Walkthrough

node:test mock functions now preserve callable names, argument lengths, and property descriptors. Mock creation also roots relevant values through RuntimeHandleScope, with unit coverage and a changelog entry.

Changes

Mock Function Metadata

Layer / File(s) Summary
Metadata extraction and rooted mock creation
crates/perry-runtime/src/node_submodules/test.rs
Mock creation derives callable names and lengths, roots relevant values, and applies metadata to generated closures.
Metadata descriptor validation
crates/perry-runtime/src/node_submodules/test.rs, crates/perry-runtime/src/node_submodules/test_metadata_unit_tests.rs
Unit tests verify preserved name, arity, and non-writable, non-enumerable, configurable name and length properties.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preserving metadata for node:test mock functions.
Description check ✅ Passed The description explains the changes, references issue #6767, and lists concrete verification commands, though it omits several template headings and checklist items.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug
proggeramlug merged commit e2557c1 into PerryTS:main Jul 31, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant