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

fix(vitest): json reporter location should include file #5106

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/vitest/src/node/reporters/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { parseErrorStacktrace } from '../../utils/source-map'

type Status = 'passed' | 'failed' | 'skipped' | 'pending' | 'todo' | 'disabled'
type Milliseconds = number
interface Callsite { line: number; column: number }
interface Callsite { line: number; column: number; file: string }
const StatusMap: Record<TaskState, Status> = {
fail: 'failed',
only: 'pending',
Expand Down Expand Up @@ -193,6 +193,9 @@ export class JsonReporter implements Reporter {
if (!frame)
return

return { line: frame.line, column: frame.column }
let file = ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think having an empty string here is a good idea

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return file == '' case should be unreachable. Because there should be no error without stack
So it's mostly for convincing typescript that all is ok anyway
If there are line and column, but there is no file, then that's strange input to this function. Strange input - strange output

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you just want to satisfy TS, you can use !

if (error.stacks && error.stacks.length)
file = error.stacks[0].file
return { line: frame.line, column: frame.column, file }
}
}