@@ -3,7 +3,7 @@ import type { ErrorWithDiff, File, Suite, Task } from 'vitest'
33import type Convert from ' ansi-to-html'
44import { isDark } from ' ~/composables/dark'
55import { createAnsiToHtmlFilter } from ' ~/composables/error'
6- import { config } from ' ~/composables/client'
6+ import { browserState , config } from ' ~/composables/client'
77import { escapeHtml } from ' ~/utils/escape'
88
99const props = defineProps <{
@@ -103,6 +103,30 @@ const failed = computed(() => {
103103 ? mapLeveledTaskStacks (isDark .value , failedFlatMap )
104104 : failedFlatMap
105105})
106+
107+ function open(task : Task ) {
108+ const filePath = task .meta ?.failScreenshotPath
109+ if (filePath ) {
110+ fetch (` /__open-in-editor?file=${encodeURIComponent (filePath )} ` )
111+ }
112+ }
113+
114+ const showScreenshot = ref (false )
115+ const timestamp = ref (Date .now ())
116+ const currentTask = ref <Task | undefined >()
117+ const currentScreenshotUrl = computed (() => {
118+ const file = currentTask .value ?.meta .failScreenshotPath
119+ // force refresh
120+ const t = timestamp .value
121+ // browser plugin using /, change this if base can be modified
122+ return file ? ` /__screenshot-error?file=${encodeURIComponent (file )}&t=${t } ` : undefined
123+ })
124+
125+ function showScreenshotModal(task : Task ) {
126+ currentTask .value = task
127+ timestamp .value = Date .now ()
128+ showScreenshot .value = true
129+ }
106130 </script >
107131
108132<template >
@@ -121,7 +145,25 @@ const failed = computed(() => {
121145 }rem`,
122146 }"
123147 >
124- {{ task.name }}
148+ <div flex =" ~ gap-2 items-center" >
149+ <span >{{ task.name }}</span >
150+ <template v-if =" browserState && task .meta ?.failScreenshotPath " >
151+ <IconButton
152+ v-tooltip .bottom =" ' View screenshot error' "
153+ class="!op-100"
154+ icon="i-carbon:image "
155+ title="View screenshot error"
156+ @click =" showScreenshotModal (task )"
157+ />
158+ <IconButton
159+ v-tooltip .bottom =" ' Open screenshot error in editor' "
160+ class="!op-100"
161+ icon="i-carbon:image-reference "
162+ title="Open screenshot error in editor"
163+ @click =" open (task )"
164+ />
165+ </template >
166+ </div >
125167 <div
126168 v-if =" task.result?.htmlError"
127169 class =" scrolls scrolls-rounded task-error"
@@ -146,6 +188,20 @@ const failed = computed(() => {
146188 All tests passed in this file
147189 </div >
148190 </template >
191+ <template v-if =" browserState " >
192+ <Modal v-model =" showScreenshot " direction="right">
193+ <template v-if =" currentTask " >
194+ <Suspense >
195+ <ScreenshotError
196+ :file =" currentTask .file .filepath "
197+ :name =" currentTask .name "
198+ :url =" currentScreenshotUrl "
199+ @close =" showScreenshot = false "
200+ />
201+ </Suspense >
202+ </template >
203+ </Modal >
204+ </template >
149205 </div >
150206</template >
151207
0 commit comments