2016-04-06 00:17:33 +00:00
|
|
|
'use strict';
|
2016-07-18 20:33:42 +00:00
|
|
|
const common = require('../common');
|
2017-04-24 14:13:21 +00:00
|
|
|
common.skipIfInspectorDisabled();
|
2017-08-09 17:29:40 +00:00
|
|
|
const path = require('../common/fixtures').path;
|
2016-04-06 00:17:33 +00:00
|
|
|
const spawn = require('child_process').spawn;
|
|
|
|
const assert = require('assert');
|
2017-08-09 17:29:40 +00:00
|
|
|
const fixture = path('debugger-repeat-last.js');
|
2016-04-06 00:17:33 +00:00
|
|
|
|
|
|
|
const args = [
|
2017-04-24 14:13:21 +00:00
|
|
|
'inspect',
|
2023-03-27 22:03:40 +00:00
|
|
|
'--port=0',
|
2021-03-26 15:51:08 +00:00
|
|
|
fixture,
|
2016-04-06 00:17:33 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const proc = spawn(process.execPath, args, { stdio: 'pipe' });
|
|
|
|
proc.stdout.setEncoding('utf8');
|
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
let stdout = '';
|
2016-04-06 00:17:33 +00:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
let sentCommand = false;
|
|
|
|
let sentExit = false;
|
2016-04-06 00:17:33 +00:00
|
|
|
|
|
|
|
proc.stdout.on('data', (data) => {
|
|
|
|
stdout += data;
|
2017-03-14 21:20:38 +00:00
|
|
|
|
|
|
|
// Send 'n' as the first step.
|
|
|
|
if (!sentCommand && stdout.includes('> 1 ')) {
|
2016-12-21 05:54:04 +00:00
|
|
|
setImmediate(() => { proc.stdin.write('n\n'); });
|
2016-04-06 00:17:33 +00:00
|
|
|
return sentCommand = true;
|
|
|
|
}
|
2017-03-14 21:20:38 +00:00
|
|
|
// Send empty (repeat last command) until we reach line 5.
|
|
|
|
if (sentCommand && !stdout.includes('> 5')) {
|
2016-12-21 05:54:04 +00:00
|
|
|
setImmediate(() => { proc.stdin.write('\n'); });
|
2017-03-14 21:20:38 +00:00
|
|
|
return true;
|
2016-04-06 00:17:33 +00:00
|
|
|
}
|
2017-03-14 21:20:38 +00:00
|
|
|
if (!sentExit && stdout.includes('> 5')) {
|
2016-12-21 05:54:04 +00:00
|
|
|
setTimeout(() => { proc.stdin.write('\n\n\n.exit\n\n\n'); }, 1);
|
2016-04-06 00:17:33 +00:00
|
|
|
return sentExit = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
process.on('exit', (exitCode) => {
|
|
|
|
assert.strictEqual(exitCode, 0);
|
|
|
|
console.log(stdout);
|
|
|
|
});
|