|
2 | 2 |
|
3 | 3 | const common = require('../common'); |
4 | 4 | common.skipIfInspectorDisabled(); |
| 5 | +const assert = require('assert'); |
| 6 | +const fixtures = require('../common/fixtures'); |
5 | 7 | const spawn = require('child_process').spawn; |
6 | 8 |
|
7 | | -const proc = spawn(process.execPath, ['inspect', 'foo']); |
| 9 | +const proc = spawn(process.execPath, [ |
| 10 | + 'inspect', fixtures.path('debugger', 'alive.js'), |
| 11 | +]); |
8 | 12 | proc.stdout.setEncoding('utf8'); |
9 | 13 |
|
10 | | -let needToSendExit = true; |
| 14 | +const TIMEOUT = common.platformTimeout(10_000); |
11 | 15 | let output = ''; |
12 | | -proc.stdout.on('data', (data) => { |
13 | | - output += data; |
14 | | - if (output.includes('debug> ') && needToSendExit) { |
15 | | - proc.stdin.write('.exit\n'); |
16 | | - needToSendExit = false; |
17 | | - } |
18 | | -}); |
| 16 | +let promptSeen = false; |
| 17 | + |
| 18 | +(async () => { |
| 19 | + await new Promise((resolve, reject) => { |
| 20 | + const timer = setTimeout(() => { |
| 21 | + proc.kill(); |
| 22 | + reject(new Error(`Timed out waiting for the debugger prompt; output: ${output}`)); |
| 23 | + }, TIMEOUT); |
| 24 | + |
| 25 | + proc.stdout.on('data', (data) => { |
| 26 | + output += data; |
| 27 | + if (output.includes('debug> ') && !promptSeen) { |
| 28 | + promptSeen = true; |
| 29 | + proc.stdin.end('.exit\n'); |
| 30 | + } |
| 31 | + }); |
| 32 | + |
| 33 | + proc.once('error', reject); |
| 34 | + proc.once('close', common.mustCall((code, signal) => { |
| 35 | + clearTimeout(timer); |
| 36 | + if (!promptSeen) { |
| 37 | + reject(new Error( |
| 38 | + `Debugger exited before showing the prompt (code ${code}, signal ${signal}); ` + |
| 39 | + `output: ${output}`)); |
| 40 | + return; |
| 41 | + } |
| 42 | + assert.strictEqual(code, 0); |
| 43 | + resolve(); |
| 44 | + })); |
| 45 | + }); |
| 46 | +})().then(common.mustCall()); |
0 commit comments