|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const { mustCall } = require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | +const { URL } = require('url'); |
| 6 | +const { spawn } = require('child_process'); |
| 7 | + |
| 8 | +function test(arg) { |
| 9 | + const args = [arg, '-p', 'process.debugPort']; |
| 10 | + const proc = spawn(process.execPath, args); |
| 11 | + proc.stdout.setEncoding('utf8'); |
| 12 | + proc.stderr.setEncoding('utf8'); |
| 13 | + let stdout = ''; |
| 14 | + let stderr = ''; |
| 15 | + proc.stdout.on('data', (data) => stdout += data); |
| 16 | + proc.stderr.on('data', (data) => stderr += data); |
| 17 | + proc.stdout.on('close', assert.ifError); |
| 18 | + proc.stderr.on('close', assert.ifError); |
| 19 | + let port = ''; |
| 20 | + proc.stderr.on('data', () => { |
| 21 | + if (!stderr.includes('\n')) return; |
| 22 | + assert(/Debugger listening on (.+)/.test(stderr)); |
| 23 | + port = new URL(RegExp.$1).port; |
| 24 | + assert(+port > 0); |
| 25 | + }); |
| 26 | + if (/inspect-brk/.test(arg)) { |
| 27 | + proc.stderr.on('data', () => { |
| 28 | + if (stderr.includes('\n') && !proc.killed) proc.kill(); |
| 29 | + }); |
| 30 | + } else { |
| 31 | + let onclose = () => { |
| 32 | + onclose = () => assert.strictEqual(port, stdout.trim()); |
| 33 | + }; |
| 34 | + proc.stdout.on('close', mustCall(() => onclose())); |
| 35 | + proc.stderr.on('close', mustCall(() => onclose())); |
| 36 | + proc.on('exit', mustCall((exitCode) => assert.strictEqual(exitCode, 0))); |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +test('--inspect=0'); |
| 41 | +test('--inspect=127.0.0.1:0'); |
| 42 | +test('--inspect=localhost:0'); |
| 43 | + |
| 44 | +test('--inspect-brk=0'); |
| 45 | +test('--inspect-brk=127.0.0.1:0'); |
| 46 | +test('--inspect-brk=localhost:0'); |
0 commit comments