0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
nodejs/test/parallel/test-repl-reset-event.js
cjihrig 6510eb5ddc test: s/assert.fail/common.fail as appropriate
Many tests use assert.fail(null, null, msg) where it would be
simpler to use common.fail(msg). This is largely because
common.fail() is fairly new. This commit makes the replacement
when applicable.

PR-URL: https://github.com/nodejs/node/pull/7735
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2016-07-15 15:50:01 -04:00

53 lines
1.2 KiB
JavaScript

'use strict';
var common = require('../common');
common.globalCheck = false;
var assert = require('assert');
var repl = require('repl');
// Create a dummy stream that does nothing
const dummy = new common.ArrayStream();
function testReset(cb) {
var r = repl.start({
input: dummy,
output: dummy,
useGlobal: false
});
r.context.foo = 42;
r.on('reset', function(context) {
assert(!!context, 'REPL did not emit a context with reset event');
assert.equal(context, r.context, 'REPL emitted incorrect context');
assert.equal(context.foo, undefined, 'REPL emitted the previous context' +
', and is not using global as context');
context.foo = 42;
cb();
});
r.resetContext();
}
function testResetGlobal(cb) {
var r = repl.start({
input: dummy,
output: dummy,
useGlobal: true
});
r.context.foo = 42;
r.on('reset', function(context) {
assert.equal(context.foo, 42,
'"foo" property is missing from REPL using global as context');
cb();
});
r.resetContext();
}
var timeout = setTimeout(function() {
common.fail('Timeout, REPL did not emit reset events');
}, 5000);
testReset(function() {
testResetGlobal(function() {
clearTimeout(timeout);
});
});