Browse Source

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: https://github.com/nodejs/node/pull/4027
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
process-exit-stdio-flushing
cjihrig 9 years ago
parent
commit
f2e319b757
  1. 20
      test/common.js
  2. 17
      test/parallel/test-repl-.save.load.js
  3. 20
      test/parallel/test-repl-autolibs.js
  4. 7
      test/parallel/test-repl-console.js
  5. 17
      test/parallel/test-repl-domain.js
  6. 7
      test/parallel/test-repl-end-emits-exit.js
  7. 7
      test/parallel/test-repl-options.js
  8. 7
      test/parallel/test-repl-reset-event.js
  9. 16
      test/parallel/test-repl-syntax-error-stack.js
  10. 19
      test/parallel/test-repl-tab-complete-crash.js
  11. 17
      test/parallel/test-repl-tab-complete.js

20
test/common.js

@ -5,6 +5,8 @@ var fs = require('fs');
var assert = require('assert'); var assert = require('assert');
var os = require('os'); var os = require('os');
var child_process = require('child_process'); var child_process = require('child_process');
const stream = require('stream');
const util = require('util');
exports.testDir = path.dirname(__filename); exports.testDir = path.dirname(__filename);
@ -449,3 +451,21 @@ exports.fileExists = function(pathname) {
exports.fail = function(msg) { exports.fail = function(msg) {
assert.fail(null, null, 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() {};

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

@ -9,24 +9,9 @@ common.refreshTmpDir();
var repl = require('repl'); 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 works = [['inner.one'], 'inner.o'];
var putIn = new ArrayStream(); const putIn = new common.ArrayStream();
var testMe = repl.start('', putIn); var testMe = repl.start('', putIn);

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

@ -1,25 +1,13 @@
/* eslint-disable required-modules */
'use strict'; 'use strict';
const common = require('../common');
var assert = require('assert'); var assert = require('assert');
var util = require('util'); var util = require('util');
var repl = require('repl'); var repl = require('repl');
// A stream to push an array into a REPL // This test adds global variables
function ArrayStream() { common.globalCheck = false;
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, null, true); var testMe = repl.start('', putIn, null, true);
test1(); test1();

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

@ -1,13 +1,10 @@
'use strict'; 'use strict';
var common = require('../common'), var common = require('../common'),
assert = require('assert'), assert = require('assert'),
Stream = require('stream'),
repl = require('repl'); repl = require('repl');
// create a dummy stream that does nothing // Create a dummy stream that does nothing
var stream = new Stream(); const stream = new common.ArrayStream();
stream.write = stream.pause = stream.resume = function() {};
stream.readable = stream.writable = true;
var r = repl.start({ var r = repl.start({
input: stream, input: stream,

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

@ -5,22 +5,7 @@ var common = require('../common');
var util = require('util'); var util = require('util');
var repl = require('repl'); var repl = require('repl');
// A stream to push an array into a REPL const putIn = new common.ArrayStream();
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();
var testMe = repl.start('', putIn); var testMe = repl.start('', putIn);
putIn.write = function(data) { putIn.write = function(data) {

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

@ -1,15 +1,12 @@
'use strict'; 'use strict';
var common = require('../common'), var common = require('../common'),
assert = require('assert'), assert = require('assert'),
Stream = require('stream'),
repl = require('repl'), repl = require('repl'),
terminalExit = 0, terminalExit = 0,
regularExit = 0; regularExit = 0;
// create a dummy stream that does nothing // Create a dummy stream that does nothing
var stream = new Stream(); const stream = new common.ArrayStream();
stream.write = stream.pause = stream.resume = function() {};
stream.readable = stream.writable = true;
function testTerminalMode() { function testTerminalMode() {
var r1 = repl.start({ var r1 = repl.start({

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

@ -1,15 +1,12 @@
'use strict'; 'use strict';
var common = require('../common'), var common = require('../common'),
assert = require('assert'), assert = require('assert'),
Stream = require('stream'),
repl = require('repl'); repl = require('repl');
common.globalCheck = false; common.globalCheck = false;
// create a dummy stream that does nothing // Create a dummy stream that does nothing
var stream = new Stream(); const stream = new common.ArrayStream();
stream.write = stream.pause = stream.resume = function() {};
stream.readable = stream.writable = true;
// 1, mostly defaults // 1, mostly defaults
var r1 = repl.start({ var r1 = repl.start({

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

@ -4,12 +4,9 @@ common.globalCheck = false;
var assert = require('assert'); var assert = require('assert');
var repl = require('repl'); var repl = require('repl');
var Stream = require('stream');
// create a dummy stream that does nothing // Create a dummy stream that does nothing
var dummy = new Stream(); const dummy = new common.ArrayStream();
dummy.write = dummy.pause = dummy.resume = function() {};
dummy.readable = dummy.writable = true;
function testReset(cb) { function testReset(cb) {
var r = repl.start({ var r = repl.start({

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

@ -11,24 +11,12 @@ process.on('exit', () => {
assert.strictEqual(found, true); assert.strictEqual(found, true);
}); });
// A stream to push an array into a REPL common.ArrayStream.prototype.write = function(output) {
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) {
if (/var foo bar;/.test(output)) if (/var foo bar;/.test(output))
found = true; found = true;
}; };
const putIn = new ArrayStream(); const putIn = new common.ArrayStream();
const testMe = repl.start('', putIn); const testMe = repl.start('', putIn);
let file = path.resolve(__dirname, '../fixtures/syntax/bad_syntax'); let file = path.resolve(__dirname, '../fixtures/syntax/bad_syntax');

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

@ -1,32 +1,19 @@
'use strict'; 'use strict';
require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const util = require('util'); const util = require('util');
const repl = require('repl'); const repl = require('repl');
var referenceErrorCount = 0; var referenceErrorCount = 0;
// A stream to push an array into a REPL common.ArrayStream.prototype.write = function(msg) {
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) {
if (msg.startsWith('ReferenceError: ')) { if (msg.startsWith('ReferenceError: ')) {
referenceErrorCount++; referenceErrorCount++;
} }
}; };
const putIn = new ArrayStream(); const putIn = new common.ArrayStream();
const testMe = repl.start('', putIn); const testMe = repl.start('', putIn);
// https://github.com/nodejs/node/issues/3346 // https://github.com/nodejs/node/issues/3346

17
test/parallel/test-repl-tab-complete.js

@ -20,23 +20,8 @@ process.on('exit', function() {
assert.strictEqual(referenceErrors, expectedReferenceErrors); 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 works = [['inner.one'], 'inner.o'];
var putIn = new ArrayStream(); const putIn = new common.ArrayStream();
var testMe = repl.start('', putIn); var testMe = repl.start('', putIn);
// Some errors are passed to the domain, but do not callback // Some errors are passed to the domain, but do not callback

Loading…
Cancel
Save