Skip to content

Commit b86bf0d

Browse files
authored
fix: print uint and buffer as a simple string (#8141)
1 parent 44940d9 commit b86bf0d

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

packages/utils/src/error.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ export function serializeValue(val: any, seen: WeakMap<WeakKey, any> = new WeakM
6060
if (typeof val !== 'object') {
6161
return val
6262
}
63+
if (typeof Buffer !== 'undefined' && val instanceof Buffer) {
64+
return `<Buffer(${val.length}) ...>`
65+
}
66+
if (typeof Uint8Array !== 'undefined' && val instanceof Uint8Array) {
67+
return `<Uint8Array(${val.length}) ...>`
68+
}
6369
// cannot serialize immutables as immutables
6470
if (isImmutable(val)) {
6571
return serializeValue(val.toJSON(), seen)

packages/vitest/src/node/printError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function printErrorInner(
130130
: stacks.find((stack) => {
131131
try {
132132
return (
133-
project.server
133+
project._vite
134134
&& project.getModuleById(stack.file)
135135
&& existsSync(stack.file)
136136
)

test/cli/test/print-error.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,19 @@ CustomError: custom error
4141
Serialized Error: { stack: [ 'custom stack 1', 'custom stack 2' ] }
4242
`.trim())
4343
})
44+
45+
test('prints buffer and UintArray', async () => {
46+
const { stderr } = await runInlineTests({
47+
'basic.test.ts': `
48+
test('failed test', () => {
49+
throw {
50+
buffer: Buffer.from([1, 2, 3]),
51+
uintarray: Uint8Array.from([1, 2, 3]),
52+
}
53+
})
54+
`,
55+
}, { globals: true })
56+
57+
expect(stderr).toContain(`buffer: '<Buffer(3) ...>'`)
58+
expect(stderr).toContain(`uintarray: '<Uint8Array(3) ...>'`)
59+
})

0 commit comments

Comments
 (0)