11<script setup lang="ts">
2- import { hasFailedSnapshot } from ' @vitest/ws-client'
32import { Tooltip as VueTooltip } from ' floating-vue'
43import type { File , Task } from ' vitest'
54import {
@@ -9,22 +8,20 @@ import {
98 currentModule ,
109 dashboardVisible ,
1110 disableCoverage ,
12- openedTreeItems ,
1311 showCoverage ,
1412 showDashboard ,
1513} from ' ~/composables/navigation'
16- import { client , files , findById , isReport , runAll } from ' ~/composables/client'
14+ import { client , findById , isReport , runAll , runFiles } from ' ~/composables/client'
1715import { isDark , toggleDark } from ' ~/composables'
1816import { activeFileId } from ' ~/composables/params'
17+ import { explorerTree } from ' ~/composables/explorer'
18+ import { initialized , shouldShowExpandAll } from ' ~/composables/explorer/state'
1919
20- const failedSnapshot = computed (
21- () => files .value && hasFailedSnapshot (files .value ),
22- )
2320function updateSnapshot() {
2421 return client .rpc .updateSnapshot ()
2522}
2623
27- const toggleMode = computed (() => ( isDark .value ? ' light' : ' dark' ) )
24+ const toggleMode = computed (() => isDark .value ? ' light' : ' dark' )
2825
2926function onItemClick(task : Task ) {
3027 activeFileId .value = task .file .id
@@ -41,46 +38,42 @@ async function onRunAll(files?: File[]) {
4138 await nextTick ()
4239 }
4340 }
44- await runAll (files )
41+ if (files ?.length ) {
42+ await runFiles (files )
43+ }
44+ else {
45+ await runAll ()
46+ }
4547}
4648
4749function collapseTests() {
48- openedTreeItems . value = []
50+ explorerTree . collapseAllNodes ()
4951}
5052
5153function expandTests() {
52- files .value .forEach ((file ) => {
53- if (! openedTreeItems .value .includes (file .id )) {
54- openedTreeItems .value .push (file .id )
55- }
56- })
54+ explorerTree .expandAllNodes ()
5755}
5856 </script >
5957
6058<template >
6159 <!-- TODO: have test tree so the folders are also nested: test -> filename -> suite -> test -->
62- <TasksList
63- border =" r base"
64- :tasks =" files"
65- :on-item-click =" onItemClick"
66- :group-by-type =" true"
67- :nested =" true"
68- @run =" onRunAll"
69- >
70- <template #header =" { filteredTests } " >
60+ <Explorer border =" r base" :on-item-click =" onItemClick" :nested =" true" @run =" onRunAll" >
61+ <template #header =" { filteredFiles } " >
7162 <img w-6 h-6 src =" /favicon.svg" alt =" Vitest logo" >
7263 <span font-light text-sm flex-1 >Vitest</span >
7364 <div class =" flex text-lg" >
7465 <IconButton
75- v-show =" openedTreeItems.length > 0 "
66+ v-show =" !shouldShowExpandAll "
7667 v-tooltip.bottom =" 'Collapse tests'"
7768 title =" Collapse tests"
69+ :disabled =" !initialized"
7870 icon =" i-carbon:collapse-all"
7971 @click =" collapseTests()"
8072 />
8173 <IconButton
82- v-show =" openedTreeItems.length === 0 "
74+ v-show =" shouldShowExpandAll "
8375 v-tooltip.bottom =" 'Expand tests'"
76+ :disabled =" !initialized"
8477 title =" Expand tests"
8578 icon =" i-carbon:expand-all"
8679 @click =" expandTests()"
@@ -101,10 +94,7 @@ function expandTests() {
10194 >
10295 <div class =" i-carbon:folder-off ma" />
10396 <template #popper >
104- <div
105- class =" op100 gap-1 p-y-1"
106- grid =" ~ items-center cols-[1.5em_1fr]"
107- >
97+ <div class =" op100 gap-1 p-y-1" grid =" ~ items-center cols-[1.5em_1fr]" >
10898 <div class =" i-carbon:information-square w-1.5em h-1.5em" />
10999 <div >Coverage enabled but missing html reporter.</div >
110100 <div style =" grid-column : 2 " >
@@ -125,23 +115,18 @@ function expandTests() {
125115 @click =" showCoverage()"
126116 />
127117 <IconButton
128- v-if =" failedSnapshot && !isReport"
118+ v-if =" (explorerTree.summary. failedSnapshot && !isReport) "
129119 v-tooltip.bottom =" 'Update all failed snapshot(s)'"
130120 icon =" i-carbon:result-old"
131- @click =" updateSnapshot()"
121+ :disabled =" !explorerTree.summary.failedSnapshotEnabled"
122+ @click =" explorerTree.summary.failedSnapshotEnabled && updateSnapshot()"
132123 />
133124 <IconButton
134125 v-if =" !isReport"
135- v-tooltip.bottom ="
136- filteredTests
137- ? filteredTests.length === 0
138- ? 'No test to run (clear filter)'
139- : 'Rerun filtered'
140- : 'Rerun all'
141- "
142- :disabled =" filteredTests?.length === 0"
126+ v-tooltip.bottom =" filteredFiles ? (filteredFiles.length === 0 ? 'No test to run (clear filter)' : 'Rerun filtered') : 'Rerun all'"
127+ :disabled =" filteredFiles?.length === 0"
143128 icon =" i-carbon:play"
144- @click =" onRunAll(filteredTests )"
129+ @click =" onRunAll(filteredFiles )"
145130 />
146131 <IconButton
147132 v-tooltip.bottom =" `Toggle to ${toggleMode} mode`"
@@ -150,5 +135,5 @@ function expandTests() {
150135 />
151136 </div >
152137 </template >
153- </TasksList >
138+ </Explorer >
154139</template >
0 commit comments