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

Function setupClient

packages/browser/src/node/rpc.ts:155–437  ·  view source on GitHub ↗
(
    project: TestProject,
    rpcId: string,
    ws: WebSocket,
    options: {
      sessionId: string
    },
  )

Source from the content-addressed store, hash-verified

153 }
154
155 function setupClient(
156 project: TestProject,
157 rpcId: string,
158 ws: WebSocket,
159 options: {
160 sessionId: string
161 },
162 ) {
163 const mockResolver = new ServerMockResolver(globalServer.vite, {
164 moduleDirectories: project.config?.deps?.moduleDirectories,
165 })
166 const mocker = project.browser?.provider.mocker
167
168 const rpc = createBirpc<WebSocketBrowserEvents, WebSocketBrowserHandlers>(
169 {
170 onOrchestratorReady() {
171 const sessions = vitest._browserSessions
172 sessions.getSession(options.sessionId)?.ready()
173 },
174 async onUnhandledError(error, type) {
175 if (error && typeof error === 'object') {
176 const _error = error as TestError
177 _error.stacks = globalServer.parseErrorStacktrace(_error)
178 }
179 vitest.state.catchError(error, type)
180 },
181 async onQueued(method, file) {
182 if (method === 'collect') {
183 vitest.state.collectFiles(project, [file])
184 }
185 else {
186 await vitest._testRun.enqueued(project, file)
187 }
188 },
189 async onCollected(method, files) {
190 if (method === 'collect') {
191 vitest.state.collectFiles(project, files)
192 }
193 else {
194 await vitest._testRun.collected(project, files)
195 }
196 },
197 async onTaskArtifactRecord(id, artifact) {
198 if (!canWrite(project)) {
199 if (artifact.type === 'internal:annotation' && artifact.annotation.attachment) {
200 artifact.annotation.attachment = undefined
201 vitest.logger.error(
202 `[vitest] Cannot record annotation attachment because file writing is disabled. See https://vitest.dev/config/browser/api.`,
203 )
204 }
205 // remove attachments if cannot write
206 if (artifact.attachments?.length) {
207 const attachments = artifact.attachments.map(n => n.path).filter(r => !!r).join('", "')
208 artifact.attachments = []
209 vitest.logger.error(
210 `[vitest] Cannot record attachments ("${attachments}") because file writing is disabled, removing attachments from artifact "${artifact.type}". See https://vitest.dev/config/browser/api.`,
211 )
212 }

Callers 1

setupBrowserRpcFunction · 0.70

Calls 4

stringifyFunction · 0.85
onCancelMethod · 0.80
sendMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected