Skip to content

💥 Merge asyncToStringMethod into toStringMethod - #7181

Open
dubzzz wants to merge 1 commit into
next-v4_9_0from
claude/merge-tostring-symbols-2qwbsa
Open

💥 Merge asyncToStringMethod into toStringMethod#7181
dubzzz wants to merge 1 commit into
next-v4_9_0from
claude/merge-tostring-symbols-2qwbsa

Conversation

@dubzzz

@dubzzz dubzzz commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Description

AI-agent disclosure: this PR was authored by an automated agent (Claude Code) and has not been line-by-line reviewed by a human before submission.

In the past we used to have two symbols to declare a custom serializer on an instance: toStringMethod for synchronous contexts and asyncToStringMethod for asynchronous ones.

The two got merged into a single one: toStringMethod. Its serializer can now return either a string or a promise of string. In other words, users previously relying on asyncToStringMethod just have to declare the same serializer on toStringMethod.

Breaking changes (impact flagged as major via a changeset):

  • asyncToStringMethod, WithAsyncToStringMethod and hasAsyncToStringMethod are dropped from the public API. Migration: replace asyncToStringMethod by toStringMethod.
  • WithToStringMethod now declares () => string | Promise<string> instead of () => string.
  • toStringMethod is now invoked even in synchronous contexts when its output turns out to be a promise (its output simply cannot be leveraged there and fast-check falls back to its default serialization). Previously asyncToStringMethod was never called in synchronous contexts.

Promise-based outputs keep the exact same constraints as asyncToStringMethod had: they are only exploited by asynchronous properties and must resolve almost instantly.

This PR follows the same direction as previous merges of the sync/async pairs (see the merge of asyncReporter into reporter in #7178): with asynchronous properties being the sole way to create properties, keeping two symbols for the same concern was no longer justified.

The PR is focused on that single concern. Internal users of the symbols were updated accordingly: func, streamOf and commands now expose a single toStringMethod returning a string when serialization can be done synchronously and a promise otherwise. Existing tests on stringify/asyncStringify and CommandWrapper were adapted to the merged symbol — among others they check that Promise-based outputs are used in asynchronous contexts and properly fall back in synchronous ones, and they would have failed without this PR. Documentation (custom-reports.md) was updated too.

Checklist

Don't delete this checklist and make sure you do the following before opening the PR

  • I have a full understanding of every line in this PR — whether the code was hand-written, AI-generated, copied from external sources or produced by any other tool
  • I flagged the impact of my change (minor / patch / major) either by running pnpm run bump or by following the instructions from the changeset bot
  • I kept this PR focused on a single concern and did not bundle unrelated changes
  • I followed the gitmoji specification for the name of the PR, including the package scope (e.g. 🐛(vitest) Something...) when the change targets a package other than fast-check
  • I added relevant tests and they would have failed without my PR (when applicable)

🤖 Generated with Claude Code

https://claude.ai/code/session_019H4rz5zF7PTMQK6JCFWh9o


Generated by Claude Code

@changeset-bot

changeset-bot Bot commented Jul 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 734f883

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
fast-check Major
@fast-check/ava Patch
@fast-check/jest Patch
@fast-check/vitest Patch
@fast-check/worker Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 25, 2026

Copy link
Copy Markdown
@fast-check/ava

npm i https://pkg.pr.new/@fast-check/ava@7181

fast-check

npm i https://pkg.pr.new/fast-check@7181

@fast-check/jest

npm i https://pkg.pr.new/@fast-check/jest@7181

@fast-check/packaged

npm i https://pkg.pr.new/@fast-check/packaged@7181

@fast-check/poisoning

npm i https://pkg.pr.new/@fast-check/poisoning@7181

@fast-check/vitest

npm i https://pkg.pr.new/@fast-check/vitest@7181

@fast-check/worker

npm i https://pkg.pr.new/@fast-check/worker@7181

commit: 734f883

In the past we used to have two symbols to define custom serializers for
instances: `toStringMethod` for synchronous contexts and
`asyncToStringMethod` for asynchronous ones.

The two got merged into a single `toStringMethod`: its serializer can now
return either a string or a promise of string. Promise-based outputs keep
being exploited only in asynchronous contexts.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019H4rz5zF7PTMQK6JCFWh9o
@dubzzz
dubzzz force-pushed the claude/merge-tostring-symbols-2qwbsa branch from c4916ff to 734f883 Compare July 25, 2026 08:11
@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.50%. Comparing base (a22e3fb) to head (734f883).

Additional details and impacted files
@@               Coverage Diff               @@
##           next-v4_9_0    #7181      +/-   ##
===============================================
- Coverage        95.50%   95.50%   -0.01%     
===============================================
  Files              206      206              
  Lines             5274     5272       -2     
  Branches          1470     1471       +1     
===============================================
- Hits              5037     5035       -2     
  Misses             229      229              
  Partials             8        8              
Flag Coverage Δ
tests 95.50% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.

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.

2 participants