2017-01-03 13:16:48 -08:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2015-11-25 16:38:01 -05:00
|
|
|
const common = require('../common');
|
2018-08-21 14:47:47 -07:00
|
|
|
const ArrayStream = require('../common/arraystream');
|
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
|
|
|
|
2018-08-21 14:47:47 -07:00
|
|
|
const putIn = new ArrayStream();
|
2018-02-11 19:17:03 +01: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
|
|
|
|
2019-03-07 01:03:53 +01:00
|
|
|
// Inspect output matches repl output
|
2017-04-28 04:06:42 +03:00
|
|
|
assert.strictEqual(data,
|
|
|
|
`${util.inspect(require('fs'), null, 2, false)}\n`);
|
2019-03-07 01:03:53 +01:00
|
|
|
// Globally added lib matches required lib
|
2025-01-22 15:30:30 -08:00
|
|
|
assert.strictEqual(globalThis.fs, require('fs'));
|
2011-12-24 23:39:57 -05:00
|
|
|
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) {
|
2019-03-22 03:44:26 +01:00
|
|
|
// REPL response error message
|
2017-01-08 15:36:25 +00:00
|
|
|
assert.strictEqual(data, '{}\n');
|
2019-03-07 01:03:53 +01:00
|
|
|
// Original value wasn't overwritten
|
2025-01-22 15:30:30 -08:00
|
|
|
assert.strictEqual(val, globalThis.url);
|
2011-12-24 23:39:57 -05:00
|
|
|
}
|
|
|
|
};
|
2017-01-08 13:19:00 +00:00
|
|
|
const val = {};
|
2025-01-22 15:30:30 -08:00
|
|
|
globalThis.url = val;
|
2018-05-14 16:16:33 +02:00
|
|
|
common.allowGlobals(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
|
|
|
}
|