diff options
author | Bradley Farias <bradley.meck@gmail.com> | 2017-12-22 11:19:50 -0600 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-02-10 14:19:54 +0100 |
commit | de848ac1e0483327a2ce8716c3f8567eaeacb660 (patch) | |
tree | 5395e33d22cd318f618b24752e178f68f40e851f /test/parallel/test-repl-eval.js | |
parent | 6007a9cc0e361d428123e4c0f74024c6cd7815f4 (diff) | |
download | node-new-de848ac1e0483327a2ce8716c3f8567eaeacb660.tar.gz |
repl: refactor tests to not rely on timing
Tests relying on synchronous timing have been migrated to use events.
PR-URL: https://github.com/nodejs/node/pull/17828
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'test/parallel/test-repl-eval.js')
-rw-r--r-- | test/parallel/test-repl-eval.js | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/test/parallel/test-repl-eval.js b/test/parallel/test-repl-eval.js index d775423fb7..d7290a1583 100644 --- a/test/parallel/test-repl-eval.js +++ b/test/parallel/test-repl-eval.js @@ -3,31 +3,31 @@ const common = require('../common'); const assert = require('assert'); const repl = require('repl'); -{ - let evalCalledWithExpectedArgs = false; +const exitTests = []; +process.on('exit', () => { + for (const test of exitTests) test(); +}); +const options = { + eval: common.mustCall((cmd, context) => { + // Assertions here will not cause the test to exit with an error code + // so set a boolean that is checked later instead. + exitTests.push(common.mustCall(() => { + assert.strictEqual(cmd, 'function f() {}\n'); + assert.strictEqual(context.foo, 'bar'); + })); + }) +}; - const options = { - eval: common.mustCall((cmd, context) => { - // Assertions here will not cause the test to exit with an error code - // so set a boolean that is checked later instead. - evalCalledWithExpectedArgs = (cmd === 'function f() {}\n' && - context.foo === 'bar'); - }) - }; +const r = repl.start(options); +r.context = { foo: 'bar' }; - const r = repl.start(options); - r.context = { foo: 'bar' }; - - try { - // Default preprocessor transforms - // function f() {} to - // var f = function f() {} - // Test to ensure that original input is preserved. - // Reference: https://github.com/nodejs/node/issues/9743 - r.write('function f() {}\n'); - } finally { - r.write('.exit\n'); - } - - assert(evalCalledWithExpectedArgs); +try { + // Default preprocessor transforms + // function f() {} to + // var f = function f() {} + // Test to ensure that original input is preserved. + // Reference: https://github.com/nodejs/node/issues/9743 + r.write('function f() {}\n'); +} finally { + r.write('.exit\n'); } |