Skip to content

fix(node:test): support symbol keyed mock methods - #7102

Open
proggeramlug wants to merge 2 commits into
mainfrom
fix/6767-node-test-mock-symbol
Open

fix(node:test): support symbol keyed mock methods#7102
proggeramlug wants to merge 2 commits into
mainfrom
fix/6767-node-test-mock-symbol

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Addresses node-suite/test/mock-fn/symbol-method in #6767.

mock.method() now accepts Symbol keys, reads and replaces the symbol-keyed implementation through Perry's symbol property side table, and reproduces Node 26.5's observable Symbol restore behavior. A failed invocation after restore is tracked and rethrown as TypeError, matching the oracle output.

Validation:

  • cargo check -p perry-runtime
  • ./run_parity_tests.sh --suite node-suite --module test --filter symbol-method (1/1, 100%)
  • neighboring inherited-method, method-receiver, and method-restore-chain fixtures remain exact-parity passes

Summary by CodeRabbit

  • New Features

    • Added support for mocking methods keyed by JavaScript Symbols through node:test.
    • Symbol-keyed mocks now support call tracking, restoration, and behavior consistent with Node.js.
    • Mocked Symbol methods can be used alongside regular object methods.
  • Bug Fixes

    • Improved handling of restored Symbol methods, including appropriate errors when invoked without an implementation.
    • Restored Symbol methods now correctly return to their unavailable state.

@coderabbitai

coderabbitai Bot commented Jul 31, 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: 0a2cd3af-4f62-41c7-9b0b-b1450316d66f

📥 Commits

Reviewing files that changed from the base of the PR and between 17498c8 and 9ca323f.

📒 Files selected for processing (2)
  • changelog.d/7102-node-test-mock-symbol.md
  • crates/perry-runtime/src/node_submodules/test.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • changelog.d/7102-node-test-mock-symbol.md
  • crates/perry-runtime/src/node_submodules/test.rs

📝 Walkthrough

Walkthrough

Adds node:test support for mocking Symbol-keyed object methods, including symbol-property access, call tracking, TypeError behavior for missing implementations, and restoration semantics.

Changes

Symbol-Named Mock Methods

Layer / File(s) Summary
Symbol method detection and restore state
crates/perry-runtime/src/node_submodules/test.rs
The mock method setup detects symbol properties, accesses them through symbol APIs, and records a symbol-specific restore target.
Symbol method invocation and restoration
crates/perry-runtime/src/node_submodules/test.rs, changelog.d/7102-node-test-mock-symbol.md
Symbol mocks clear their implementation during restoration and record then throw a TypeError when invoked without one. The changelog documents this behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • PerryTS/perry#7096: Modifies the same runtime test module and extends related node:test behavior.

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: adding support for Symbol-keyed mock methods in node:test.
Description check ✅ Passed The description covers the change, related issue, implementation details, and validation results, although it does not use the template headings or checklist.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/6767-node-test-mock-symbol

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 force-pushed the fix/6767-node-test-mock-symbol branch from 17498c8 to 9ca323f Compare July 31, 2026 02:01
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