diff options
author | Jon Moss <me@jonathanmoss.me> | 2017-10-13 22:42:38 -0400 |
---|---|---|
committer | Refael Ackermann <refack@gmail.com> | 2017-10-17 19:35:50 -0400 |
commit | 978629ca1240b9f2038390c7e960f3d226daa4e8 (patch) | |
tree | 8c15fba04351dfb1921221f930157957317dae4f /test/parallel/test-inspector-port-zero.js | |
parent | ff747e3fe8fc960bb6cd04185167bd6376940998 (diff) | |
download | node-new-978629ca1240b9f2038390c7e960f3d226daa4e8.tar.gz |
test: move inspector tests to parallel/sequential
* remove inspector directory artifacts
PR-URL: https://github.com/nodejs/node/pull/16197
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-inspector-port-zero.js')
-rw-r--r-- | test/parallel/test-inspector-port-zero.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/parallel/test-inspector-port-zero.js b/test/parallel/test-inspector-port-zero.js new file mode 100644 index 0000000000..a3eb08e5fb --- /dev/null +++ b/test/parallel/test-inspector-port-zero.js @@ -0,0 +1,53 @@ +'use strict'; +const { mustCall, skipIfInspectorDisabled } = require('../common'); + +skipIfInspectorDisabled(); + +const assert = require('assert'); +const { URL } = require('url'); +const { spawn } = require('child_process'); + +function test(arg, port = '') { + const args = [arg, '-p', 'process.debugPort']; + const proc = spawn(process.execPath, args); + proc.stdout.setEncoding('utf8'); + proc.stderr.setEncoding('utf8'); + let stdout = ''; + let stderr = ''; + proc.stdout.on('data', (data) => stdout += data); + proc.stderr.on('data', (data) => stderr += data); + proc.stdout.on('close', assert.ifError); + proc.stderr.on('close', assert.ifError); + proc.stderr.on('data', () => { + if (!stderr.includes('\n')) return; + assert(/Debugger listening on (.+)/.test(stderr)); + port = new URL(RegExp.$1).port; + assert(+port > 0); + }); + if (/inspect-brk/.test(arg)) { + proc.stderr.on('data', () => { + if (stderr.includes('\n') && !proc.killed) proc.kill(); + }); + } else { + let onclose = () => { + onclose = () => assert.strictEqual(port, stdout.trim()); + }; + proc.stdout.on('close', mustCall(() => onclose())); + proc.stderr.on('close', mustCall(() => onclose())); + proc.on('exit', mustCall((exitCode) => assert.strictEqual(exitCode, 0))); + } +} + +test('--inspect=0'); +test('--inspect=127.0.0.1:0'); +test('--inspect=localhost:0'); + +test('--inspect-brk=0'); +test('--inspect-brk=127.0.0.1:0'); +test('--inspect-brk=localhost:0'); + +// In these cases, the inspector doesn't listen, so an ephemeral port is not +// allocated and the expected value of `process.debugPort` is `0`. +test('--inspect-port=0', '0'); +test('--inspect-port=127.0.0.1:0', '0'); +test('--inspect-port=localhost:0', '0'); |