diff --git a/packages/ui/client/composables/explorer/collector.ts b/packages/ui/client/composables/explorer/collector.ts index c1688bd997c0..6794f229b634 100644 --- a/packages/ui/client/composables/explorer/collector.ts +++ b/packages/ui/client/composables/explorer/collector.ts @@ -6,9 +6,14 @@ import { hasFailedSnapshot } from '@vitest/ws-client' import type { CollectFilteredTests, CollectorInfo, Filter, FilteredTests } from '~/composables/explorer/types' import { client, findById } from '~/composables/client' import { runFilter, testMatcher } from '~/composables/explorer/filter' -import { createOrUpdateFileNode, createOrUpdateNodeTask, createOrUpdateSuiteTask } from '~/composables/explorer/utils' +import { + createOrUpdateFileNode, + createOrUpdateNodeTask, + createOrUpdateSuiteTask, + isRunningTestNode, +} from '~/composables/explorer/utils' import { isSuite } from '~/utils/task' -import { openedTreeItems, treeFilter, uiFiles } from '~/composables/explorer/state' +import { openedTreeItems, treeFilter, uiEntries, uiFiles } from '~/composables/explorer/state' import { explorerTree } from '~/composables/explorer/index' import { expandNodesOnEndRun } from '~/composables/explorer/expand' @@ -91,6 +96,25 @@ export function runCollect( }) } +function* collectRunningTodoTests() { + yield * uiEntries.value.filter(isRunningTestNode) +} + +function updateRunningTodoTests() { + const idMap = client.state.idMap + let task: Task | undefined + for (const test of collectRunningTodoTests()) { + // lookup the parent + task = idMap.get(test.parentId) + if (task && isSuite(task) && task.mode === 'todo') { + task = idMap.get(test.id) + if (task) { + task.mode = 'todo' + } + } + } +} + function traverseFiles(collect: boolean) { const rootTasks = explorerTree.root.tasks // collect remote children @@ -146,7 +170,7 @@ function doRunFilter( // refresh explorer queueMicrotask(() => { - runFilter(search, filter) + refreshExplorer(search, filter, end) }) if (applyExpandNodes) { @@ -158,10 +182,18 @@ function doRunFilter( } }) // refresh explorer - queueMicrotask(() => runFilter(search, filter)) + queueMicrotask(() => { + refreshExplorer(search, filter, end) + }) } } +function refreshExplorer(search: string, filter: Filter, end: boolean) { + runFilter(search, filter) + // update only at the end + end && updateRunningTodoTests() +} + function createOrUpdateEntry(tasks: Task[]) { let task: Task for (let i = 0; i < tasks.length; i++) { diff --git a/packages/ui/client/composables/explorer/utils.ts b/packages/ui/client/composables/explorer/utils.ts index 9cd1e8593a83..52067dd24b38 100644 --- a/packages/ui/client/composables/explorer/utils.ts +++ b/packages/ui/client/composables/explorer/utils.ts @@ -17,6 +17,10 @@ export function isTestNode(node: UITaskTreeNode): node is TestTreeNode | CustomT return node.type === 'test' || node.type === 'custom' } +export function isRunningTestNode(node: UITaskTreeNode): node is TestTreeNode | CustomTestTreeNode { + return node.mode === 'run' && (node.type === 'test' || node.type === 'custom') +} + export function isFileNode(node: UITaskTreeNode): node is FileTreeNode { return node.type === 'file' }