diff options
author | James M Snell <jasnell@gmail.com> | 2018-08-21 14:47:47 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2018-08-23 16:51:56 -0700 |
commit | fa543c00cdaca6a6c68d1df4c68c061e2b82ca21 (patch) | |
tree | 5fec72f5c739129a75ec1588fa1e0face32a5cf6 /test/common | |
parent | 2d64a51270f20e47de663fd45326a93dda1694e4 (diff) | |
download | android-node-v8-fa543c00cdaca6a6c68d1df4c68c061e2b82ca21.tar.gz android-node-v8-fa543c00cdaca6a6c68d1df4c68c061e2b82ca21.tar.bz2 android-node-v8-fa543c00cdaca6a6c68d1df4c68c061e2b82ca21.zip |
test: move common.ArrayStream to separate module
In a continuing effort to de-monolithize `require('../common')`,
move `common.ArrayStream` out to a separate module that is
imported only when it is needed.
PR-URL: https://github.com/nodejs/node/pull/22447
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'test/common')
-rw-r--r-- | test/common/README.md | 17 | ||||
-rw-r--r-- | test/common/arraystream.js | 24 | ||||
-rw-r--r-- | test/common/index.js | 18 |
3 files changed, 38 insertions, 21 deletions
diff --git a/test/common/README.md b/test/common/README.md index 27634c97e1..e44dcd299c 100644 --- a/test/common/README.md +++ b/test/common/README.md @@ -38,9 +38,6 @@ tasks. Takes `whitelist` and concats that with predefined `knownGlobals`. -### arrayStream -A stream to push an array into a REPL - ### busyLoop(time) * `time` [<number>] @@ -413,6 +410,20 @@ Platform normalizes the `pwd` command. Synchronous version of `spawnPwd`. +## ArrayStream Module + +The `ArrayStream` module provides a simple `Stream` that pushes elements from +a given array. + +<!-- eslint-disable no-undef, node-core/required-modules --> +```js +const ArrayStream = require('../common/arraystream'); +const stream = new ArrayStream(); +stream.run(['a', 'b', 'c']); +``` + +It can be used within tests as a simple mock stream. + ## Countdown Module The `Countdown` module provides a simple countdown mechanism for tests that diff --git a/test/common/arraystream.js b/test/common/arraystream.js new file mode 100644 index 0000000000..dadd6ff048 --- /dev/null +++ b/test/common/arraystream.js @@ -0,0 +1,24 @@ +/* eslint-disable node-core/required-modules */ +'use strict'; + +const { Stream } = require('stream'); +const { inherits } = require('util'); +function noop() {} + +// A stream to push an array into a REPL +function ArrayStream() { + this.run = function(data) { + data.forEach((line) => { + this.emit('data', `${line}\n`); + }); + }; +} + +inherits(ArrayStream, Stream); +ArrayStream.prototype.readable = true; +ArrayStream.prototype.writable = true; +ArrayStream.prototype.pause = noop; +ArrayStream.prototype.resume = noop; +ArrayStream.prototype.write = noop; + +module.exports = ArrayStream; diff --git a/test/common/index.js b/test/common/index.js index 8254f54101..369f23f790 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -27,7 +27,6 @@ const fs = require('fs'); const assert = require('assert'); const os = require('os'); const { exec, execSync, spawn, spawnSync } = require('child_process'); -const stream = require('stream'); const util = require('util'); const { fixturesDir } = require('./fixtures'); const tmpdir = require('./tmpdir'); @@ -511,23 +510,6 @@ exports.skip = function(msg) { process.exit(0); }; -// 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 = noop; -ArrayStream.prototype.resume = noop; -ArrayStream.prototype.write = noop; - // Returns true if the exit code "exitCode" and/or signal name "signal" // represent the exit code and/or signal name of a node process that aborted, // false otherwise. |