node/test/parallel/test-repl-eval-scope.js
Bradley Farias de848ac1e0
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>
2018-02-10 14:19:54 +01:00

30 lines
683 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const repl = require('repl');
const exitTests = [];
process.on('exit', () => {
for (const test of exitTests) test();
});
const CONTEXT = { animal: 'Sterrance' };
const stream = new common.ArrayStream();
const options = {
eval: common.mustCall((cmd, context) => {
// need to escape the domain
exitTests.push(common.mustCall(() => {
assert.strictEqual(cmd, '.scope');
assert.ok(context === CONTEXT);
}));
}),
input: stream,
output: stream,
terminal: true
};
const r = repl.start(options);
r.context = CONTEXT;
stream.emit('data', '\t');
stream.emit('.exit\n');