Skip to content

Commit 3e535f7

Browse files
authored
fix(ui): keep the same tab open when clicking on different tests (#8599)
1 parent 4d41928 commit 3e535f7

File tree

5 files changed

+32
-15
lines changed

5 files changed

+32
-15
lines changed

packages/ui/client/auto-imports.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ declare global {
1111
const asyncComputed: typeof import('@vueuse/core')['asyncComputed']
1212
const autoResetRef: typeof import('@vueuse/core')['autoResetRef']
1313
const calcExternalLabels: typeof import('./composables/module-graph')['calcExternalLabels']
14+
const clickOnTask: typeof import('./composables/navigation')['clickOnTask']
1415
const codemirrorRef: typeof import('./composables/codemirror')['codemirrorRef']
1516
const columnNumber: typeof import('./composables/params')['columnNumber']
1617
const computed: typeof import('vue')['computed']

packages/ui/client/components/Navigation.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<script setup lang="ts">
2-
import type { File } from 'vitest'
2+
import type { RunnerTestFile } from 'vitest'
33
import { Tooltip as VueTooltip } from 'floating-vue'
44
import { isDark, toggleDark } from '~/composables'
55
import { client, isReport, runAll, runFiles } from '~/composables/client'
66
import { explorerTree } from '~/composables/explorer'
77
import { initialized, shouldShowExpandAll } from '~/composables/explorer/state'
88
import {
9+
clickOnTask,
910
coverageConfigured,
1011
coverageEnabled,
1112
coverageVisible,
1213
dashboardVisible,
1314
disableCoverage,
1415
showCoverage,
1516
showDashboard,
16-
showReport,
1717
} from '~/composables/navigation'
1818
1919
function updateSnapshot() {
@@ -22,7 +22,7 @@ function updateSnapshot() {
2222
2323
const toggleMode = computed(() => isDark.value ? 'light' : 'dark')
2424
25-
async function onRunAll(files?: File[]) {
25+
async function onRunAll(files?: RunnerTestFile[]) {
2626
if (coverageEnabled.value) {
2727
disableCoverage.value = true
2828
await nextTick()
@@ -50,7 +50,7 @@ function expandTests() {
5050

5151
<template>
5252
<!-- TODO: have test tree so the folders are also nested: test -> filename -> suite -> test -->
53-
<Explorer border="r base" :on-item-click="showReport" :nested="true" @run="onRunAll">
53+
<Explorer border="r base" :on-item-click="clickOnTask" :nested="true" @run="onRunAll">
5454
<template #header="{ filteredFiles }">
5555
<img w-6 h-6 src="/favicon.svg" alt="Vitest logo">
5656
<span font-light text-sm flex-1>Vitest</span>

packages/ui/client/components/views/ViewEditor.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import type { Task } from '@vitest/runner'
33
import type CodeMirror from 'codemirror'
4-
import type { File, TestAnnotation, TestError } from 'vitest'
4+
import type { RunnerTestFile, TestAnnotation, TestError } from 'vitest'
55
import { createTooltip, destroyTooltip } from 'floating-vue'
66
import { getAttachmentUrl, sanitizeFilePath } from '~/composables/attachments'
77
import { client, isReport } from '~/composables/client'
@@ -11,7 +11,7 @@ import { openInEditor } from '~/composables/error'
1111
import { columnNumber, lineNumber } from '~/composables/params'
1212
1313
const props = defineProps<{
14-
file?: File
14+
file?: RunnerTestFile
1515
}>()
1616
1717
const emit = defineEmits<{ (event: 'draft', value: boolean): void }>()

packages/ui/client/composables/codemirror.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export async function showTaskSource(task: Task) {
6767
file: task.file.id,
6868
line: task.location?.line ?? 0,
6969
view: 'editor',
70-
test: null,
70+
test: task.id,
7171
column: null,
7272
})
7373
}

packages/ui/client/composables/navigation.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,30 @@ export function navigateTo({ file, line, view, test, column }: Params) {
111111
showDashboard(false)
112112
}
113113

114-
export function showReport(task: Task) {
115-
navigateTo({
116-
file: task.file.id,
117-
test: task.type === 'test' ? task.id : null,
118-
line: null,
119-
view: null,
120-
column: null,
121-
})
114+
export function clickOnTask(task: Task) {
115+
if (task.type === 'test') {
116+
if (viewMode.value === 'editor') {
117+
showTaskSource(task)
118+
}
119+
else {
120+
navigateTo({
121+
file: task.file.id,
122+
line: null,
123+
column: null,
124+
view: viewMode.value,
125+
test: task.id,
126+
})
127+
}
128+
}
129+
else {
130+
navigateTo({
131+
file: task.file.id,
132+
test: null,
133+
line: null,
134+
view: viewMode.value,
135+
column: null,
136+
})
137+
}
122138
}
123139

124140
export function showCoverage() {

0 commit comments

Comments
 (0)