Skip to content

fix(pretty-format): fix output limit over counting#9965

Merged
sheremet-va merged 4 commits intovitest-dev:mainfrom
hi-ogawa:fix-pretty-format-fix-output-limit-over-counting
Mar 25, 2026
Merged

fix(pretty-format): fix output limit over counting#9965
sheremet-va merged 4 commits intovitest-dev:mainfrom
hi-ogawa:fix-pretty-format-fix-output-limit-over-counting

Conversation

@hi-ogawa
Copy link
Collaborator

@hi-ogawa hi-ogawa commented Mar 24, 2026

Description

Previous approach's single outputLength counter had an issue that it over counts deeper children multiple times due to tree structure. Pictoricaly it looks like:

total output: [================================================================]

depth 1:      [==========A==========]  [==========B==========]  [=====C=====]
depth 2:      [=a1=] [=a2=] [=a3=]     [==b1==] [==b2==]        [=c1=]
depth 3:      [x][y]  [z]              [p] [q]                   [r]

A different idea in this PR is to accumulate print length per depth and trigger maxDepth = 0 bail 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

  • PR 9949: Actual format length limit ~= maxOutputLength / Average depth
    • This is because the output of children at depth n contributes to outputLength counter for n times
  • This PR: Actual format length limit ~= maxOutputLength * Average depth
    • This is because outputLengthPerDepth is 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:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify
Copy link

netlify bot commented Mar 24, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 42e140d
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69c26945ed27780008a85522
😎 Deploy Preview https://deploy-preview-9965--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 25, 2026

@vitest/browser

npm i https://pkg.pr.new/@vitest/browser@9965

@vitest/browser-playwright

npm i https://pkg.pr.new/@vitest/browser-playwright@9965

@vitest/browser-preview

npm i https://pkg.pr.new/@vitest/browser-preview@9965

@vitest/browser-webdriverio

npm i https://pkg.pr.new/@vitest/browser-webdriverio@9965

@vitest/coverage-istanbul

npm i https://pkg.pr.new/@vitest/coverage-istanbul@9965

@vitest/coverage-v8

npm i https://pkg.pr.new/@vitest/coverage-v8@9965

@vitest/expect

npm i https://pkg.pr.new/@vitest/expect@9965

@vitest/mocker

npm i https://pkg.pr.new/@vitest/mocker@9965

@vitest/pretty-format

npm i https://pkg.pr.new/@vitest/pretty-format@9965

@vitest/runner

npm i https://pkg.pr.new/@vitest/runner@9965

@vitest/snapshot

npm i https://pkg.pr.new/@vitest/snapshot@9965

@vitest/spy

npm i https://pkg.pr.new/@vitest/spy@9965

@vitest/ui

npm i https://pkg.pr.new/@vitest/ui@9965

@vitest/utils

npm i https://pkg.pr.new/@vitest/utils@9965

vitest

npm i https://pkg.pr.new/vitest@9965

@vitest/web-worker

npm i https://pkg.pr.new/@vitest/web-worker@9965

@vitest/ws-client

npm i https://pkg.pr.new/@vitest/ws-client@9965

commit: 696730d

@hi-ogawa hi-ogawa marked this pull request as ready for review March 25, 2026 00:46
@sheremet-va sheremet-va merged commit d3b7a40 into vitest-dev:main Mar 25, 2026
17 of 18 checks passed
@hi-ogawa hi-ogawa deleted the fix-pretty-format-fix-output-limit-over-counting branch March 25, 2026 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Snapshots do not render completely anymore since 4.1.1

2 participants