Files
node/test/parallel/test-debugger-inspect-help-forwarding.mjs
T
Joyee Cheung 78bbee385b debugger: add --help to node inspect and improve docs
- Add `--help` / `-h` to `node inspect` covering both interactive and
  non-interactive probe modes. The help text is printed when
  `--help`/`-h` appears before any positional argument to avoid
  hijacking `--help` passed to a child script.
- Improve the documentation of probe mode and add examples, explain
  same-location probe coalescing, TDZ caveat for let/const bindings,
  basename matching and exit code behavior. Also move it to a
  section parallel to interactive mode. Remove recommendation of
  evaluating structured expressions as that is prone to missing
  info in JSON mode.

Drive-by: When probe mode exits due to invalid arguments, exit with
`kInvalidCommandLineArgument` (9) instead of `kGenericUserError` (1).

Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/63201
Reviewed-By: Jan Martin <jan.krems@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Aviv Keller <me@aviv.sh>
2026-05-11 21:54:19 +00:00

35 lines
1018 B
JavaScript

// Tests that --help / -h are forwarded to the debuggee when a script is
// also passed, instead of being hijacked as the inspect help flag.
import { skipIfInspectorDisabled } from '../common/index.mjs';
skipIfInspectorDisabled();
import * as fixtures from '../common/fixtures.mjs';
import startCLI from '../common/debugger.js';
import assert from 'assert';
async function getEvaluatedArgv(flag) {
const script = fixtures.path('debugger', 'empty.js');
const cli = startCLI([script, flag]);
try {
await cli.waitForInitialBreak();
await cli.waitForPrompt();
await cli.command('exec process.argv');
return cli.output;
} finally {
await cli.quit();
}
}
async function checkForwardedHelp(flag) {
const output = await getEvaluatedArgv(flag);
assert(output.includes(`'${flag}'`),
`expected debuggee process.argv to include "${flag}", got:\n${output}`);
assert.doesNotMatch(output, /Usage: .+ inspect/);
}
await checkForwardedHelp('--help');
await checkForwardedHelp('-h');