← Back to Pull requests

Add mock.property to node:test #8383

Merged
littledivy merged 2 files (429 lines) on Nov 12, 2026 15:38 UTC
View on GitHub
littledivy littledivy commented on Nov 12, 2026 04:38 UTC
Author

Node v24.3.0 added mock.property(object, propertyName[, value]) to the node:test MockTracker, but workerd's port only has fn, method, getter and setter, so code that mocks a plain data property fails with mock.property is not a function.

In this patch:

  • MockPropertyContext and MockTracker.property are ported from Node's lib/internal/test_runner/mock/mock.js, with accesses, accessCount(), mockImplementation(), mockImplementationOnce(), resetAccesses() and restore().

  • Each tracked mock now stores its own restore function, as in Node, so reset() and restoreAll() restore property mocks too.

  • Node's mock.property tests from test-runner-mocking.js are ported. The one that relies on per-test t.mock auto-restore is replaced with a restoreAll()/reset() check, since workerd's node:test has no per-test context.
  • | | Before | After |
    |---|---|---|
    | mock.property(obj, 'foo', 42) | TypeError: mock.property is not a function | proxy where obj.foo === 42 |
    | prop.mock.accessCount() | n/a | 1 after one read |
    | mock.restoreAll() | n/a | obj.foo back to its original value |

    This adds a method that is only reachable through node:test under nodejs_compat, so it ships without a compatibility flag.

    Diff: 429 lines (+425 / -4) across 2 files Reviewer: ryanking13 Review duration: 660m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.41) × (1 − Review Confidence (0.56)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.41 · 429 lines diff across 2 files
    0.41
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.12 · 1 substantive comment(s)
    0.12
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.363
    Shallow Review Depth shallow_review_depth
    0.309
    Real PR Conversation Timeline
    4 items
    clanky-the-clanker[bot] clanky-the-clanker[bot] commented on Nov 12, 2026 04:40 UTC
    Reviewer

    <!-- durable-reviewer:review run=75adf01c-9508-48a1-a3b2-4fd2e1f7d58e -->

    ✅ Approved — A faithful port of Node's mock.property with matching tests; no correctness, security, performance or documentation issues found.

    <sub>The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.</sub>

    ---

    <details>
    <summary>✅ All checks passed</summary>

    🔒 Security: ✅ LGTM

    No security concerns. This is test-runner instrumentation that can only be reached through node:test.

    ---

    📖 AGENTS.md: ✅ LGTM

    No issues found.

    ---

    📋 Code Quality: ✅ LGTM

    No issues found. The per-mock restore function is wired up the same way for function mocks and property mocks.

    ---

    ⚡ Performance: ✅ LGTM

    No performance issues. Recording an access record and stack for each property access is opt-in test instrumentation, and resetAccesses() clears it.

    ---

    📝 Documentation: ✅ LGTM

    No issues found.

    </details>

    ---
    <sub>Reviewed commit: d22988e7</sub>

    ryanking13 ryanking13 approved these changes on Nov 12, 2026 06:01 UTC
    Approved Reviewer

    Approved these changes.

    jasnell jasnell approved these changes on Nov 12, 2026 15:38 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    littledivy littledivy
    Labels
    risk: low confidence: 56.3% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.7% (MEDIUM) · Higher = larger blast radius
    40.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.3% · Lower = rushed or shallow review
    56.3%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.8% · Safe to merge
    17.8%