node/test/parallel/test-debugger-inspect-help.js
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

37 lines
972 B
JavaScript

'use strict';
// Tests that `node inspect` help text is printed when
// `--help` / `-h` is passed and there is no script,
// or when there are no additional arguments.
const common = require('../common');
common.skipIfInspectorDisabled();
const {
spawnSyncAndAssert,
spawnSyncAndExit,
} = require('../common/child_process');
const usageRegex = /^Usage: .+ inspect .*debugger\.html/ms;
// --help / -h prints the usage to stdout and exits with code 0,
// for both interactive and probe-mode invocations.
const helpArgs = [
['inspect', '--help'],
['inspect', '-h'],
['inspect', '--probe', '--help'],
['inspect', '--probe', '-h'],
];
for (const args of helpArgs) {
spawnSyncAndAssert(process.execPath, args, {
stdout: usageRegex,
});
}
// `node inspect` with no args prints the usage to stderr and exits
// with kInvalidCommandLineArgument (9).
spawnSyncAndExit(process.execPath, ['inspect'], {
status: 9,
signal: null,
stderr: usageRegex,
});