aboutsummaryrefslogtreecommitdiff
path: root/test/parallel/test-repl-use-global.js
diff options
context:
space:
mode:
authorBradley Farias <bradley.meck@gmail.com>2017-12-22 11:19:50 -0600
committerRuben Bridgewater <ruben@bridgewater.de>2018-02-10 14:19:54 +0100
commitde848ac1e0483327a2ce8716c3f8567eaeacb660 (patch)
tree5395e33d22cd318f618b24752e178f68f40e851f /test/parallel/test-repl-use-global.js
parent6007a9cc0e361d428123e4c0f74024c6cd7815f4 (diff)
downloadandroid-node-v8-de848ac1e0483327a2ce8716c3f8567eaeacb660.tar.gz
android-node-v8-de848ac1e0483327a2ce8716c3f8567eaeacb660.tar.bz2
android-node-v8-de848ac1e0483327a2ce8716c3f8567eaeacb660.zip
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-use-global.js')
-rw-r--r--test/parallel/test-repl-use-global.js65
1 files changed, 33 insertions, 32 deletions
diff --git a/test/parallel/test-repl-use-global.js b/test/parallel/test-repl-use-global.js
index c76505272b..75646a9c00 100644
--- a/test/parallel/test-repl-use-global.js
+++ b/test/parallel/test-repl-use-global.js
@@ -7,13 +7,6 @@ const stream = require('stream');
const repl = require('internal/repl');
const assert = require('assert');
-// Array of [useGlobal, expectedResult] pairs
-const globalTestCases = [
- [false, 'undefined'],
- [true, '\'tacos\''],
- [undefined, 'undefined']
-];
-
const globalTest = (useGlobal, cb, output) => (err, repl) => {
if (err)
return cb(err);
@@ -26,26 +19,12 @@ const globalTest = (useGlobal, cb, output) => (err, repl) => {
global.lunch = 'tacos';
repl.write('global.lunch;\n');
repl.close();
- delete global.lunch;
- cb(null, str.trim());
-};
-
-// Test how the global object behaves in each state for useGlobal
-for (const [option, expected] of globalTestCases) {
- runRepl(option, globalTest, common.mustCall((err, output) => {
- assert.ifError(err);
- assert.strictEqual(output, expected);
+ repl.on('exit', common.mustCall(() => {
+ delete global.lunch;
+ cb(null, str.trim());
}));
-}
+};
-// Test how shadowing the process object via `let`
-// behaves in each useGlobal state. Note: we can't
-// actually test the state when useGlobal is true,
-// because the exception that's generated is caught
-// (see below), but errors are printed, and the test
-// suite is aware of it, causing a failure to be flagged.
-//
-const processTestCases = [false, undefined];
const processTest = (useGlobal, cb, output) => (err, repl) => {
if (err)
return cb(err);
@@ -57,15 +36,37 @@ const processTest = (useGlobal, cb, output) => (err, repl) => {
repl.write('let process;\n');
repl.write('21 * 2;\n');
repl.close();
- cb(null, str.trim());
-};
-
-for (const option of processTestCases) {
- runRepl(option, processTest, common.mustCall((err, output) => {
+ repl.on('exit', common.mustCall((err) => {
assert.ifError(err);
- assert.strictEqual(output, 'undefined\n42');
+ cb(null, str.trim());
}));
-}
+};
+
+// Array of [useGlobal, expectedResult, fn] pairs
+const testCases = [
+ // Test how the global object behaves in each state for useGlobal
+ [false, 'undefined', globalTest],
+ [true, '\'tacos\'', globalTest],
+ [undefined, 'undefined', globalTest],
+ // Test how shadowing the process object via `let`
+ // behaves in each useGlobal state. Note: we can't
+ // actually test the state when useGlobal is true,
+ // because the exception that's generated is caught
+ // (see below), but errors are printed, and the test
+ // suite is aware of it, causing a failure to be flagged.
+ [false, 'undefined\n42', processTest]
+];
+
+const next = common.mustCall(() => {
+ if (testCases.length) {
+ const [option, expected, runner] = testCases.shift();
+ runRepl(option, runner, common.mustCall((err, output) => {
+ assert.strictEqual(output, expected);
+ next();
+ }));
+ }
+}, testCases.length + 1);
+next();
function runRepl(useGlobal, testFunc, cb) {
const inputStream = new stream.PassThrough();