fix(pretty-format): fix output limit over counting#9965
Merged
sheremet-va merged 4 commits intovitest-dev:mainfrom Mar 25, 2026
Merged
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
@vitest/browser
@vitest/browser-playwright
@vitest/browser-preview
@vitest/browser-webdriverio
@vitest/coverage-istanbul
@vitest/coverage-v8
@vitest/expect
@vitest/mocker
@vitest/pretty-format
@vitest/runner
@vitest/snapshot
@vitest/spy
@vitest/ui
@vitest/utils
vitest
@vitest/web-worker
@vitest/ws-client
commit: |
6 tasks
sheremet-va
approved these changes
Mar 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Previous approach's single
outputLengthcounter had an issue that it over counts deeper children multiple times due to tree structure. Pictoricaly it looks like:A different idea in this PR is to accumulate print length per depth and trigger
maxDepth = 0bail out at any depth. And this is indeed what Node actually does https://github.com/nodejs/node/blob/61102cdbb3d59155ad5bb4fc9419627a31e63f7a/lib/internal/util/inspect.js#L1486-L1498 (My last agent research note said this but I totally overlooked 🤦)However notably neither of approach is an exact total length tracking and they are only heuristics that get skewed by input object's nesting structure and depth factor. Rough estimation of length limit guarantee is
Actual format length limit ~= maxOutputLength / Average depthncontributes tooutputLengthcounter forntimesActual format length limit ~= maxOutputLength * Average depthoutputLengthPerDepthis per depth accumulation.I'm not entirely sure the practical impact between two, so this is entirely an educated guess, but this PR has chosen the 2nd approach instead of bumping up limit with 1st approach.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.