From a2013a58653c15fa2da5b4a992b82f1448b4277b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=BCller?= Date: Wed, 26 Jan 2022 10:41:58 +0100 Subject: [PATCH] feat(cli): add `--no-open` option (#635) --- docs/guide/index.md | 3 ++- packages/vitest/src/node/cli.ts | 3 ++- packages/vitest/src/node/plugins/index.ts | 2 +- packages/vitest/src/types/config.ts | 9 ++++++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/guide/index.md b/docs/guide/index.md index 9d4999677a44..e501a37698ac 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -103,7 +103,8 @@ You can specify additional CLI options like `--port` or `--https`. For a full li | `-u, --update` | Update snapshots | | `-w, --watch` | Watch mode | | `-t, --testNamePattern ` | Run tests with names matching the pattern | -| `--ui` | Open UI | +| `--ui` | Enable UI | +| `--open` | Open the UI automatically if enabled (default: true) | | `--api [api]` | Serve API, available options: `--api.port `, `--api.host [host]` and `--api.strictPort` | | `--threads` | Enable Threads (default: true) | | `--silent` | Silent console output from tests | diff --git a/packages/vitest/src/node/cli.ts b/packages/vitest/src/node/cli.ts index ac55bd2ab7c3..735426203115 100644 --- a/packages/vitest/src/node/cli.ts +++ b/packages/vitest/src/node/cli.ts @@ -14,7 +14,8 @@ cli .option('-u, --update', 'update snapshot') .option('-w, --watch', 'watch mode') .option('-t, --testNamePattern ', 'run test names with the specified pattern') - .option('--ui', 'open UI') + .option('--ui', 'enable UI') + .option('--open', 'open UI automatically', { default: true }) .option('--api [api]', 'serve API, available options: --api.port , --api.host [host] and --api.strictPort') .option('--threads', 'enabled threads', { default: true }) .option('--silent', 'silent console output from tests') diff --git a/packages/vitest/src/node/plugins/index.ts b/packages/vitest/src/node/plugins/index.ts index a57cfff36d28..fbf003fa0211 100644 --- a/packages/vitest/src/node/plugins/index.ts +++ b/packages/vitest/src/node/plugins/index.ts @@ -30,7 +30,7 @@ export async function VitestPlugin(options: UserConfig = {}, viteOverrides: Vite }, server: { ...options.api, - open: options.ui + open: options.ui && options.open ? options.uiBase ?? '/__vitest__/' : undefined, preTransformRequests: false, diff --git a/packages/vitest/src/types/config.ts b/packages/vitest/src/types/config.ts index 4d0bfec5a8d1..16a17c9cd001 100644 --- a/packages/vitest/src/types/config.ts +++ b/packages/vitest/src/types/config.ts @@ -232,11 +232,18 @@ export interface InlineConfig { api?: boolean | number | ApiConfig /** - * Open Vitest UI + * Enable Vitest UI * @internal WIP */ ui?: boolean + /** + * Open UI automatically. + * + * @default true + */ + open?: boolean + /** * Base url for the UI *