diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-02-11 19:17:03 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-02-12 15:42:06 +0100 |
commit | 1fc373bdf6758dcf045db21e4a075e4099ca7c19 (patch) | |
tree | 6845172f59c4bdf9be6d37efadc502e867adb248 /test/parallel/test-repl-function-definition-edge-case.js | |
parent | 60c9ad797994e544af21ce991dce2c3360ae1801 (diff) | |
download | android-node-v8-1fc373bdf6758dcf045db21e4a075e4099ca7c19.tar.gz android-node-v8-1fc373bdf6758dcf045db21e4a075e4099ca7c19.tar.bz2 android-node-v8-1fc373bdf6758dcf045db21e4a075e4099ca7c19.zip |
Revert "repl: refactor tests to not rely on timing"
This reverts commit de848ac1e0483327a2ce8716c3f8567eaeacb660.
The commit broke multiline repl.
PR-URL: https://github.com/nodejs/node/pull/18715
Refs: https://github.com/nodejs/node/pull/17828
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/parallel/test-repl-function-definition-edge-case.js')
-rw-r--r-- | test/parallel/test-repl-function-definition-edge-case.js | 71 |
1 files changed, 28 insertions, 43 deletions
diff --git a/test/parallel/test-repl-function-definition-edge-case.js b/test/parallel/test-repl-function-definition-edge-case.js index bda40594a8..1e3063e3db 100644 --- a/test/parallel/test-repl-function-definition-edge-case.js +++ b/test/parallel/test-repl-function-definition-edge-case.js @@ -7,47 +7,32 @@ const stream = require('stream'); common.globalCheck = false; -const input = new stream(); -input.write = input.pause = input.resume = () => {}; -input.readable = true; - -const output = new stream(); -output.writable = true; -output.accumulator = []; - -output.write = (data) => output.accumulator.push(data); - -const replserver = repl.start({ - input, - output, - useColors: false, - terminal: false, - prompt: '' -}); -const callbacks = []; -const $eval = replserver.eval; -replserver.eval = function(code, context, file, cb) { - const expected = callbacks.shift(); - return $eval.call(this, code, context, file, (...args) => { - try { - expected(...args); - } catch (e) { - console.error(e); - process.exit(1); - } - cb(...args); +const r = initRepl(); + +r.input.emit('data', 'function a() { return 42; } (1)\n'); +r.input.emit('data', 'a\n'); +r.input.emit('data', '.exit'); + +const expected = '1\n[Function: a]\n'; +const got = r.output.accumulator.join(''); +assert.strictEqual(got, expected); + +function initRepl() { + const input = new stream(); + input.write = input.pause = input.resume = () => {}; + input.readable = true; + + const output = new stream(); + output.writable = true; + output.accumulator = []; + + output.write = (data) => output.accumulator.push(data); + + return repl.start({ + input, + output, + useColors: false, + terminal: false, + prompt: '' }); -}; - -callbacks.push(common.mustCall((err, result) => { - assert.ifError(err); - assert.strictEqual(result, 1); -})); -replserver.input.emit('data', 'function a() { return 42; } (1)\n'); -callbacks.push(common.mustCall((err, result) => { - assert.ifError(err); - assert.strictEqual(typeof result, 'function'); - assert.strictEqual(result.toString(), 'function a() { return 42; }'); -})); -replserver.input.emit('data', 'a\n'); -replserver.input.emit('data', '.exit'); +} |