Skip to content

Commit

Permalink
fix(utils): Produce valid snapshot names (#5724)
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz authored May 15, 2024
1 parent 3270663 commit 1ec61ce
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 40 deletions.
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"dependencies": {
"diff-sequences": "^29.6.3",
"estree-walker": "^3.0.3",
"loupe": "^3.1.0",
"loupe": "^3.1.1",
"pretty-format": "^29.7.0"
},
"devDependencies": {
Expand Down
47 changes: 9 additions & 38 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion test/core/test/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { beforeAll, describe, expect, test } from 'vitest'
import { assertTypes, deepClone, objectAttr, toArray } from '@vitest/utils'
import { assertTypes, deepClone, objDisplay, objectAttr, toArray } from '@vitest/utils'
import { deepMerge, resetModules } from '../../../packages/vitest/src/utils'
import { deepMergeSnapshot } from '../../../packages/snapshot/src/port/utils'
import type { EncodedSourceMap } from '../../../packages/vite-node/src/types'
Expand Down Expand Up @@ -271,3 +271,17 @@ describe('objectAttr', () => {
expect(objectAttr(value, path)).toEqual(expected)
})
})

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)
})
})

0 comments on commit 1ec61ce

Please sign in to comment.