Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from Apr 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/1.getting-started/11.testing.md
Expand Up @@ -84,6 +84,13 @@ Whether to launch a server to respond to requests in the test suite.
* Type: `boolean`
* Default: `true`

#### `port`

If provided, set the launched test server port to the value.

* Type: `number | undefined`
* Default: `undefined`

#### `build`

Whether to run a separate build step.
Expand Down
2 changes: 1 addition & 1 deletion packages/test-utils/src/server.ts
Expand Up @@ -13,7 +13,7 @@ const kit: typeof _kit = _kit.default || _kit
export async function startServer () {
const ctx = useTestContext()
await stopServer()
const port = await getRandomPort()
const port = ctx.options.port || await getRandomPort()
ctx.url = 'http://127.0.0.1:' + port
if (ctx.options.dev) {
const nuxiCLI = await kit.resolvePath('nuxi/cli')
Expand Down
1 change: 1 addition & 0 deletions packages/test-utils/src/types.ts
Expand Up @@ -23,6 +23,7 @@ export interface TestOptions {
launch?: LaunchOptions
}
server: boolean
port?: number
}

export interface TestContext {
Expand Down