• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3common.skipIfInspectorDisabled();
4const path = require('../common/fixtures').path;
5const spawn = require('child_process').spawn;
6const assert = require('assert');
7const fixture = path('debugger-repeat-last.js');
8
9const args = [
10  'inspect',
11  `--port=${common.PORT}`,
12  fixture,
13];
14
15const proc = spawn(process.execPath, args, { stdio: 'pipe' });
16proc.stdout.setEncoding('utf8');
17
18let stdout = '';
19
20let sentCommand = false;
21let sentExit = false;
22
23proc.stdout.on('data', (data) => {
24  stdout += data;
25
26  // Send 'n' as the first step.
27  if (!sentCommand && stdout.includes('> 1 ')) {
28    setImmediate(() => { proc.stdin.write('n\n'); });
29    return sentCommand = true;
30  }
31  // Send empty (repeat last command) until we reach line 5.
32  if (sentCommand && !stdout.includes('> 5')) {
33    setImmediate(() => { proc.stdin.write('\n'); });
34    return true;
35  }
36  if (!sentExit && stdout.includes('> 5')) {
37    setTimeout(() => { proc.stdin.write('\n\n\n.exit\n\n\n'); }, 1);
38    return sentExit = true;
39  }
40});
41
42process.on('exit', (exitCode) => {
43  assert.strictEqual(exitCode, 0);
44  console.log(stdout);
45});
46