Skip to content

feat(helpers): resolve functions from prototypes in fake - #3970

Open
hugosmoreira wants to merge 4 commits into
faker-js:nextfrom
hugosmoreira:agent/fix-helpers-fake-instance-members
Open

feat(helpers): resolve functions from prototypes in fake#3970
hugosmoreira wants to merge 4 commits into
faker-js:nextfrom
hugosmoreira:agent/fix-helpers-fake-instance-members

Conversation

@hugosmoreira

Copy link
Copy Markdown

Summary

  • resolve properties on primitive values returned by fakeEval
  • bind generated object and primitive methods to their source value
  • document member chaining for fakeEval and helpers.fake
  • add regression coverage for implicit and explicit calls, properties, prototype methods, and constructor-chain safety

Root cause

The expression resolver only followed properties on objects. When a Faker method returned a primitive, the chain stopped; when it returned an object method such as Date.prototype.toISOString, the method was later invoked without its receiver.

The resolver now boxes supported primitives for property lookup and binds callable properties to the generated value. Functions returned by functions still use the existing recursive resolution path, preserving the constructor-chain protection added for GHSA-qxc2-j82w-r537.

Validation

  • pnpm run preflight
    • 55 test files passed
    • 52,740 tests passed
    • TypeScript checks passed
  • targeted helpers suites: 862 tests passed

Closes #3465

This contribution was developed and validated with OpenAI Codex assistance.

@hugosmoreira
hugosmoreira requested a review from a team as a code owner July 27, 2026 05:49
@netlify

netlify Bot commented Jul 27, 2026

Copy link
Copy Markdown

Deploy Preview for fakerjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 831c6ce
🔍 Latest deploy log https://app.netlify.com/projects/fakerjs/deploys/6a67b038336e6700088e559f
😎 Deploy Preview https://deploy-preview-3970.fakerjs.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment thread src/modules/helpers/module.ts
Comment thread src/modules/helpers/eval.ts Outdated
@ST-DDT ST-DDT added c: feature Request for new feature p: 1-normal Nothing urgent m: helpers Something is referring to the helpers module labels Jul 27, 2026
@ST-DDT ST-DDT added this to the v10.x milestone Jul 27, 2026
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.88%. Comparing base (717fa14) to head (831c6ce).

Files with missing lines Patch % Lines
src/modules/helpers/eval.ts 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #3970      +/-   ##
==========================================
- Coverage   98.91%   98.88%   -0.03%     
==========================================
  Files         924      924              
  Lines        3224     3229       +5     
  Branches      585      569      -16     
==========================================
+ Hits         3189     3193       +4     
- Misses         31       32       +1     
  Partials        4        4              
Files with missing lines Coverage Δ
src/modules/helpers/module.ts 94.84% <ø> (ø)
src/modules/helpers/eval.ts 97.29% <83.33%> (-1.26%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 improves helpers.fake / fakeEval expression resolution so member access continues after generated primitive values and callable members are invoked with the correct receiver (this), fixing failures when chaining prototype methods (e.g., toISOString, trim, toPrecision).

Changes:

  • Extend property resolution to box primitive generated values so properties and prototype members can be accessed after faker method calls.
  • Bind callable resolved members to their source value to preserve correct receiver semantics.
  • Add documentation and regression tests covering property/method chaining and constructor-chain safety.

Reviewed changes

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

File Description
src/modules/helpers/eval.ts Updates the resolver to box primitives for property lookup and bind callable properties to the generated value.
src/modules/helpers/module.ts Documents member/property chaining behavior for helpers.fake.
test/modules/helpers.spec.ts Adds regression coverage for helpers.fake chaining on primitives and prototype methods.
test/modules/helpers-eval.spec.ts Adds regression coverage for fakeEval chaining (implicit/explicit calls) and extends the GHSA constructor-chain safety suite.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/modules/helpers/eval.ts
Comment thread src/modules/helpers/module.ts Outdated
Comment thread src/modules/helpers/eval.ts
Comment thread src/modules/helpers/eval.ts Outdated
Comment thread src/modules/helpers/module.ts
@ST-DDT ST-DDT changed the title fix(helpers): resolve generated value members feat(helpers): resolve functions from prototypes in fake Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: feature Request for new feature m: helpers Something is referring to the helpers module p: 1-normal Nothing urgent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

helpers.fake - patterns after root expression fail when referencing instance members

4 participants