Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 69c95bb

Browse filesBrowse files
cjihrigrvagg
authored andcommitted
test: move ArrayStream to common
A number of REPL tests define the same ArrayStream object. This commit moves the repeated code into common.js. PR-URL: #4027 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent d94a70e commit 69c95bb
Copy full SHA for 69c95bb
Expand file treeCollapse file tree

11 files changed

+40
-114
lines changed
Open diff view settings
Collapse file

‎test/common.js‎

Copy file name to clipboardExpand all lines: test/common.js
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ var fs = require('fs');
55
var assert = require('assert');
66
var os = require('os');
77
var child_process = require('child_process');
8+
const stream = require('stream');
9+
const util = require('util');
810

911

1012
exports.testDir = path.dirname(__filename);
@@ -449,3 +451,21 @@ exports.fileExists = function(pathname) {
449451
exports.fail = function(msg) {
450452
assert.fail(null, null, msg);
451453
};
454+
455+
456+
// A stream to push an array into a REPL
457+
function ArrayStream() {
458+
this.run = function(data) {
459+
data.forEach(line => {
460+
this.emit('data', line + '\n');
461+
});
462+
};
463+
}
464+
465+
util.inherits(ArrayStream, stream.Stream);
466+
exports.ArrayStream = ArrayStream;
467+
ArrayStream.prototype.readable = true;
468+
ArrayStream.prototype.writable = true;
469+
ArrayStream.prototype.pause = function() {};
470+
ArrayStream.prototype.resume = function() {};
471+
ArrayStream.prototype.write = function() {};
Collapse file

‎test/parallel/test-repl-.save.load.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-.save.load.js
+1-16Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,9 @@ common.refreshTmpDir();
99

1010
var repl = require('repl');
1111

12-
// A stream to push an array into a REPL
13-
function ArrayStream() {
14-
this.run = function(data) {
15-
var self = this;
16-
data.forEach(function(line) {
17-
self.emit('data', line + '\n');
18-
});
19-
};
20-
}
21-
util.inherits(ArrayStream, require('stream').Stream);
22-
ArrayStream.prototype.readable = true;
23-
ArrayStream.prototype.writable = true;
24-
ArrayStream.prototype.resume = function() {};
25-
ArrayStream.prototype.write = function() {};
26-
2712
var works = [['inner.one'], 'inner.o'];
2813

29-
var putIn = new ArrayStream();
14+
const putIn = new common.ArrayStream();
3015
var testMe = repl.start('', putIn);
3116

3217

Collapse file

‎test/parallel/test-repl-autolibs.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-autolibs.js
+4-16Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
1-
/* eslint-disable required-modules */
21
'use strict';
2+
const common = require('../common');
33
var assert = require('assert');
44
var util = require('util');
55
var repl = require('repl');
66

7-
// A stream to push an array into a REPL
8-
function ArrayStream() {
9-
this.run = function(data) {
10-
var self = this;
11-
data.forEach(function(line) {
12-
self.emit('data', line + '\n');
13-
});
14-
};
15-
}
16-
util.inherits(ArrayStream, require('stream').Stream);
17-
ArrayStream.prototype.readable = true;
18-
ArrayStream.prototype.writable = true;
19-
ArrayStream.prototype.resume = function() {};
20-
ArrayStream.prototype.write = function() {};
7+
// This test adds global variables
8+
common.globalCheck = false;
219

22-
var putIn = new ArrayStream();
10+
const putIn = new common.ArrayStream();
2311
var testMe = repl.start('', putIn, null, true);
2412

2513
test1();
Collapse file

‎test/parallel/test-repl-console.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-console.js
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
'use strict';
22
var common = require('../common'),
33
assert = require('assert'),
4-
Stream = require('stream'),
54
repl = require('repl');
65

7-
// create a dummy stream that does nothing
8-
var stream = new Stream();
9-
stream.write = stream.pause = stream.resume = function() {};
10-
stream.readable = stream.writable = true;
6+
// Create a dummy stream that does nothing
7+
const stream = new common.ArrayStream();
118

129
var r = repl.start({
1310
input: stream,
Collapse file

‎test/parallel/test-repl-domain.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-domain.js
+1-16Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,7 @@ var common = require('../common');
55
var util = require('util');
66
var repl = require('repl');
77

8-
// A stream to push an array into a REPL
9-
function ArrayStream() {
10-
this.run = function(data) {
11-
var self = this;
12-
data.forEach(function(line) {
13-
self.emit('data', line + '\n');
14-
});
15-
};
16-
}
17-
util.inherits(ArrayStream, require('stream').Stream);
18-
ArrayStream.prototype.readable = true;
19-
ArrayStream.prototype.writable = true;
20-
ArrayStream.prototype.resume = function() {};
21-
ArrayStream.prototype.write = function() {};
22-
23-
var putIn = new ArrayStream();
8+
const putIn = new common.ArrayStream();
249
var testMe = repl.start('', putIn);
2510

2611
putIn.write = function(data) {
Collapse file

‎test/parallel/test-repl-end-emits-exit.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-end-emits-exit.js
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
'use strict';
22
var common = require('../common'),
33
assert = require('assert'),
4-
Stream = require('stream'),
54
repl = require('repl'),
65
terminalExit = 0,
76
regularExit = 0;
87

9-
// create a dummy stream that does nothing
10-
var stream = new Stream();
11-
stream.write = stream.pause = stream.resume = function() {};
12-
stream.readable = stream.writable = true;
8+
// Create a dummy stream that does nothing
9+
const stream = new common.ArrayStream();
1310

1411
function testTerminalMode() {
1512
var r1 = repl.start({
Collapse file

‎test/parallel/test-repl-options.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-options.js
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
'use strict';
22
var common = require('../common'),
33
assert = require('assert'),
4-
Stream = require('stream'),
54
repl = require('repl');
65

76
common.globalCheck = false;
87

9-
// create a dummy stream that does nothing
10-
var stream = new Stream();
11-
stream.write = stream.pause = stream.resume = function() {};
12-
stream.readable = stream.writable = true;
8+
// Create a dummy stream that does nothing
9+
const stream = new common.ArrayStream();
1310

1411
// 1, mostly defaults
1512
var r1 = repl.start({
Collapse file

‎test/parallel/test-repl-reset-event.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-reset-event.js
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ common.globalCheck = false;
44

55
var assert = require('assert');
66
var repl = require('repl');
7-
var Stream = require('stream');
87

9-
// create a dummy stream that does nothing
10-
var dummy = new Stream();
11-
dummy.write = dummy.pause = dummy.resume = function() {};
12-
dummy.readable = dummy.writable = true;
8+
// Create a dummy stream that does nothing
9+
const dummy = new common.ArrayStream();
1310

1411
function testReset(cb) {
1512
var r = repl.start({
Collapse file

‎test/parallel/test-repl-syntax-error-stack.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-syntax-error-stack.js
+2-14Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,12 @@ process.on('exit', () => {
1111
assert.strictEqual(found, true);
1212
});
1313

14-
// A stream to push an array into a REPL
15-
function ArrayStream() {
16-
this.run = function(data) {
17-
data.forEach(line => {
18-
this.emit('data', line + '\n');
19-
});
20-
};
21-
}
22-
util.inherits(ArrayStream, require('stream').Stream);
23-
ArrayStream.prototype.readable = true;
24-
ArrayStream.prototype.writable = true;
25-
ArrayStream.prototype.resume = function() {};
26-
ArrayStream.prototype.write = function(output) {
14+
common.ArrayStream.prototype.write = function(output) {
2715
if (/var foo bar;/.test(output))
2816
found = true;
2917
};
3018

31-
const putIn = new ArrayStream();
19+
const putIn = new common.ArrayStream();
3220
const testMe = repl.start('', putIn);
3321
let file = path.resolve(__dirname, '../fixtures/syntax/bad_syntax');
3422

Collapse file

‎test/parallel/test-repl-tab-complete-crash.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-tab-complete-crash.js
+3-16Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,19 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
44
const assert = require('assert');
55
const util = require('util');
66
const repl = require('repl');
77

88
var referenceErrorCount = 0;
99

10-
// A stream to push an array into a REPL
11-
function ArrayStream() {
12-
this.run = function(data) {
13-
const self = this;
14-
data.forEach(function(line) {
15-
self.emit('data', line + '\n');
16-
});
17-
};
18-
}
19-
util.inherits(ArrayStream, require('stream').Stream);
20-
ArrayStream.prototype.readable = true;
21-
ArrayStream.prototype.writable = true;
22-
ArrayStream.prototype.resume = function() {};
23-
ArrayStream.prototype.write = function(msg) {
10+
common.ArrayStream.prototype.write = function(msg) {
2411
if (msg.startsWith('ReferenceError: ')) {
2512
referenceErrorCount++;
2613
}
2714
};
2815

29-
const putIn = new ArrayStream();
16+
const putIn = new common.ArrayStream();
3017
const testMe = repl.start('', putIn);
3118

3219
// https://github.com/nodejs/node/issues/3346

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.