refactor!: replace loupe.inspect with pretty-format#9609
Draft
hi-ogawa wants to merge 34 commits intovitest-dev:mainfrom
Draft
refactor!: replace loupe.inspect with pretty-format#9609hi-ogawa wants to merge 34 commits intovitest-dev:mainfrom
loupe.inspect with pretty-format#9609hi-ogawa wants to merge 34 commits intovitest-dev:mainfrom
Conversation
loupe.inspect with pretty-formatloupe.inspect with pretty-format
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Cover value types (primitives, collections, built-ins), existing options (indent, maxDepth, maxWidth, min, compareKeys, callToJSON, escapeString, escapeRegex, printBasicPrototype, printFunctionName), new PR options (singleQuote, quoteKeys, spacingInner, spacingOuter), ErrorPlugin, and custom plugin API. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add INSPECT_OPTIONS and prettyInspect() as the unified replacement for inspect() and objDisplay(). Uses stringify with inspect-like options (singleQuote, quoteKeys: false, min, spaced) and surface-level truncation (structural summaries for containers, ellipsis for scalars). Refactor conformance tests to use prettyInspect from @vitest/utils/display instead of a local wrapper with duplicated options. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
hi-ogawa
commented
Mar 6, 2026
Comment on lines
-282
to
-294
| describe('objDisplay', () => { | ||
| test.each` | ||
| value | expected | ||
| ${'a'.repeat(100)} | ${`'${'a'.repeat(37)}…'`} | ||
| ${'🐱'.repeat(100)} | ${`'${'🐱'.repeat(18)}…'`} | ||
| ${`a${'🐱'.repeat(100)}…`} | ${`'a${'🐱'.repeat(18)}…'`} | ||
| `('Do not truncate strings anywhere but produce valid unicode strings for $value', ({ value, expected }) => { | ||
| // encodeURI can be used to detect invalid strings including invalid code-points | ||
| // note: our code should not split surrogate pairs, but may split graphemes | ||
| expect(() => encodeURI(objDisplay(value))).not.toThrow() | ||
| expect(objDisplay(value)).toEqual(expected) | ||
| }) | ||
| }) |
Collaborator
Author
There was a problem hiding this comment.
Similar test exists in pretty-format.test.ts, so removed from here.
Comment on lines
+236
to
+238
| // if stringify's adaptive maxDepth (down to 1) fails to truncate enough, | ||
| // - for known types (e.g. string, object), do something reasonable. | ||
| // - for other values, fallback to maxDepth = 0 which should show minimal output (though it can technically exeed the threshold for some cases) |
Collaborator
Author
There was a problem hiding this comment.
Truncation implementation is very poor compared to loupe, but I think this should get quite far in practice.
Comment on lines
+1031
to
+1032
| // TODO: introduce new option | ||
| return inspect(value, { truncate: runner?.config?.chaiConfig?.truncateThreshold ?? 40 }) |
Collaborator
Author
There was a problem hiding this comment.
The same option is reused for our inspect for now.
7 tasks
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
pretty-formatandinspect#9582Summary
loupedependency in@vitest/utilswith@vitest/pretty-formatfor all value inspection (test titles, error display, assertion messages (onlytoHavePropertywas usingobjDisplaydirectly))inspect(),objDisplay(),baseFormat(),format(), andbrowserFormat()into two clean exports:inspect()andformat()@vitest/pretty-format:inspectstyle formatting, new options are added, but there are still some discrepeancy.pretty-format.test.tsshould show almost full coverage including how three inspects (vitest, node, loupe) differ each other.@vitest/utils/displayexports:inspect(obj, loupeOptions)inspect(obj, { truncate?, multiline? ... })objDisplay(obj, loupeOptions)inspectwithtruncate)format(...args)format(args, options?)— signature changed from rest params to arraybrowserFormat(...args)format(args, { multiline: true }))baseFormat(args, options)format)Breaking changes
Since this changes
test.for/eachtitle formatting, this is considered a breaking change.Question: truncation config
For
test.for/eachtitle object formatting, the old behavior supported configuring truncation throughchaiConfig.truncateThresholdwith defaulttruncate: 40. This PR inherits the same behavior, but I think we should introduce a separate option since we now own the formatting and relevant to chai nor loupe. Perhaps, this can be follow-up.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:.