[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix(snapshot): increase default snapshot max output length (#10150)

Co-authored-by: Codex <noreply@openai.com>

authored by

Hiroshi Ogawa
Codex
and committed by
GitHub
(Apr 15, 2026, 8:23 AM +0200) 21e66ff6 bb4829ad

+87
+3
packages/pretty-format/USAGE.md
··· 117 117 - `escapeString: false` 118 118 - `escapeRegex: true` 119 119 - `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`. 120 123 121 124 Default snapshot plugin stack: 122 125
+80
test/snapshots/test/options.test.ts
··· 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 + })
+4
packages/snapshot/src/port/state.ts
··· 112 112 this._snapshotFormat = { 113 113 printBasicPrototype: false, 114 114 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, 115 119 ...options.snapshotFormat, 116 120 } 117 121 this._environment = options.snapshotEnvironment