forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-debug-prompt.js
More file actions
46 lines (40 loc) · 1.23 KB
/
Copy pathtest-debug-prompt.js
File metadata and controls
46 lines (40 loc) · 1.23 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
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const assert = require('assert');
const fixtures = require('../common/fixtures');
const spawn = require('child_process').spawn;
const proc = spawn(process.execPath, [
'inspect', fixtures.path('debugger', 'alive.js'),
]);
proc.stdout.setEncoding('utf8');
const TIMEOUT = common.platformTimeout(10_000);
let output = '';
let promptSeen = false;
(async () => {
await new Promise((resolve, reject) => {
const timer = setTimeout(() => {
proc.kill();
reject(new Error(`Timed out waiting for the debugger prompt; output: ${output}`));
}, TIMEOUT);
proc.stdout.on('data', (data) => {
output += data;
if (output.includes('debug> ') && !promptSeen) {
promptSeen = true;
proc.stdin.end('.exit\n');
}
});
proc.once('error', reject);
proc.once('close', common.mustCall((code, signal) => {
clearTimeout(timer);
if (!promptSeen) {
reject(new Error(
`Debugger exited before showing the prompt (code ${code}, signal ${signal}); ` +
`output: ${output}`));
return;
}
assert.strictEqual(code, 0);
resolve();
}));
});
})().then(common.mustCall());