test: fix flaky test-debug-prompt

Be sure to send `.exit` only once to avoid spurious EPIPE and possibly
other errors.

Fixes: https://github.com/nodejs/node/issues/21724

PR-URL: https://github.com/nodejs/node/pull/21826
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
This commit is contained in:
Rich Trott 2018-07-15 10:52:36 -07:00
parent a8ec288884
commit df97126173

View File

@ -7,9 +7,12 @@ const spawn = require('child_process').spawn;
const proc = spawn(process.execPath, ['inspect', 'foo']);
proc.stdout.setEncoding('utf8');
let needToSendExit = true;
let output = '';
proc.stdout.on('data', (data) => {
output += data;
if (output.includes('debug> '))
if (output.includes('debug> ') && needToSendExit) {
proc.stdin.write('.exit\n');
needToSendExit = false;
}
});