summaryrefslogtreecommitdiff
path: root/test/parallel/test-debugger-repeat-last.js
blob: 666a7bca743b9fed80c2d550dcf0456b98392b20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
const path = require('path');
const spawn = require('child_process').spawn;
const assert = require('assert');

const common = require('../common');

const fixture = path.join(
  common.fixturesDir,
  'debugger-repeat-last.js'
);

const args = [
  'debug',
  `--port=${common.PORT}`,
  fixture
];

const proc = spawn(process.execPath, args, { stdio: 'pipe' });
proc.stdout.setEncoding('utf8');

var stdout = '';

var sentCommand = false;
var sentEmpty = false;
var sentExit = false;

proc.stdout.on('data', (data) => {
  stdout += data;
  if (!sentCommand && stdout.includes('> 1')) {
    setImmediate(() => {proc.stdin.write('n\n');});
    return sentCommand = true;
  }
  if (!sentEmpty && stdout.includes('> 3')) {
    setImmediate(() => {proc.stdin.write('\n');});
    return sentEmpty = true;
  }
  if (!sentExit && sentCommand && sentEmpty) {
    setTimeout(() => {proc.stdin.write('\n\n\n.exit\n\n\n');}, 1);
    return sentExit = true;
  }
});

process.on('exit', (exitCode) => {
  assert.strictEqual(exitCode, 0);
  console.log(stdout);
});