summaryrefslogtreecommitdiff
path: root/test/parallel/test-repl-inspector.js
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2017-10-29 18:19:24 +0100
committerMichaël Zasso <targos@protonmail.com>2017-12-21 14:47:29 +0100
commit416c0ec95267b4dd9d442bd624f5a7f64be76f2e (patch)
tree05a56c3de05bd1bbd824d82e0000ce054484b8d4 /test/parallel/test-repl-inspector.js
parentd1d6b54b698f964ae030414472db34ea45aecb39 (diff)
downloadandroid-node-v8-416c0ec95267b4dd9d442bd624f5a7f64be76f2e.tar.gz
android-node-v8-416c0ec95267b4dd9d442bd624f5a7f64be76f2e.tar.bz2
android-node-v8-416c0ec95267b4dd9d442bd624f5a7f64be76f2e.zip
repl: show lexically scoped vars in tab completion
Use the V8 inspector protocol, if available, to query the list of lexically scoped variables (defined with `let`, `const` or `class`). PR-URL: https://github.com/nodejs/node/pull/16591 Fixes: https://github.com/nodejs/node/issues/983 Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/parallel/test-repl-inspector.js')
-rw-r--r--test/parallel/test-repl-inspector.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/parallel/test-repl-inspector.js b/test/parallel/test-repl-inspector.js
new file mode 100644
index 0000000000..b02f6139e7
--- /dev/null
+++ b/test/parallel/test-repl-inspector.js
@@ -0,0 +1,34 @@
+'use strict';
+
+const common = require('../common');
+const assert = require('assert');
+const repl = require('repl');
+
+common.skipIfInspectorDisabled();
+
+// This test verifies that the V8 inspector API is usable in the REPL.
+
+const putIn = new common.ArrayStream();
+let output = '';
+putIn.write = function(data) {
+ output += data;
+};
+
+const testMe = repl.start('', putIn);
+
+putIn.run(['const myVariable = 42']);
+
+testMe.complete('myVar', common.mustCall((error, data) => {
+ assert.deepStrictEqual(data, [['myVariable'], 'myVar']);
+}));
+
+putIn.run([
+ 'const inspector = require("inspector")',
+ 'const session = new inspector.Session()',
+ 'session.connect()',
+ 'session.post("Runtime.evaluate", { expression: "1 + 1" }, console.log)',
+ 'session.disconnect()'
+]);
+
+assert(output.includes(
+ "null { result: { type: 'number', value: 2, description: '2' } }"));