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

Show test failure details in UI report tab #684

Closed
4 tasks done
uicowboy opened this issue Feb 5, 2022 · 15 comments · Fixed by #685
Closed
4 tasks done

Show test failure details in UI report tab #684

uicowboy opened this issue Feb 5, 2022 · 15 comments · Fixed by #685
Assignees
Labels
enhancement New feature or request

Comments

@uicowboy
Copy link

uicowboy commented Feb 5, 2022

Clear and concise description of the problem

Currently when a test fails, the details of the failure are shown in the terminal, but it would be great if they were also displayed in the UI. I've tested this on a React project with TypeScript.

Suggested solution

The UI of Vitest is such a killer feature, so thank you for building this! At the moment the UI only marks the test case as failed, but the "Report" tab only renders the name of the component. Ideally, it would display the details of the test failure. Has this been considered?

Alternative

No response

Additional context

No response

Validations

@DerYeger DerYeger self-assigned this Feb 5, 2022
@DerYeger DerYeger added the enhancement New feature or request label Feb 5, 2022
@DerYeger
Copy link
Member

DerYeger commented Feb 5, 2022

Hi, thank you for the suggestion!

I created #685 to address this issue. Does the attached screenshot meet your requirements?

@uicowboy
Copy link
Author

uicowboy commented Feb 5, 2022

Thank you @DerYeger for your speedy PR!

Yeah it looks good! Out of curiosity, the task: Task object in the collectFailed function would receive the test failure output that's also shown in the terminal when unit or even snapshot tests fail?

@DerYeger
Copy link
Member

DerYeger commented Feb 5, 2022

Thank you @DerYeger for your speedy PR!

Thanks!

Yeah it looks good! Out of curiosity, the task: Task object in the collectFailed function would receive the test failure output that's also shown in the terminal when unit or even snapshot tests fail?

I'm not sure, since I haven't worked on the terminal output.
The UI report is only for a single file. So I guess the terminal output differs by collecting the failed tasks of all files.

@uicowboy
Copy link
Author

uicowboy commented Feb 5, 2022

That makes sense, thanks for explaining. Look forward to trying this out once it's merged (unless there's another way you'd want me to test this before merging and I'll be happy to do so).

@Demivan
Copy link
Member

Demivan commented Feb 5, 2022

There is logs property on the Task that could probably be used for this.

@uicowboy
Copy link
Author

uicowboy commented Feb 5, 2022

Looks like there's some info here that may be potentially useful:

logs?: UserConsoleLog[]

export interface UserConsoleLog {
  content: string
  type: 'stdout' | 'stderr'
  taskId?: string
  time: number
}

export interface UserConsoleLog {

@DerYeger
Copy link
Member

DerYeger commented Feb 5, 2022

@Demivan @uicrafts In what way should the logs be used here? There already is a logs view.

@Demivan
Copy link
Member

Demivan commented Feb 5, 2022

I thought logs are not being displayed if test fails. If they are, then everything is fine.

@uicowboy
Copy link
Author

uicowboy commented Feb 5, 2022

I apologize if perhaps I didn't clarify things correctly when opening this issue! The original idea/suggestion that prompted me to open this thread was that when tests fail, the terminal shows the log details for that failure, but the UI doesn't. Here's an example of a snapshot test (but the same happens with unit tests):

Terminal output:
image

UI:
image

As you can see, the UI only displays the name of the failed component, but no logs/details for the test failure like we see in the terminal. @Demivan looking at the UserConsoleLog interface, would the content property contain the log failure (i.e. my first screenshot), or is it maybe just used for something else like capturing console.log calls from the user? Otherwise maybe using this interface isn't necessary and what @DerYeger did takes care of this?

@userquin
Copy link
Member

userquin commented Feb 5, 2022

@uicrafts can you go in that case to code tab? IIRC that error is shown in the code.

@userquin
Copy link
Member

userquin commented Feb 5, 2022

imagen

@uicowboy
Copy link
Author

uicowboy commented Feb 5, 2022

@userquin I thought that might be the case too initially, but it looks like the Code tab doesn't display any test failures and instead shows the source code (the whole Modal.test.tsx file), which is also pretty handy 👌

Edit: just saw the screenshot you shared, and I can confirm I'm not seeing that for failed snapshot or unit tests, at least on .tsx files.

image

@userquin
Copy link
Member

userquin commented Feb 5, 2022

@uicrafts it seems tsx or tests with snapshots not working, tested on my repro (not working). It seems that codemirror is not updating either.

EDIT: you can modify the tests on the code tab and then crtl + s or command + s to save it.

@uicowboy
Copy link
Author

uicowboy commented Feb 5, 2022

@userquin Ah, thanks for confirming on your end that it's a bug 👍

Also, that's a nice tip about being able to update the tests and save the file from the UI -- another cool feature in Vitest 👌

@DerYeger
Copy link
Member

DerYeger commented Feb 5, 2022

@uicrafts I think my PR does just that.

image

The logs are just your console output.

@Demivan The logs of failing tests are included.

chaii3 pushed a commit to chaii3/vitest that referenced this issue May 13, 2022
The document correctly specified that this works in effect scope, and
does nothing if not. Change the comment in code to be the same as in the
document.
@github-actions github-actions bot locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants