From 7ee9534a80f54126a695a6d0025d30d87a8a0a88 Mon Sep 17 00:00:00 2001 From: iclectic Date: Sun, 5 Jul 2026 13:12:02 +0100 Subject: [PATCH] repl: reject --watch without script --- src/node_options.cc | 2 +- test/sequential/test-watch-mode-watch-flags.mjs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/node_options.cc b/src/node_options.cc index ca12586e479b99..917ba7453d6d80 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -266,7 +266,7 @@ void EnvironmentOptions::CheckOptions(std::vector* errors, } else if (test_runner_force_exit) { errors->push_back("either --watch or --test-force-exit " "can be used, not both"); - } else if (!test_runner && watch_mode_paths.empty() && argv->size() < 1) { + } else if (!test_runner && watch_mode_paths.empty() && argv->size() < 2) { errors->push_back("--watch requires specifying a file"); } diff --git a/test/sequential/test-watch-mode-watch-flags.mjs b/test/sequential/test-watch-mode-watch-flags.mjs index 385f381ad6a0ed..91a96d5269c51b 100644 --- a/test/sequential/test-watch-mode-watch-flags.mjs +++ b/test/sequential/test-watch-mode-watch-flags.mjs @@ -51,6 +51,15 @@ async function runNode({ tmpdir.refresh(); describe('watch mode - watch flags', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_000 }, () => { + it('should require a file to watch', async () => { + const { code, signal, stderr, stdout } = await common.spawnPromisified(execPath, ['--watch']); + + assert.strictEqual(code, 9); + assert.strictEqual(signal, null); + assert.match(stderr, /--watch requires specifying a file/); + assert.strictEqual(stdout, ''); + }); + it('when multiple `--watch` flags are provided should run as if only one was', async () => { const projectDir = tmpdir.resolve('project-multi-flag'); mkdirSync(projectDir);