2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2015-11-25 16:38:01 -05:00
|
|
|
const common = require('../common');
|
2016-12-30 18:38:06 -05:00
|
|
|
const assert = require('assert');
|
|
|
|
const util = require('util');
|
|
|
|
const repl = require('repl');
|
2011-12-24 23:39:57 -05:00
|
|
|
|
2015-11-25 16:38:01 -05:00
|
|
|
// This test adds global variables
|
|
|
|
common.globalCheck = false;
|
2011-12-24 23:39:57 -05:00
|
|
|
|
2015-11-25 16:38:01 -05:00
|
|
|
const putIn = new common.ArrayStream();
|
2016-01-01 17:37:10 -08:00
|
|
|
repl.start('', putIn, null, true);
|
2011-12-24 23:39:57 -05:00
|
|
|
|
|
|
|
test1();
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
function test1() {
|
2017-01-08 13:19:00 +00:00
|
|
|
let gotWrite = false;
|
2015-05-19 13:00:06 +02:00
|
|
|
putIn.write = function(data) {
|
2012-04-06 13:49:27 -07:00
|
|
|
gotWrite = true;
|
2011-12-24 23:39:57 -05:00
|
|
|
if (data.length) {
|
2012-10-02 16:54:49 -07:00
|
|
|
|
2011-12-24 23:39:57 -05:00
|
|
|
// inspect output matches repl output
|
2016-08-17 09:47:13 -05:00
|
|
|
assert.equal(data, util.inspect(require('fs'), null, 2, false) + '\n');
|
2011-12-24 23:39:57 -05:00
|
|
|
// globally added lib matches required lib
|
|
|
|
assert.equal(global.fs, require('fs'));
|
|
|
|
test2();
|
|
|
|
}
|
|
|
|
};
|
2012-04-06 13:49:27 -07:00
|
|
|
assert(!gotWrite);
|
2011-12-24 23:39:57 -05:00
|
|
|
putIn.run(['fs']);
|
2012-04-06 13:49:27 -07:00
|
|
|
assert(gotWrite);
|
2011-12-24 23:39:57 -05:00
|
|
|
}
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
function test2() {
|
2017-01-08 13:19:00 +00:00
|
|
|
let gotWrite = false;
|
2011-12-24 23:39:57 -05:00
|
|
|
putIn.write = function(data) {
|
2012-04-06 13:49:27 -07:00
|
|
|
gotWrite = true;
|
2011-12-24 23:39:57 -05:00
|
|
|
if (data.length) {
|
|
|
|
// repl response error message
|
2016-08-17 09:47:13 -05:00
|
|
|
assert.equal(data, '{}\n');
|
2011-12-24 23:39:57 -05:00
|
|
|
// original value wasn't overwritten
|
|
|
|
assert.equal(val, global.url);
|
|
|
|
}
|
|
|
|
};
|
2017-01-08 13:19:00 +00:00
|
|
|
const val = {};
|
2011-12-24 23:39:57 -05:00
|
|
|
global.url = val;
|
2012-04-06 13:49:27 -07:00
|
|
|
assert(!gotWrite);
|
2011-12-24 23:39:57 -05:00
|
|
|
putIn.run(['url']);
|
2012-04-06 13:49:27 -07:00
|
|
|
assert(gotWrite);
|
2011-12-24 23:39:57 -05:00
|
|
|
}
|