From 4a4180cc29db6aea2b47c2daa7d6da8eb473f1cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Jedlicska?= Date: Fri, 21 Apr 2023 21:24:03 +0200 Subject: [PATCH 1/2] feat(test-utils): add option to configure test server port --- packages/test-utils/src/server.ts | 2 +- packages/test-utils/src/types.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/test-utils/src/server.ts b/packages/test-utils/src/server.ts index 78e803b8ba6b..99c55e60b4e1 100644 --- a/packages/test-utils/src/server.ts +++ b/packages/test-utils/src/server.ts @@ -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') diff --git a/packages/test-utils/src/types.ts b/packages/test-utils/src/types.ts index ab8612ff216a..e40e389da66d 100644 --- a/packages/test-utils/src/types.ts +++ b/packages/test-utils/src/types.ts @@ -23,6 +23,7 @@ export interface TestOptions { launch?: LaunchOptions } server: boolean + port?: number } export interface TestContext { From 2c78968cb8180f6eae5f0bf7d1aee57fe9e12711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Jedlicska?= Date: Fri, 21 Apr 2023 21:32:19 +0200 Subject: [PATCH 2/2] docs(11.testing): add section about the configurable port option --- docs/1.getting-started/11.testing.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/1.getting-started/11.testing.md b/docs/1.getting-started/11.testing.md index 45f06b5707ec..6ae12d8375ae 100644 --- a/docs/1.getting-started/11.testing.md +++ b/docs/1.getting-started/11.testing.md @@ -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.