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

The html reporter allows viewing the current use case code #5931

Closed
4 tasks done
wll8 opened this issue Jun 20, 2024 · 4 comments · Fixed by #5948
Closed
4 tasks done

The html reporter allows viewing the current use case code #5931

wll8 opened this issue Jun 20, 2024 · 4 comments · Fixed by #5948

Comments

@wll8
Copy link

wll8 commented Jun 20, 2024

Clear and concise description of the problem

image

I hope that when I click on a use case, I can view the test code of the use case. It can bring the following benefits:

  • It is equivalent to a usage example for users to refer to.
  • It is equivalent to a code snippet, which helps developers quickly locate problems.
  • Use cases are usage examples, which reduces the work of repeatedly writing sample code.

Suggested solution

Suppose there is a use case a. When you click on the use case a, there is a parameter in the url, such as ?it=a, which is used to mark the current use case. And you can view its corresponding code on the right.

I can paste the url link to other places, such as the usage document. When others click on this url, they can view the relevant information of the corresponding use case.

Even simply displaying the toString result of the test case function (ignoring other functions referenced within the function) is sufficient for participating in the example.

Alternative

No response

Additional context

Its functionality is similar to mochawesome.

Test case code:

image

UI test results:

image

Validations

@sheremet-va
Copy link
Member

Is it html reporter or dynamic Vitest UI? There is usually a Code tab already.

@wll8
Copy link
Author

wll8 commented Jun 20, 2024

It is html report: npx vitest --reporter=html && npx vite preview --outDir html;
Not dynamic ui: npx vitest --ui;

And the existing Code tab shows the code of the entire *.test.js file, not the code of the current test case.

image

@sheremet-va
Copy link
Member

I don't really see any reason to add a separate tab to show just a small part of the code when we already show full code. The #5948 PR adds a way to scroll to the test line, - it should be enough to close this issue.

@wll8
Copy link
Author

wll8 commented Jun 23, 2024

reason:

I hope that when I click on a use case, I can view the test code of the use case. It can bring the following benefits:

  • It is equivalent to a usage example for users to refer to.
  • It is equivalent to a code snippet, which helps developers quickly locate problems.
  • Use cases are usage examples, which reduces the work of repeatedly writing sample code.

I'm not sure if that PR has the ability to view the code for the current use case (rather than the code for the entire file) in the html report.

There are more reasons to allow viewing of only the current use case, for example:

These features clearly demonstrate the usefulness of allowing navigation to a certain content.

@wll8 wll8 changed the title Click on the use case to view its code The html reporter allows viewing the current use case code Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants