mirror of
https://github.com/hanzoai/vite.git
synced 2026-10-30 19:36:16 +00:00
39 lines
971 B
TypeScript
39 lines
971 B
TypeScript
// this is automatically detected by playground/vitestSetup.ts and will replace
|
|
// the default e2e test serve behavior
|
|
|
|
import path from 'node:path'
|
|
import kill from 'kill-port'
|
|
import { hmrPorts, ports, rootDir } from '~utils'
|
|
|
|
export const port = ports['css/lightningcss-proxy']
|
|
|
|
export async function serve(): Promise<{ close(): Promise<void> }> {
|
|
await kill(port)
|
|
|
|
const { createServer } = await import(path.resolve(rootDir, 'server.js'))
|
|
const { app, vite } = await createServer(
|
|
rootDir,
|
|
hmrPorts['css/lightningcss-proxy'],
|
|
)
|
|
|
|
return new Promise((resolve, reject) => {
|
|
try {
|
|
const server = app.listen(port, () => {
|
|
resolve({
|
|
// for test teardown
|
|
async close() {
|
|
await new Promise((resolve) => {
|
|
server.close(resolve)
|
|
})
|
|
if (vite) {
|
|
await vite.close()
|
|
}
|
|
},
|
|
})
|
|
})
|
|
} catch (e) {
|
|
reject(e)
|
|
}
|
|
})
|
|
}
|