aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/common.js20
-rw-r--r--test/parallel/test-repl-.save.load.js17
-rw-r--r--test/parallel/test-repl-autolibs.js20
-rw-r--r--test/parallel/test-repl-console.js7
-rw-r--r--test/parallel/test-repl-domain.js17
-rw-r--r--test/parallel/test-repl-end-emits-exit.js7
-rw-r--r--test/parallel/test-repl-options.js7
-rw-r--r--test/parallel/test-repl-reset-event.js7
-rw-r--r--test/parallel/test-repl-syntax-error-stack.js16
-rw-r--r--test/parallel/test-repl-tab-complete-crash.js19
-rw-r--r--test/parallel/test-repl-tab-complete.js17
11 files changed, 40 insertions, 114 deletions
diff --git a/test/common.js b/test/common.js
index 572a1dcf98..470f2f4688 100644
--- a/test/common.js
+++ b/test/common.js
@@ -5,6 +5,8 @@ var fs = require('fs');
var assert = require('assert');
var os = require('os');
var child_process = require('child_process');
+const stream = require('stream');
+const util = require('util');
exports.testDir = path.dirname(__filename);
@@ -449,3 +451,21 @@ exports.fileExists = function(pathname) {
exports.fail = function(msg) {
assert.fail(null, null, msg);
};
+
+
+// A stream to push an array into a REPL
+function ArrayStream() {
+ this.run = function(data) {
+ data.forEach(line => {
+ this.emit('data', line + '\n');
+ });
+ };
+}
+
+util.inherits(ArrayStream, stream.Stream);
+exports.ArrayStream = ArrayStream;
+ArrayStream.prototype.readable = true;
+ArrayStream.prototype.writable = true;
+ArrayStream.prototype.pause = function() {};
+ArrayStream.prototype.resume = function() {};
+ArrayStream.prototype.write = function() {};
diff --git a/test/parallel/test-repl-.save.load.js b/test/parallel/test-repl-.save.load.js
index f63b61bf41..2b9ceed4db 100644
--- a/test/parallel/test-repl-.save.load.js
+++ b/test/parallel/test-repl-.save.load.js
@@ -9,24 +9,9 @@ common.refreshTmpDir();
var repl = require('repl');
-// A stream to push an array into a REPL
-function ArrayStream() {
- this.run = function(data) {
- var self = this;
- data.forEach(function(line) {
- self.emit('data', line + '\n');
- });
- };
-}
-util.inherits(ArrayStream, require('stream').Stream);
-ArrayStream.prototype.readable = true;
-ArrayStream.prototype.writable = true;
-ArrayStream.prototype.resume = function() {};
-ArrayStream.prototype.write = function() {};
-
var works = [['inner.one'], 'inner.o'];
-var putIn = new ArrayStream();
+const putIn = new common.ArrayStream();
var testMe = repl.start('', putIn);
diff --git a/test/parallel/test-repl-autolibs.js b/test/parallel/test-repl-autolibs.js
index e37f2d036e..05cc299f56 100644
--- a/test/parallel/test-repl-autolibs.js
+++ b/test/parallel/test-repl-autolibs.js
@@ -1,25 +1,13 @@
-/* eslint-disable required-modules */
'use strict';
+const common = require('../common');
var assert = require('assert');
var util = require('util');
var repl = require('repl');
-// A stream to push an array into a REPL
-function ArrayStream() {
- this.run = function(data) {
- var self = this;
- data.forEach(function(line) {
- self.emit('data', line + '\n');
- });
- };
-}
-util.inherits(ArrayStream, require('stream').Stream);
-ArrayStream.prototype.readable = true;
-ArrayStream.prototype.writable = true;
-ArrayStream.prototype.resume = function() {};
-ArrayStream.prototype.write = function() {};
+// This test adds global variables
+common.globalCheck = false;
-var putIn = new ArrayStream();
+const putIn = new common.ArrayStream();
var testMe = repl.start('', putIn, null, true);
test1();
diff --git a/test/parallel/test-repl-console.js b/test/parallel/test-repl-console.js
index e66fcb1621..fe737d841e 100644
--- a/test/parallel/test-repl-console.js
+++ b/test/parallel/test-repl-console.js
@@ -1,13 +1,10 @@
'use strict';
var common = require('../common'),
assert = require('assert'),
- Stream = require('stream'),
repl = require('repl');
-// create a dummy stream that does nothing
-var stream = new Stream();
-stream.write = stream.pause = stream.resume = function() {};
-stream.readable = stream.writable = true;
+// Create a dummy stream that does nothing
+const stream = new common.ArrayStream();
var r = repl.start({
input: stream,
diff --git a/test/parallel/test-repl-domain.js b/test/parallel/test-repl-domain.js
index 7528f50287..baf0485b3b 100644
--- a/test/parallel/test-repl-domain.js
+++ b/test/parallel/test-repl-domain.js
@@ -5,22 +5,7 @@ var common = require('../common');
var util = require('util');
var repl = require('repl');
-// A stream to push an array into a REPL
-function ArrayStream() {
- this.run = function(data) {
- var self = this;
- data.forEach(function(line) {
- self.emit('data', line + '\n');
- });
- };
-}
-util.inherits(ArrayStream, require('stream').Stream);
-ArrayStream.prototype.readable = true;
-ArrayStream.prototype.writable = true;
-ArrayStream.prototype.resume = function() {};
-ArrayStream.prototype.write = function() {};
-
-var putIn = new ArrayStream();
+const putIn = new common.ArrayStream();
var testMe = repl.start('', putIn);
putIn.write = function(data) {
diff --git a/test/parallel/test-repl-end-emits-exit.js b/test/parallel/test-repl-end-emits-exit.js
index e4bc4da78c..2c18b413d6 100644
--- a/test/parallel/test-repl-end-emits-exit.js
+++ b/test/parallel/test-repl-end-emits-exit.js
@@ -1,15 +1,12 @@
'use strict';
var common = require('../common'),
assert = require('assert'),
- Stream = require('stream'),
repl = require('repl'),
terminalExit = 0,
regularExit = 0;
-// create a dummy stream that does nothing
-var stream = new Stream();
-stream.write = stream.pause = stream.resume = function() {};
-stream.readable = stream.writable = true;
+// Create a dummy stream that does nothing
+const stream = new common.ArrayStream();
function testTerminalMode() {
var r1 = repl.start({
diff --git a/test/parallel/test-repl-options.js b/test/parallel/test-repl-options.js
index 5bc37d2d71..ec3b144ec0 100644
--- a/test/parallel/test-repl-options.js
+++ b/test/parallel/test-repl-options.js
@@ -1,15 +1,12 @@
'use strict';
var common = require('../common'),
assert = require('assert'),
- Stream = require('stream'),
repl = require('repl');
common.globalCheck = false;
-// create a dummy stream that does nothing
-var stream = new Stream();
-stream.write = stream.pause = stream.resume = function() {};
-stream.readable = stream.writable = true;
+// Create a dummy stream that does nothing
+const stream = new common.ArrayStream();
// 1, mostly defaults
var r1 = repl.start({
diff --git a/test/parallel/test-repl-reset-event.js b/test/parallel/test-repl-reset-event.js
index e6d4eed138..0bd43dcd6c 100644
--- a/test/parallel/test-repl-reset-event.js
+++ b/test/parallel/test-repl-reset-event.js
@@ -4,12 +4,9 @@ common.globalCheck = false;
var assert = require('assert');
var repl = require('repl');
-var Stream = require('stream');
-// create a dummy stream that does nothing
-var dummy = new Stream();
-dummy.write = dummy.pause = dummy.resume = function() {};
-dummy.readable = dummy.writable = true;
+// Create a dummy stream that does nothing
+const dummy = new common.ArrayStream();
function testReset(cb) {
var r = repl.start({
diff --git a/test/parallel/test-repl-syntax-error-stack.js b/test/parallel/test-repl-syntax-error-stack.js
index 573059e8d9..647d3e3569 100644
--- a/test/parallel/test-repl-syntax-error-stack.js
+++ b/test/parallel/test-repl-syntax-error-stack.js
@@ -11,24 +11,12 @@ process.on('exit', () => {
assert.strictEqual(found, true);
});
-// A stream to push an array into a REPL
-function ArrayStream() {
- this.run = function(data) {
- data.forEach(line => {
- this.emit('data', line + '\n');
- });
- };
-}
-util.inherits(ArrayStream, require('stream').Stream);
-ArrayStream.prototype.readable = true;
-ArrayStream.prototype.writable = true;
-ArrayStream.prototype.resume = function() {};
-ArrayStream.prototype.write = function(output) {
+common.ArrayStream.prototype.write = function(output) {
if (/var foo bar;/.test(output))
found = true;
};
-const putIn = new ArrayStream();
+const putIn = new common.ArrayStream();
const testMe = repl.start('', putIn);
let file = path.resolve(__dirname, '../fixtures/syntax/bad_syntax');
diff --git a/test/parallel/test-repl-tab-complete-crash.js b/test/parallel/test-repl-tab-complete-crash.js
index 85ab0577eb..484580f1e7 100644
--- a/test/parallel/test-repl-tab-complete-crash.js
+++ b/test/parallel/test-repl-tab-complete-crash.js
@@ -1,32 +1,19 @@
'use strict';
-require('../common');
+const common = require('../common');
const assert = require('assert');
const util = require('util');
const repl = require('repl');
var referenceErrorCount = 0;
-// A stream to push an array into a REPL
-function ArrayStream() {
- this.run = function(data) {
- const self = this;
- data.forEach(function(line) {
- self.emit('data', line + '\n');
- });
- };
-}
-util.inherits(ArrayStream, require('stream').Stream);
-ArrayStream.prototype.readable = true;
-ArrayStream.prototype.writable = true;
-ArrayStream.prototype.resume = function() {};
-ArrayStream.prototype.write = function(msg) {
+common.ArrayStream.prototype.write = function(msg) {
if (msg.startsWith('ReferenceError: ')) {
referenceErrorCount++;
}
};
-const putIn = new ArrayStream();
+const putIn = new common.ArrayStream();
const testMe = repl.start('', putIn);
// https://github.com/nodejs/node/issues/3346
diff --git a/test/parallel/test-repl-tab-complete.js b/test/parallel/test-repl-tab-complete.js
index 1cb6e7791d..6bf7d5059d 100644
--- a/test/parallel/test-repl-tab-complete.js
+++ b/test/parallel/test-repl-tab-complete.js
@@ -20,23 +20,8 @@ process.on('exit', function() {
assert.strictEqual(referenceErrors, expectedReferenceErrors);
});
-// A stream to push an array into a REPL
-function ArrayStream() {
- this.run = function(data) {
- var self = this;
- data.forEach(function(line) {
- self.emit('data', line + '\n');
- });
- };
-}
-util.inherits(ArrayStream, require('stream').Stream);
-ArrayStream.prototype.readable = true;
-ArrayStream.prototype.writable = true;
-ArrayStream.prototype.resume = function() {};
-ArrayStream.prototype.write = function() {};
-
var works = [['inner.one'], 'inner.o'];
-var putIn = new ArrayStream();
+const putIn = new common.ArrayStream();
var testMe = repl.start('', putIn);
// Some errors are passed to the domain, but do not callback