Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 21e66ff

Browse filesBrowse files
hi-ogawacodex
andauthored
fix(snapshot): increase default snapshot max output length (#10150)
Co-authored-by: Codex <noreply@openai.com>
1 parent bb4829a commit 21e66ff
Copy full SHA for 21e66ff

3 files changed

+87Lines changed: 87 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/pretty-format/USAGE.md‎

Copy file name to clipboardExpand all lines: packages/pretty-format/USAGE.md
+3Lines changed: 3 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ Snapshots use `@vitest/pretty-format` with snapshot-specific defaults such as:
117117
- `escapeString: false`
118118
- `escapeRegex: true`
119119
- `printFunctionName: false`
120+
- `maxOutputLength: 2 ** 27`
121+
122+
Snapshots use a more generous safety cap than the package default. The default `maxOutputLength` is tuned for general-purpose formatting such as logs and error messages, while snapshot users may intentionally persist large serialized values to dedicated files. Users can still opt into a smaller cap through `test.snapshotFormat.maxOutputLength`.
120123

121124
Default snapshot plugin stack:
122125

Collapse file

‎packages/snapshot/src/port/state.ts‎

Copy file name to clipboardExpand all lines: packages/snapshot/src/port/state.ts
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ export default class SnapshotState {
112112
this._snapshotFormat = {
113113
printBasicPrototype: false,
114114
escapeString: false,
115+
// more generous safety cap 128MB (same as Node's util.inspect)
116+
// instead of tighter pretty-format default 1MB
117+
// since users can purposely save large snapshot to a dedicated file.
118+
maxOutputLength: 2 ** 27,
115119
...options.snapshotFormat,
116120
}
117121
this._environment = options.snapshotEnvironment
Collapse file
+80Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { describe, expect, test } from 'vitest'
2+
import { runInlineTests } from '../../test-utils'
3+
4+
describe('maxOutputLength', () => {
5+
test('default', async () => {
6+
const result = await runInlineTests(
7+
{
8+
'basic.test.ts': `
9+
import { expect, test } from 'vitest'
10+
11+
test('large snapshot', () => {
12+
expect(Array.from({ length: 500_000 }, (_, i) => ({ i }))).toMatchSnapshot()
13+
})
14+
`,
15+
},
16+
{
17+
update: 'all',
18+
},
19+
)
20+
21+
expect(result.stderr).toMatchInlineSnapshot(`""`)
22+
const snapshot = result.fs.readFile('__snapshots__/basic.test.ts.snap')
23+
expect(snapshot.slice(-50)).toMatchInlineSnapshot(`
24+
" "i": 499998,
25+
},
26+
{
27+
"i": 499999,
28+
},
29+
]
30+
\`;
31+
"
32+
`)
33+
expect(snapshot.length).toMatchInlineSnapshot(`12888992`)
34+
})
35+
36+
test('override', async () => {
37+
const result = await runInlineTests(
38+
{
39+
'basic.test.ts': `
40+
import { expect, test } from 'vitest'
41+
42+
test('large snapshot', () => {
43+
expect(Array.from({ length: 8 }, (_, i) => ({ i }))).toMatchSnapshot()
44+
})
45+
`,
46+
},
47+
{
48+
update: 'all',
49+
snapshotFormat: {
50+
maxOutputLength: 50,
51+
},
52+
},
53+
)
54+
55+
expect(result.stderr).toMatchInlineSnapshot(`""`)
56+
expect(result.fs.readFile('__snapshots__/basic.test.ts.snap')).toMatchInlineSnapshot(`
57+
"// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
58+
59+
exports[\`large snapshot 1\`] = \`
60+
[
61+
{
62+
"i": 0,
63+
},
64+
{
65+
"i": 1,
66+
},
67+
{
68+
"i": 2,
69+
},
70+
[Object],
71+
[Object],
72+
[Object],
73+
[Object],
74+
[Object],
75+
]
76+
\`;
77+
"
78+
`)
79+
})
80+
})

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.