vite/playground/ssr-html/test-network-imports.js
Hiroshi Ogawa 7f9f8c6851
fix: use websocket to test server liveness before client reload (#17891)
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
2024-10-25 13:54:11 +09:00

28 lines
755 B
JavaScript

import assert from 'node:assert'
import { fileURLToPath } from 'node:url'
import { createServer, createServerModuleRunner } from 'vite'
async function runTest(userRunner) {
const server = await createServer({
configFile: false,
root: fileURLToPath(new URL('.', import.meta.url)),
server: {
middlewareMode: true,
ws: false,
},
})
let mod
if (userRunner) {
const runner = await createServerModuleRunner(server.environments.ssr, {
hmr: false,
})
mod = await runner.import('/src/network-imports.js')
} else {
mod = await server.ssrLoadModule('/src/network-imports.js')
}
assert.equal(mod.slash('foo\\bar'), 'foo/bar')
await server.close()
}
runTest(process.argv.includes('--module-runner'))