Skip to content

Commit f72c40f

Browse files
authored
chore: remove ws-client package from the repository (#10185)
1 parent ff2478d commit f72c40f

14 files changed

Lines changed: 146 additions & 281 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { getNames } from '@vitest/ws-client'
2+
import { getNames } from '@vitest/runner/utils'
33
import { computed } from 'vue'
44
import { client, currentLogs as logs } from '~/composables/client'
55
import { isDark } from '~/composables/dark'

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import type {
88
TestAnnotation,
99
} from 'vitest'
1010
import type { BrowserRunnerState } from '../../../types'
11-
import { createFileTask } from '@vitest/runner/utils'
12-
import { createClient, getTasks } from '@vitest/ws-client'
11+
import type { VitestClient } from './ws'
12+
import { createFileTask, getTasks } from '@vitest/runner/utils'
1313
import { computed, reactive as reactiveVue, ref, shallowRef, watch } from 'vue'
1414
import { explorerTree } from '~/composables/explorer'
1515
import { isFileNode } from '~/composables/explorer/utils'
@@ -20,15 +20,16 @@ import { parseError } from '../error'
2020
import { activeFileId } from '../params'
2121
import { testRunState, unhandledErrors } from './state'
2222
import { createStaticClient } from './static'
23+
import { createWsClient } from './ws'
2324

2425
export { ENTRY_URL, HOST, isReport, PORT } from '../../constants'
2526

26-
export const client = (function createVitestClient() {
27+
export const client: VitestClient = (function createVitestClient() {
2728
if (isReport) {
2829
return createStaticClient()
2930
}
3031
else {
31-
return createClient(ENTRY_URL, {
32+
return createWsClient(ENTRY_URL, {
3233
reactive: (data, ctxKey) => {
3334
return ctxKey === 'state' ? reactiveVue(data as any) as any : shallowRef(data)
3435
},

packages/ui/client/composables/client/state.ts

Lines changed: 135 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
import type { TestTagDefinition } from '@vitest/runner'
21
import type { TestError } from '@vitest/utils'
2+
import type {
3+
RunnerTask,
4+
RunnerTaskResultPack,
5+
RunnerTestFile,
6+
TestTagDefinition,
7+
UserConsoleLog,
8+
} from 'vitest'
39
import type { Ref } from 'vue'
410
import type { RunState } from '../../../types'
11+
import { createFileTask } from '@vitest/runner/utils'
512
import { computed, ref } from 'vue'
613
import { config } from '.'
714

@@ -15,3 +22,130 @@ export const tagsDefinitions = computed(() => {
1522
return acc
1623
}, {} as Record<string, TestTagDefinition>)
1724
})
25+
26+
export class StateManager {
27+
filesMap: Map<string, RunnerTestFile[]> = new Map()
28+
pathsSet: Set<string> = new Set()
29+
idMap: Map<string, RunnerTask> = new Map()
30+
31+
getPaths(): string[] {
32+
return Array.from(this.pathsSet)
33+
}
34+
35+
/**
36+
* Return files that were running or collected.
37+
*/
38+
getFiles(keys?: string[]): RunnerTestFile[] {
39+
if (keys) {
40+
return keys
41+
.map(key => this.filesMap.get(key)!)
42+
.flat()
43+
.filter(file => file && !file.local)
44+
}
45+
return Array.from(this.filesMap.values()).flat().filter(file => !file.local)
46+
}
47+
48+
getFilepaths(): string[] {
49+
return Array.from(this.filesMap.keys())
50+
}
51+
52+
getFailedFilepaths(): string[] {
53+
return this.getFiles()
54+
.filter(i => i.result?.state === 'fail')
55+
.map(i => i.filepath)
56+
}
57+
58+
collectPaths(paths: string[] = []): void {
59+
paths.forEach((path) => {
60+
this.pathsSet.add(path)
61+
})
62+
}
63+
64+
collectFiles(files: RunnerTestFile[] = []): void {
65+
files.forEach((file) => {
66+
const existing = this.filesMap.get(file.filepath) || []
67+
const otherProject = existing.filter(
68+
i => i.projectName !== file.projectName || i.meta.typecheck !== file.meta.typecheck,
69+
)
70+
const currentFile = existing.find(
71+
i => i.projectName === file.projectName,
72+
)
73+
// keep logs for the previous file because it should always be initiated before the collections phase
74+
// which means that all logs are collected during the collection and not inside tests
75+
if (currentFile) {
76+
file.logs = currentFile.logs
77+
}
78+
otherProject.push(file)
79+
this.filesMap.set(file.filepath, otherProject)
80+
this.updateId(file)
81+
})
82+
}
83+
84+
// this file is reused by ws-client, and should not rely on heavy dependencies like workspace
85+
clearFiles(
86+
_project: { config: { name: string | undefined; root: string } },
87+
paths: string[] = [],
88+
): void {
89+
const project = _project
90+
paths.forEach((path) => {
91+
const files = this.filesMap.get(path)
92+
const fileTask = createFileTask(
93+
path,
94+
project.config.root,
95+
project.config.name || '',
96+
)
97+
fileTask.local = true
98+
this.idMap.set(fileTask.id, fileTask)
99+
if (!files) {
100+
this.filesMap.set(path, [fileTask])
101+
return
102+
}
103+
const filtered = files.filter(
104+
file => file.projectName !== project.config.name,
105+
)
106+
// always keep a File task, so we can associate logs with it
107+
if (!filtered.length) {
108+
this.filesMap.set(path, [fileTask])
109+
}
110+
else {
111+
this.filesMap.set(path, [...filtered, fileTask])
112+
}
113+
})
114+
}
115+
116+
updateId(task: RunnerTask): void {
117+
if (this.idMap.get(task.id) === task) {
118+
return
119+
}
120+
this.idMap.set(task.id, task)
121+
if (task.type === 'suite') {
122+
task.tasks.forEach((task) => {
123+
this.updateId(task)
124+
})
125+
}
126+
}
127+
128+
updateTasks(packs: RunnerTaskResultPack[]): void {
129+
for (const [id, result, meta] of packs) {
130+
const task = this.idMap.get(id)
131+
if (task) {
132+
task.result = result
133+
task.meta = meta
134+
// skipped with new PendingError
135+
if (result?.state === 'skip') {
136+
task.mode = 'skip'
137+
}
138+
}
139+
}
140+
}
141+
142+
updateUserLog(log: UserConsoleLog): void {
143+
const task = log.taskId && this.idMap.get(log.taskId)
144+
if (task) {
145+
if (!task.logs) {
146+
task.logs = []
147+
}
148+
task.logs.push(log)
149+
}
150+
}
151+
}

packages/ui/client/composables/client/static.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { VitestClient } from '@vitest/ws-client'
21
import type { BirpcReturn } from 'birpc'
32
import type {
43
ModuleGraphData,
@@ -7,10 +6,11 @@ import type {
76
WebSocketEvents,
87
WebSocketHandlers,
98
} from 'vitest'
9+
import type { VitestClient } from './ws'
1010
import { decompressSync, strFromU8 } from 'fflate'
1111
import { parse } from 'flatted'
1212
import { reactive } from 'vue'
13-
import { StateManager } from '../../../../ws-client/src/state'
13+
import { StateManager } from './state'
1414

1515
interface HTMLReportMetadata {
1616
paths: string[]

packages/ws-client/src/index.ts renamed to packages/ui/client/composables/client/ws.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import type { BirpcOptions, BirpcReturn } from 'birpc'
2-
// eslint-disable-next-line no-restricted-imports
32
import type { WebSocketEvents, WebSocketHandlers } from 'vitest'
43
import { createBirpc } from 'birpc'
5-
64
import { parse, stringify } from 'flatted'
75
import { StateManager } from './state'
86

9-
export * from '@vitest/runner/utils'
10-
117
export interface VitestClientOptions {
128
handlers?: Partial<WebSocketEvents>
139
autoReconnect?: boolean
@@ -27,7 +23,7 @@ export interface VitestClient {
2723
reconnect: () => Promise<void>
2824
}
2925

30-
export function createClient(url: string, options: VitestClientOptions = {}): VitestClient {
26+
export function createWsClient(url: string, options: VitestClientOptions = {}): VitestClient {
3127
const {
3228
handlers = {},
3329
autoReconnect = true,
@@ -128,7 +124,7 @@ export function createClient(url: string, options: VitestClientOptions = {}): Vi
128124
`Cannot connect to the server in ${connectTimeout / 1000} seconds`,
129125
),
130126
)
131-
}, connectTimeout)?.unref?.()
127+
}, connectTimeout)
132128
if (ctx.ws.OPEN === ctx.ws.readyState) {
133129
resolve()
134130
}

packages/ui/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
"@vitest/browser-preview": "workspace:*",
7676
"@vitest/browser-webdriverio": "workspace:*",
7777
"@vitest/runner": "workspace:*",
78-
"@vitest/ws-client": "workspace:*",
7978
"@vue/test-utils": "^2.4.6",
8079
"@vueuse/core": "catalog:",
8180
"ansi-to-html": "^0.7.2",

packages/ui/vite.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export default defineConfig({
1717
dedupe: ['vue'],
1818
alias: {
1919
'~/': `${resolve(import.meta.dirname, 'client')}/`,
20-
'@vitest/ws-client': `${resolve(import.meta.dirname, '../ws-client/src/index.ts')}`,
2120
},
2221
},
2322
define: {

packages/vitest/src/public/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export type {
146146
TestFunction,
147147
TestOptions,
148148
VitestRunnerConfig as TestRunnerConfig,
149+
TestTagDefinition,
149150

150151
TestTags,
151152
VitestRunner as VitestTestRunner,

packages/ws-client/package.json

Lines changed: 0 additions & 48 deletions
This file was deleted.

packages/ws-client/rollup.config.js

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)