Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: harden debugger prompt test
Use a long-lived debugger target and assert that the prompt is received
before sending the exit command.

Handle child exit and timeout failures explicitly instead of leaving the
test hanging when startup does not produce a prompt.

Signed-off-by: Matteo Collina <[email protected]>
  • Loading branch information
mcollina committed Jul 26, 2026
commit 9e4ff2c2518aac8aeacef7a86a66dcb12ee863d1
46 changes: 37 additions & 9 deletions test/sequential/test-debug-prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,45 @@

const common = require('../common');
common.skipIfInspectorDisabled();
const assert = require('assert');
const fixtures = require('../common/fixtures');
const spawn = require('child_process').spawn;

const proc = spawn(process.execPath, ['inspect', 'foo']);
const proc = spawn(process.execPath, [
'inspect', fixtures.path('debugger', 'alive.js'),
]);
proc.stdout.setEncoding('utf8');

let needToSendExit = true;
const TIMEOUT = common.platformTimeout(10_000);
let output = '';
proc.stdout.on('data', (data) => {
output += data;
if (output.includes('debug> ') && needToSendExit) {
proc.stdin.write('.exit\n');
needToSendExit = false;
}
});
let promptSeen = false;

(async () => {
await new Promise((resolve, reject) => {
const timer = setTimeout(() => {
proc.kill();
reject(new Error(`Timed out waiting for the debugger prompt; output: ${output}`));
}, TIMEOUT);

proc.stdout.on('data', (data) => {
output += data;
if (output.includes('debug> ') && !promptSeen) {
promptSeen = true;
proc.stdin.end('.exit\n');
}
});

proc.once('error', reject);
proc.once('close', common.mustCall((code, signal) => {
clearTimeout(timer);
if (!promptSeen) {
reject(new Error(
`Debugger exited before showing the prompt (code ${code}, signal ${signal}); ` +
`output: ${output}`));
return;
}
assert.strictEqual(code, 0);
resolve();
}));
});
})().then(common.mustCall());
Loading