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

Function sendOnMessage

test/core/test/web-worker-node.test.ts:281–293  ·  view source on GitHub ↗
(worker: SharedWorker, msg: any)

Source from the content-addressed store, hash-verified

279}
280
281function sendOnMessage(worker: SharedWorker, msg: any) {
282 return new Promise<string>((resolve, reject) => {
283 const timeout = setTimeout(() => {
284 reject(new Error(`Failed to send the message ${msg} to the SharedWorker.`))
285 }, 5_000)
286 worker.port.onmessage = function onmessage(e) {
287 worker.port.onmessage = null
288 clearTimeout(timeout)
289 resolve(e.data as string)
290 }
291 worker.port.postMessage(msg)
292 })
293}
294
295it('vite shared worker works', async () => {
296 expect(MySharedWorker).toBeDefined()

Callers 1

Calls 3

rejectFunction · 0.70
resolveFunction · 0.70
postMessageMethod · 0.45

Tested by

no test coverage detected