forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-debugger-remote.js
More file actions
61 lines (51 loc) · 1.76 KB
/
test-debugger-remote.js
File metadata and controls
61 lines (51 loc) · 1.76 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;
const path = require('path');
const PORT = common.PORT;
const scriptToDebug = path.join(common.fixturesDir, 'empty.js');
// running with debug agent
const child = spawn(process.execPath, [`--debug-brk=${PORT}`, scriptToDebug]);
// connect to debug agent
const interfacer = spawn(process.execPath, ['debug', `localhost:${PORT}`]);
interfacer.stdout.setEncoding('utf-8');
// fail the test if either of the processes exit normally
const debugBreakExit = common.mustNotCall('child should not exit normally');
const debugExit = common.mustNotCall('interfacer should not exit normally');
child.on('exit', debugBreakExit);
interfacer.on('exit', debugExit);
let buffer = '';
const expected = [
`\bconnecting to localhost:${PORT} ... ok`,
'\bbreak in test/fixtures/empty.js:2'
];
const actual = [];
interfacer.stdout.on('data', function(data) {
data = (buffer + data).split('\n');
buffer = data.pop();
data.forEach(function(line) {
interfacer.emit('line', line);
});
});
interfacer.on('line', function(line) {
line = line.replace(/^(debug> *)+/, '');
if (expected.includes(line)) {
actual.push(line);
}
});
// allow time to start up the debugger
setTimeout(function() {
// remove the exit handlers before killing the processes
child.removeListener('exit', debugBreakExit);
interfacer.removeListener('exit', debugExit);
child.kill();
interfacer.kill();
}, common.platformTimeout(2000));
process.on('exit', function() {
// additional checks to ensure that both the processes were actually killed
assert(child.killed);
assert(interfacer.killed);
assert.deepStrictEqual(actual, expected);
});
interfacer.stderr.pipe(process.stderr);