Skip to content

Commit af7fec5

Browse files
authored
fix(ui): test files notified only when running (#6069)
1 parent 7012f8c commit af7fec5

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

packages/ui/client/composables/client/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { parseError } from '../error'
99
import { activeFileId } from '../params'
1010
import { createStaticClient } from './static'
1111
import { testRunState, unhandledErrors } from './state'
12-
import { uiFiles } from '~/composables/explorer/state'
1312
import { explorerTree } from '~/composables/explorer'
1413
import { isFileNode } from '~/composables/explorer/utils'
1514

@@ -51,8 +50,7 @@ export const status = ref<WebSocketStatus>('CONNECTING')
5150

5251
export const current = computed(() => {
5352
const currentFileId = activeFileId.value
54-
const entry = uiFiles.value.find(file => file.id === currentFileId)!
55-
return entry ? findById(entry.id) : undefined
53+
return currentFileId ? findById(currentFileId) : undefined
5654
})
5755
export const currentLogs = computed(() => getTasks(current.value).map(i => i?.logs || []).flat() || [])
5856

packages/ui/client/composables/explorer/collector.ts

+30-2
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ function updateRunningTodoTests() {
122122
}
123123

124124
function traverseFiles(collect: boolean) {
125+
// add missing files: now we have only files with running tests on the initial ws open event
126+
const files = client.state.getFiles()
127+
const currentFiles = explorerTree.nodes
128+
const missingFiles = files.filter(f => !currentFiles.has(f.id))
129+
for (let i = 0; i < missingFiles.length; i++) {
130+
createOrUpdateFileNode(missingFiles[i], collect)
131+
createOrUpdateEntry(missingFiles[i].tasks)
132+
}
133+
134+
// update pending tasks
125135
const rootTasks = explorerTree.root.tasks
126136
// collect remote children
127137
for (let i = 0; i < rootTasks.length; i++) {
@@ -142,11 +152,29 @@ function traverseFiles(collect: boolean) {
142152
}
143153

144154
function traverseReceivedFiles(collect: boolean) {
145-
const rootTasks = explorerTree.root.tasks
146155
const updatedFiles = new Map(explorerTree.pendingTasks.entries())
147156
explorerTree.pendingTasks.clear()
148-
const idMap = client.state.idMap
157+
158+
// add missing files: now we have only files with running tests on the initial ws open event
159+
const currentFiles = explorerTree.nodes
160+
const missingFiles = Array
161+
.from(updatedFiles.keys())
162+
.filter(id => !currentFiles.has(id))
163+
.map(id => findById(id))
164+
.filter(Boolean) as File[]
165+
166+
let newFile: File
167+
for (let i = 0; i < missingFiles.length; i++) {
168+
newFile = missingFiles[i]
169+
createOrUpdateFileNode(newFile, false)
170+
createOrUpdateEntry(newFile.tasks)
171+
// remove the file from the updated files
172+
updatedFiles.delete(newFile.id)
173+
}
174+
149175
// collect remote children
176+
const idMap = client.state.idMap
177+
const rootTasks = explorerTree.root.tasks
150178
for (let i = 0; i < rootTasks.length; i++) {
151179
const fileNode = rootTasks[i]
152180
const file = findById(fileNode.id)

packages/ui/client/composables/explorer/filter.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
isFileNode,
66
isParentNode,
77
isTestNode,
8+
sortedRootTasks,
89
} from '~/composables/explorer/utils'
910
import { client, findById } from '~/composables/client'
1011
import { filteredFiles, uiEntries } from '~/composables/explorer/state'
@@ -35,7 +36,7 @@ export function* filterAll(
3536
search: string,
3637
filter: Filter,
3738
) {
38-
for (const node of explorerTree.root.tasks) {
39+
for (const node of sortedRootTasks()) {
3940
yield * filterNode(node, search, filter)
4041
}
4142
}

packages/ui/client/composables/explorer/utils.ts

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ export function isParentNode(node: UITaskTreeNode): node is FileTreeNode | Suite
3333
return node.type === 'file' || node.type === 'suite'
3434
}
3535

36+
export function sortedRootTasks(tasks = explorerTree.root.tasks) {
37+
return tasks.sort((a, b) => {
38+
return `${a.filepath}:${a.projectName}`.localeCompare(`${b.filepath}:${b.projectName}`)
39+
})
40+
}
41+
3642
export function createOrUpdateFileNode(
3743
file: File,
3844
collect = false,

0 commit comments

Comments
 (0)