|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const repl = require('repl'); |
| 5 | +const ArrayStream = require('../common/arraystream'); |
| 6 | +const assert = require('assert'); |
| 7 | + |
| 8 | +const completionTests = [ |
| 9 | + { send: 'Promise.reject().' }, |
| 10 | + { send: 'let p = Promise.reject().' }, |
| 11 | + { send: 'Promise.resolve().' }, |
| 12 | + { send: 'Promise.resolve().then(() => {}).' }, |
| 13 | + { send: `async function f() {throw new Error('test');}; f().` }, |
| 14 | + { send: `async function f() {}; f().` }, |
| 15 | +]; |
| 16 | + |
| 17 | +(async function() { |
| 18 | + await runReplCompleteTests(completionTests); |
| 19 | +})().then(common.mustCall()); |
| 20 | + |
| 21 | +async function runReplCompleteTests(tests) { |
| 22 | + const input = new ArrayStream(); |
| 23 | + const output = new ArrayStream(); |
| 24 | + |
| 25 | + const replServer = repl.start({ |
| 26 | + prompt: '', |
| 27 | + input, |
| 28 | + output: output, |
| 29 | + allowBlockingCompletions: true, |
| 30 | + terminal: true |
| 31 | + }); |
| 32 | + |
| 33 | + replServer._domain.on('error', (e) => { |
| 34 | + assert.fail(`Error in REPL domain: ${e}`); |
| 35 | + }); |
| 36 | + for (const { send } of tests) { |
| 37 | + replServer.complete( |
| 38 | + send, |
| 39 | + common.mustCall((error, data) => { |
| 40 | + assert.strictEqual(error, null); |
| 41 | + assert.strictEqual(data.length, 2); |
| 42 | + assert.strictEqual(typeof data[1], 'string'); |
| 43 | + assert.ok(send.includes(data[1])); |
| 44 | + }) |
| 45 | + ); |
| 46 | + } |
| 47 | +} |
0 commit comments