Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to filter the stack trace #1999

Closed
4 tasks done
aleclarson opened this issue Sep 7, 2022 · 2 comments · Fixed by #4338
Closed
4 tasks done

Ability to filter the stack trace #1999

aleclarson opened this issue Sep 7, 2022 · 2 comments · Fixed by #4338
Labels
enhancement New feature or request good first issue Good for newcomers pr welcome

Comments

@aleclarson
Copy link
Contributor

Clear and concise description of the problem

In some cases, stack traces contain a bunch of lines from third party packages, and I would prefer to omit those lines from the stack trace, as it's extremely unlikely that I need to be aware of them.

Suggested solution

Add an option like filterStack that takes a function that receives a file path and returns a boolean to indicate whether the stack frame should be removed from the trace. This is what I do in Saus (my Vite-based framework), and it works great.

Alternative

No response

Additional context

No response

Validations

@sheremet-va sheremet-va added the enhancement New feature or request label Sep 8, 2022
@g4rry420
Copy link
Contributor

@aleclarson Can you please update this link - it works great. ? I wanted to take a look into it.

@sheremet-va
Copy link
Member

sheremet-va commented Oct 4, 2023

Vitest already parses error stack traces, so this feature should be straightforward to implement. We can do the same thing we did for console log filtering: https://vitest.dev/config/#onconsolelog

export default defineConfig({
  test: {
    onStackTrace({ method, file, line, column }) {
      if(file.includes('unexpected')) return false
    }
  }
})

This is where parsing happens:

export function parseErrorStacktrace(e: ErrorWithDiff, options: StackTraceParserOptions = {}): ParsedStack[] {

clarkf added a commit to clarkf/vitest that referenced this issue Oct 19, 2023
This change introduces a new optional configuration parameter,
`onStackTrace`. If included, each frame of each error stacktrace
encountered during the test run will be tested by the provided
function. If the test fails, the frame will be omitted from the
displayed trace.
clarkf added a commit to clarkf/vitest that referenced this issue Oct 19, 2023
This change introduces a new optional configuration parameter,
`onStackTrace`. If included, each frame of each error stacktrace
encountered during the test run will be tested by the provided
function. If the test fails, the frame will be omitted from the
displayed trace.
clarkf added a commit to clarkf/vitest that referenced this issue Oct 19, 2023
This change introduces a new optional configuration parameter,
`onStackTrace`. If included, each frame of each error stacktrace
encountered during the test run will be tested by the provided
function. If the test fails, the frame will be omitted from the
displayed trace.
@github-actions github-actions bot locked and limited conversation to collaborators Nov 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request good first issue Good for newcomers pr welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants