feat(test-utils): add option to configure test server port (#20443)

This commit is contained in:
Gergő Jedlicska 2023-04-30 00:01:10 +01:00 committed by GitHub
parent 24cce84e4b
commit 4e7206bfab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View File

@ -84,6 +84,13 @@ Whether to launch a server to respond to requests in the test suite.
* Type: `boolean` * Type: `boolean`
* Default: `true` * Default: `true`
#### `port`
If provided, set the launched test server port to the value.
* Type: `number | undefined`
* Default: `undefined`
#### `build` #### `build`
Whether to run a separate build step. Whether to run a separate build step.

View File

@ -13,7 +13,7 @@ const kit: typeof _kit = _kit.default || _kit
export async function startServer () { export async function startServer () {
const ctx = useTestContext() const ctx = useTestContext()
await stopServer() await stopServer()
const port = await getRandomPort() const port = ctx.options.port || await getRandomPort()
ctx.url = 'http://127.0.0.1:' + port ctx.url = 'http://127.0.0.1:' + port
if (ctx.options.dev) { if (ctx.options.dev) {
const nuxiCLI = await kit.resolvePath('nuxi/cli') const nuxiCLI = await kit.resolvePath('nuxi/cli')

View File

@ -23,6 +23,7 @@ export interface TestOptions {
launch?: LaunchOptions launch?: LaunchOptions
} }
server: boolean server: boolean
port?: number
} }
export interface TestContext { export interface TestContext {