-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: store failure screenshots using artifacts API #9588
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <script setup lang="ts"> | ||
| import type { RunnerTask } from 'vitest' | ||
| import { computed, ref } from 'vue' | ||
| import { getAttachmentUrl } from '~/composables/attachments' | ||
| import { isReport } from '~/constants' | ||
| import IconButton from './IconButton.vue' | ||
| import Modal from './Modal.vue' | ||
| import ScreenshotError from './views/ScreenshotError.vue' | ||
|
|
||
| const { task } = defineProps<{ | ||
| task: RunnerTask | ||
| }>() | ||
|
|
||
| const showScreenshot = ref(false) | ||
| const artifact = computed(() => { | ||
| if (task.type === 'test') { | ||
| const artifact = task.artifacts.find(artifact => artifact.type === 'internal:failureScreenshot') | ||
|
|
||
| if (artifact !== undefined) { | ||
| return artifact | ||
| } | ||
| } | ||
|
|
||
| return null | ||
| }) | ||
| const screenshotUrl = computed(() => | ||
| artifact.value && artifact.value.attachments.length && getAttachmentUrl(artifact.value.attachments[0]), | ||
| ) | ||
|
|
||
| function openScreenshot() { | ||
| if (artifact.value === null || artifact.value.attachments.length === 0) { | ||
| return | ||
| } | ||
|
|
||
| const filePath = artifact.value.attachments[0].originalPath | ||
|
|
||
| fetch(`/__open-in-editor?file=${encodeURIComponent(filePath)}`) | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
| <template v-if="screenshotUrl"> | ||
| <div flex="~ gap-2 items-center"> | ||
| <IconButton | ||
| v-tooltip.bottom="'View screenshot error'" | ||
| class="!op-100" | ||
| icon="i-carbon:image" | ||
| title="View screenshot error" | ||
| @click="showScreenshot = true" | ||
| /> | ||
| <!-- in a report there is no dev server to handle the action --> | ||
| <IconButton | ||
| v-if="!isReport" | ||
| v-tooltip.bottom="'Open screenshot error in editor'" | ||
| class="!op-100" | ||
| icon="i-carbon:image-reference" | ||
| title="Open screenshot error in editor" | ||
| @click="openScreenshot" | ||
| /> | ||
|
Comment on lines
+44
to
+59
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The screenshot is visible in the report, but we can't open the screenshot in the editor since we don't have a server to handle the open action
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrote a comment in the file explaining why it's hidden in a report for posterity |
||
| </div> | ||
| <Modal :key="screenshotUrl" v-model="showScreenshot" direction="right"> | ||
| <ScreenshotError | ||
| :file="task.file.filepath" | ||
| :name="task.name" | ||
| :url="screenshotUrl" | ||
| @close="showScreenshot = false" | ||
| /> | ||
| </Modal> | ||
| </template> | ||
| </template> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| <script setup lang="ts"> | ||
| import type { RunnerTestCase, TestArtifact } from 'vitest' | ||
| import type { Component } from 'vue' | ||
| import { computed } from 'vue' | ||
| import { getLocationString, openLocation } from '~/composables/location' | ||
| import VisualRegression from './visual-regression/VisualRegression.vue' | ||
|
|
||
| const { test } = defineProps<{ test: RunnerTestCase }>() | ||
|
|
||
| interface HandledArtifact { artifact: TestArtifact; component: Component; props: object } | ||
|
|
||
| type ComponentProps<T> = T extends new(...args: any) => { $props: infer P } ? NonNullable<P> | ||
| : T extends (props: infer P, ...args: any) => any ? P | ||
| : object | ||
|
|
||
| const handledArtifacts = computed<readonly HandledArtifact[]>(() => { | ||
| const handledArtifacts: HandledArtifact[] = [] | ||
|
|
||
| for (const artifact of test.artifacts) { | ||
| switch (artifact.type) { | ||
| case 'internal:toMatchScreenshot': { | ||
| if (artifact.kind === 'visual-regression') { | ||
| handledArtifacts.push({ | ||
| artifact, | ||
| component: VisualRegression, | ||
| props: { regression: artifact } satisfies ComponentProps<typeof VisualRegression>, | ||
| }) | ||
| } | ||
|
|
||
| continue | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return handledArtifacts | ||
| }) | ||
| </script> | ||
|
|
||
| <template> | ||
| <template v-if="handledArtifacts.length"> | ||
| <h1 m-2> | ||
| Test Artifacts | ||
| </h1> | ||
| <div | ||
| v-for="{ artifact, component, props }, index of handledArtifacts" | ||
| :key="artifact.type + index" | ||
| bg="yellow-500/10" | ||
| text="yellow-500 sm" | ||
| p="x3 y2" | ||
| m-2 | ||
| rounded | ||
| role="note" | ||
| > | ||
| <div flex="~ gap-2 items-center justify-between" overflow-hidden> | ||
| <div> | ||
| <span | ||
| v-if="artifact.location && artifact.location.file === test.file.filepath" | ||
| v-tooltip.bottom="'Open in Editor'" | ||
| title="Open in Editor" | ||
| class="flex gap-1 text-yellow-500/80 cursor-pointer" | ||
| ws-nowrap | ||
| @click="openLocation(test, artifact.location)" | ||
| > | ||
| {{ getLocationString(artifact.location) }} | ||
| </span> | ||
| <span | ||
| v-else-if="artifact.location && artifact.location.file !== test.file.filepath" | ||
| class="flex gap-1 text-yellow-500/80" | ||
| ws-nowrap | ||
| > | ||
| {{ getLocationString(artifact.location) }} | ||
| </span> | ||
| </div> | ||
| </div> | ||
| <component :is="component" v-bind="props" /> | ||
| </div> | ||
| </template> | ||
| </template> |
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 should not be needed anymore since the image is fetched as an attachment