Skip to content

Commit

Permalink
fix(ui): update running todo tests inside todo suites (each) (#5939)
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin authored Jun 20, 2024
1 parent bec434c commit 63ae10b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
40 changes: 36 additions & 4 deletions packages/ui/client/composables/explorer/collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -146,7 +170,7 @@ function doRunFilter(

// refresh explorer
queueMicrotask(() => {
runFilter(search, filter)
refreshExplorer(search, filter, end)
})

if (applyExpandNodes) {
Expand All @@ -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++) {
Expand Down
4 changes: 4 additions & 0 deletions packages/ui/client/composables/explorer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down

0 comments on commit 63ae10b

Please sign in to comment.