-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(ui): display test's snapshot result on vitest-ui #8335
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
base: main
Are you sure you want to change the base?
Conversation
…shot result more detail
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can display them in a similar way to annotations (but hidden by default, unless there is an error). This will require storing more information in Test
(maybe snapshot names and location?) Also regarding existing code, maybe if the snapshot failed, we should show the diff?
|
||
add(result: SnapshotResult): void { | ||
addSnapshotResult(this.summary, result) | ||
this.result = result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a separate variable? What does result
represent?
<div v-if="snapshotData.snapshots.unmatched.length > 0" class="space-y-2"> | ||
<details class="group" open> | ||
<summary class="cursor-pointer p-2 bg-red-50 dark:bg-red-950 border border-red-200 dark:border-red-800 rounded text-red-700 dark:text-red-300 font-medium text-sm"> | ||
❌ Unmatched Snapshots ({{ snapshotData.snapshots.unmatched.length }}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is "unmatched" snapshot?
<div v-if="snapshotData.snapshots.added.length > 0" class="space-y-2"> | ||
<details class="group" open> | ||
<summary class="cursor-pointer p-2 bg-green-50 dark:bg-green-950 border border-green-200 dark:border-green-800 rounded text-green-700 dark:text-green-300 font-medium text-sm"> | ||
🆕 Added Snapshots ({{ snapshotData.snapshots.added.length }}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not use emojis, we have iconify icons available (see dependencies for from which library)
async getSnapshotData(): Promise<SnapshotData | void> { | ||
try { | ||
// Get snapshot result from the Vitest context | ||
const snapshotResult = ctx.snapshot.result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this is sensitive to race conditions? result
doesn't represent all of snapshots, or? Only for a specific file?
export interface SnapshotData { | ||
filepath: string | ||
snapshots: { | ||
added: Array<{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can probably be its own type, so we don't need to repeat it
@sheremet-va Thank you for your feedback!
Is my understanding correct that, in this PR, instead of displaying Snapshots within a dedicated Snapshot Tab, you're proposing to have an expandable Annotation Block within the Code Tab, similar to Test Annotations in an HTML Reporter, at the location where Snapshot comparisons are performed in the code, and expanding it would allow users to view the Snapshot? If so, that sounds good! Also, in that case, InlineSnapshot might be ignored since its content is already present within the code itself.
That's true! Failed snapshots are displayed in Report Tab in current implementation, so maybe we don't need to display failed snapshot results in Code(or Snapshot) Tab duplicatedly. |
Yes, that is what I am proposing. We can probably reuse annotations for these. If needed, the type can be extended. Or we can also introduce a separate field that is only available after the test has finished (annotations appear while the test is running and have a separate reporter event which can make the reporting slower). I think I would prefer to reduce the amount of text that we have to pass down between UI and Node because it's
Makes sense, let's not duplicate it. |
Thank you! I could grasp what I should do! I will implement the snapshot visualization feature according to what should be done, so please let me more time to implement this. (perhaps, I will re-create PullRequest if the most of implementation in this PR is not needed, but I cannot judge at least now) |
Description
Close: #4060
In this ticket, I implemented to display test's snapshot result on vitest-ui. Please feel free to provide any feedback about UserInterface(=vitest/ui itself) and also data flow design.
In this implementation, vitest/ui can display added/matched/unmatched/unchecked snapshots result. Vitest node environment(=vm context) executes tests and generate snapshot result, and passes that result to vitest core context via
rpc()
, and vitest-ui fetches some data from vitest core context. However, vitest node environment passes only snapshot diff count information to vitest core context. in current implementation. So I changed to pass more detailed snapshot result to vitest core context to display these in vitest-ui.If you have any concern or something unclear, please feel free to pointed out!
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yaml
unless you introduce a new test example.Tests
pnpm test:ci
.Documentation
pnpm run docs
command.Changesets
feat:
,fix:
,perf:
,docs:
, orchore:
.