diff --git a/docs/config/index.md b/docs/config/index.md index e94262dea8af..f3835b3ffd82 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -686,11 +686,15 @@ Update snapshot files. This will update all changed snapshots and delete obsolet ### watch - **Type:** `boolean` -- **Default:** `!process.env.CI` +- **Default:** `!process.env.CI && process.stdin.isTTY` - **CLI:** `-w`, `--watch`, `--watch=false` Enable watch mode +In interactive environments, this is the default, unless `--run` is specified explicitly. + +In CI, or when run from a non-interactive shell, "watch" mode is not the default, but can be enabled explicitly with this flag. + ### root - **Type:** `string` diff --git a/docs/guide/cli.md b/docs/guide/cli.md index deb22903d45e..a6e6939e59aa 100644 --- a/docs/guide/cli.md +++ b/docs/guide/cli.md @@ -9,7 +9,7 @@ outline: deep ### `vitest` -Start Vitest in the current directory. Will enter the watch mode in development environment and run mode in CI automatically. +Start Vitest in the current directory. Will enter the watch mode in development environment and run mode in CI (or non-interactive terminal) automatically. You can pass an additional argument as the filter of the test files to run. For example: @@ -50,7 +50,7 @@ Perform a single run without watch mode. ### `vitest watch` -Run all test suites but watch for changes and rerun tests when they change. Same as calling `vitest` without an argument. Will fallback to `vitest run` in CI. +Run all test suites but watch for changes and rerun tests when they change. Same as calling `vitest` without an argument. Will fallback to `vitest run` in CI or when stdin is not a TTY (non-interactive environment). ### `vitest dev` diff --git a/packages/vitest/src/defaults.ts b/packages/vitest/src/defaults.ts index 1206405ddcfa..059645f46048 100644 --- a/packages/vitest/src/defaults.ts +++ b/packages/vitest/src/defaults.ts @@ -131,7 +131,7 @@ export const configDefaults: Readonly<{ }> = Object.freeze({ allowOnly: !isCI, isolate: true, - watch: !isCI, + watch: !isCI && process.stdin.isTTY, globals: false, environment: 'node' as const, pool: 'forks' as const,