Skip to content

Commit 1ec61ce

Browse files
authored
fix(utils): Produce valid snapshot names (#5724)
1 parent 3270663 commit 1ec61ce

File tree

3 files changed

+25
-40
lines changed

3 files changed

+25
-40
lines changed

packages/utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"dependencies": {
6464
"diff-sequences": "^29.6.3",
6565
"estree-walker": "^3.0.3",
66-
"loupe": "^3.1.0",
66+
"loupe": "^3.1.1",
6767
"pretty-format": "^29.7.0"
6868
},
6969
"devDependencies": {

pnpm-lock.yaml

Lines changed: 9 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/core/test/utils.spec.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { beforeAll, describe, expect, test } from 'vitest'
2-
import { assertTypes, deepClone, objectAttr, toArray } from '@vitest/utils'
2+
import { assertTypes, deepClone, objDisplay, objectAttr, toArray } from '@vitest/utils'
33
import { deepMerge, resetModules } from '../../../packages/vitest/src/utils'
44
import { deepMergeSnapshot } from '../../../packages/snapshot/src/port/utils'
55
import type { EncodedSourceMap } from '../../../packages/vite-node/src/types'
@@ -271,3 +271,17 @@ describe('objectAttr', () => {
271271
expect(objectAttr(value, path)).toEqual(expected)
272272
})
273273
})
274+
275+
describe('objDisplay', () => {
276+
test.each`
277+
value | expected
278+
${'a'.repeat(100)} | ${`'${'a'.repeat(37)}…'`}
279+
${'🐱'.repeat(100)} | ${`'${'🐱'.repeat(18)}…'`}
280+
${`a${'🐱'.repeat(100)}…`} | ${`'a${'🐱'.repeat(18)}…'`}
281+
`('Do not truncate strings anywhere but produce valid unicode strings for $value', ({ value, expected }) => {
282+
// encodeURI can be used to detect invalid strings including invalid code-points
283+
// note: our code should not split surrogate pairs, but may split graphemes
284+
expect(() => encodeURI(objDisplay(value))).not.toThrow()
285+
expect(objDisplay(value)).toEqual(expected)
286+
})
287+
})

0 commit comments

Comments
 (0)