MCPcopy
hub / github.com/vitest-dev/vitest / createClient

Function createClient

packages/ws-client/src/index.ts:30–160  ·  view source on GitHub ↗
(url: string, options: VitestClientOptions = {})

Source from the content-addressed store, hash-verified

28}
29
30export function createClient(url: string, options: VitestClientOptions = {}): VitestClient {
31 const {
32 handlers = {},
33 autoReconnect = true,
34 reconnectInterval = 2000,
35 reconnectTries = 10,
36 connectTimeout = 60000,
37 reactive = v => v,
38 WebSocketConstructor = globalThis.WebSocket,
39 } = options
40
41 let tries = reconnectTries
42 const ctx = reactive({
43 ws: new WebSocketConstructor(url),
44 state: new StateManager(),
45 waitForConnection,
46 reconnect,
47 }, 'state') as VitestClient
48
49 ctx.state.filesMap = reactive(ctx.state.filesMap, 'filesMap')
50 ctx.state.idMap = reactive(ctx.state.idMap, 'idMap')
51
52 let onMessage: (data: any) => void
53 const functions: WebSocketEvents = {
54 onTestAnnotate(testId, annotation) {
55 handlers.onTestAnnotate?.(testId, annotation)
56 },
57 onTestArtifactRecord(testId, artifact) {
58 handlers.onTestArtifactRecord?.(testId, artifact)
59 },
60 onSpecsCollected(specs, startTime) {
61 specs?.forEach(([config, file]) => {
62 ctx.state.clearFiles({ config }, [file])
63 })
64 handlers.onSpecsCollected?.(specs, startTime)
65 },
66 onPathsCollected(paths) {
67 ctx.state.collectPaths(paths)
68 handlers.onPathsCollected?.(paths)
69 },
70 onCollected(files) {
71 ctx.state.collectFiles(files)
72 handlers.onCollected?.(files)
73 },
74 onTaskUpdate(packs, events) {
75 ctx.state.updateTasks(packs)
76 handlers.onTaskUpdate?.(packs, events)
77 },
78 onUserConsoleLog(log) {
79 ctx.state.updateUserLog(log)
80 handlers.onUserConsoleLog?.(log)
81 },
82 onFinished(files, errors, coverage, executionTime) {
83 handlers.onFinished?.(files, errors, coverage, executionTime)
84 },
85 onFinishedReportCoverage() {
86 handlers.onFinishedReportCoverage?.()
87 },

Callers 1

index.tsFile · 0.90

Calls 3

stringifyFunction · 0.85
registerWSFunction · 0.70
sendMethod · 0.45

Tested by

no test coverage detected