Skip to content

Commit 2f37cce

Browse files
authored
docs: Improve onStackTrace docs to include limitations and tips (#8905)
1 parent 2e7b2b8 commit 2f37cce

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

docs/config/index.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,17 +1927,21 @@ export default defineConfig({
19271927

19281928
- **Type**: `(error: Error, frame: ParsedStack) => boolean | void`
19291929

1930-
Apply a filtering function to each frame of each stack trace when handling errors. The first argument, `error`, is an object with the same properties as a standard `Error`, but it is not an actual instance.
1930+
Apply a filtering function to each frame of each stack trace when handling errors. This does not apply to stack traces printed by [`printConsoleTrace`](#printConsoleTrace). The first argument, `error`, is a `TestError`.
19311931

19321932
Can be useful for filtering out stack trace frames from third-party libraries.
19331933

1934+
::: tip
1935+
The stack trace's total size is also typically limited by V8's [`Error.stackTraceLimit`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/stackTraceLimit) number. You could set this to a high value in your test setup function to prevent stacks from being truncated.
1936+
:::
1937+
19341938
```ts
1935-
import type { ParsedStack } from 'vitest'
1939+
import type { ParsedStack, TestError } from 'vitest'
19361940
import { defineConfig } from 'vitest/config'
19371941
19381942
export default defineConfig({
19391943
test: {
1940-
onStackTrace(error: Error, { file }: ParsedStack): boolean | void {
1944+
onStackTrace(error: TestError, { file }: ParsedStack): boolean | void {
19411945
// If we've encountered a ReferenceError, show the whole stack.
19421946
if (error.name === 'ReferenceError') {
19431947
return

0 commit comments

Comments
 (0)