|
1 | 1 | 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' |
3 | 3 | import { deepMerge, resetModules } from '../../../packages/vitest/src/utils' |
4 | 4 | import { deepMergeSnapshot } from '../../../packages/snapshot/src/port/utils' |
5 | 5 | import type { EncodedSourceMap } from '../../../packages/vite-node/src/types' |
@@ -271,3 +271,17 @@ describe('objectAttr', () => { |
271 | 271 | expect(objectAttr(value, path)).toEqual(expected) |
272 | 272 | }) |
273 | 273 | }) |
| 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