Skip to content

Commit

Permalink
get host for random port too
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Sep 11, 2023
1 parent d8e1e12 commit 42512f5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/test-utils/src/server.ts
Expand Up @@ -13,8 +13,9 @@ const kit: typeof _kit = _kit.default || _kit
export async function startServer () {
const ctx = useTestContext()
await stopServer()
const port = ctx.options.port || await getRandomPort()
ctx.url = 'http://127.0.0.1:' + port
const host = '127.0.0.1'
const port = ctx.options.port || await getRandomPort(host)
ctx.url = `http://${host}:${port}`
if (ctx.options.dev) {
const nuxiCLI = await kit.resolvePath('nuxi/cli')
ctx.serverProcess = execa(nuxiCLI, ['_dev'], {
Expand All @@ -28,7 +29,7 @@ export async function startServer () {
NODE_ENV: 'development'
}
})
await waitForPort(port, { retries: 10, host: '127.0.0.1' }).catch(() => {})
await waitForPort(port, { retries: 10, host }).catch(() => {})
let lastError
for (let i = 0; i < 150; i++) {
await new Promise(resolve => setTimeout(resolve, 100))
Expand All @@ -55,7 +56,7 @@ export async function startServer () {
NODE_ENV: 'test'
}
})
await waitForPort(port, { retries: 8, host: '127.0.0.1' })
await waitForPort(port, { retries: 8, host })
}
}

Expand Down

0 comments on commit 42512f5

Please sign in to comment.