summaryrefslogtreecommitdiff
path: root/test/parallel
diff options
context:
space:
mode:
authorAleksei Koziatinskii <ak239spb@gmail.com>2019-05-16 15:33:09 -0700
committerAleksei Koziatinskii <ak239spb@gmail.com>2019-06-03 18:15:04 +0300
commitf0018a5152a9faaf2104d62f3152776a60f59390 (patch)
tree786fb50acdeb349a43cbad532670e4b41258d87a /test/parallel
parent7e18c650de419ae98511be3c7bc54b34efc6d3d4 (diff)
downloadnode-new-f0018a5152a9faaf2104d62f3152776a60f59390.tar.gz
inspector: added --inspect-publish-uid
This flag specifies how inspector websocket url should be reported. Tthre options are supported: - stderr - reports websocket as a message to stderr, - http - exposes /json/list endpoint that contains inspector websocket url, - binding - require('inspector').url(). Related discussion: https://github.com/nodejs/diagnostics/issues/303 PR-URL: https://github.com/nodejs/node/pull/27741 Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'test/parallel')
-rw-r--r--test/parallel/test-inspect-publish-uid.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/parallel/test-inspect-publish-uid.js b/test/parallel/test-inspect-publish-uid.js
new file mode 100644
index 0000000000..58d651e97d
--- /dev/null
+++ b/test/parallel/test-inspect-publish-uid.js
@@ -0,0 +1,42 @@
+'use strict';
+const common = require('../common');
+
+common.skipIfInspectorDisabled();
+
+const assert = require('assert');
+const { spawnSync } = require('child_process');
+
+(async function test() {
+ await testArg('stderr');
+ await testArg('http');
+ await testArg('http,stderr');
+})();
+
+async function testArg(argValue) {
+ console.log('Checks ' + argValue + '..');
+ const hasHttp = argValue.split(',').includes('http');
+ const hasStderr = argValue.split(',').includes('stderr');
+
+ const nodeProcess = spawnSync(process.execPath, [
+ '--inspect=0',
+ `--inspect-publish-uid=${argValue}`,
+ '-e', `(${scriptMain.toString()})(${hasHttp ? 200 : 404})`
+ ]);
+ const hasWebSocketInStderr = checkStdError(
+ nodeProcess.stderr.toString('utf8'));
+ assert.strictEqual(hasWebSocketInStderr, hasStderr);
+
+ function checkStdError(data) {
+ const matches = data.toString('utf8').match(/ws:\/\/.+:(\d+)\/.+/);
+ return !!matches;
+ }
+
+ function scriptMain(code) {
+ const url = require('inspector').url();
+ const { host } = require('url').parse(url);
+ require('http').get('http://' + host + '/json/list', (response) => {
+ assert.strictEqual(response.statusCode, code);
+ response.destroy();
+ });
+ }
+}