Skip to content

Commit

Permalink
test: remove unused transport
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Dec 4, 2024
1 parent 72ee49b commit 0a1db74
Showing 1 changed file with 0 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,46 +1,10 @@
import { BroadcastChannel, Worker } from 'node:worker_threads'
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
import type { HotChannel, HotChannelListener, HotPayload } from 'vite'
import type { BirpcReturn } from 'birpc'
import { createBirpc } from 'birpc'
import { DevEnvironment } from '../../..'
import { type ViteDevServer, createServer } from '../../../server'

const createWorkerTransport = (w: Worker): HotChannel => {
const handlerToWorkerListener = new WeakMap<
HotChannelListener,
(value: HotPayload) => void
>()

return {
send: (data) => w.postMessage(data),
on: (event: string, handler: HotChannelListener) => {
if (event === 'connection') return

const listener = (value: HotPayload) => {
if (value.type === 'custom' && value.event === event) {
const client = {
send(payload: HotPayload) {
w.postMessage(payload)
},
}
handler(value.data, client)
}
}
handlerToWorkerListener.set(handler, listener)
w.on('message', listener)
},
off: (event, handler: HotChannelListener) => {
if (event === 'connection') return
const listener = handlerToWorkerListener.get(handler)
if (listener) {
w.off('message', listener)
handlerToWorkerListener.delete(handler)
}
},
}
}

describe('running module runner inside a worker and using the ModuleRunnerTransport#invoke API', () => {
let worker: Worker
let server: ViteDevServer
Expand Down Expand Up @@ -77,7 +41,6 @@ describe('running module runner inside a worker and using the ModuleRunnerTransp
createEnvironment: (name, config) => {
return new DevEnvironment(name, config, {
hot: false,
transport: createWorkerTransport(worker),
})
},
},
Expand Down

0 comments on commit 0a1db74

Please sign in to comment.