| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e684382 commit 98af170
24 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,9 +38,6 @@ tasks. | |||
| 38 | 38 | ||
| 39 | 39 | Takes `whitelist` and concats that with predefined `knownGlobals`. | |
| 40 | 40 | ||
| 41 | - ### arrayStream | ||
| 42 | - A stream to push an array into a REPL | ||
| 43 | - | ||
| 44 | 41 | ### busyLoop(time) | |
| 45 | 42 | * `time` [<number>] | |
| 46 | 43 | ||
@@ -413,6 +410,20 @@ Platform normalizes the `pwd` command. | |||
| 413 | 410 | ||
| 414 | 411 | Synchronous version of `spawnPwd`. | |
| 415 | 412 | ||
| 413 | + ## ArrayStream Module | ||
| 414 | + | ||
| 415 | + The `ArrayStream` module provides a simple `Stream` that pushes elements from | ||
| 416 | + a given array. | ||
| 417 | + | ||
| 418 | + <!-- eslint-disable no-undef, node-core/required-modules --> | ||
| 419 | + ```js | ||
| 420 | + const ArrayStream = require('../common/arraystream'); | ||
| 421 | + const stream = new ArrayStream(); | ||
| 422 | + stream.run(['a', 'b', 'c']); | ||
| 423 | + ``` | ||
| 424 | + | ||
| 425 | + It can be used within tests as a simple mock stream. | ||
| 426 | + | ||
| 416 | 427 | ## Countdown Module | |
| 417 | 428 | ||
| 418 | 429 | The `Countdown` module provides a simple countdown mechanism for tests that | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,24 @@ | |||
| 1 | + /* eslint-disable node-core/required-modules */ | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + const { Stream } = require('stream'); | ||
| 5 | + const { inherits } = require('util'); | ||
| 6 | + function noop() {} | ||
| 7 | + | ||
| 8 | + // A stream to push an array into a REPL | ||
| 9 | + function ArrayStream() { | ||
| 10 | + this.run = function(data) { | ||
| 11 | + data.forEach((line) => { | ||
| 12 | + this.emit('data', `${line}\n`); | ||
| 13 | + }); | ||
| 14 | + }; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + inherits(ArrayStream, Stream); | ||
| 18 | + ArrayStream.prototype.readable = true; | ||
| 19 | + ArrayStream.prototype.writable = true; | ||
| 20 | + ArrayStream.prototype.pause = noop; | ||
| 21 | + ArrayStream.prototype.resume = noop; | ||
| 22 | + ArrayStream.prototype.write = noop; | ||
| 23 | + | ||
| 24 | + module.exports = ArrayStream; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,7 +27,6 @@ const fs = require('fs'); | |||
| 27 | 27 | const assert = require('assert'); | |
| 28 | 28 | const os = require('os'); | |
| 29 | 29 | const { exec, execSync, spawn, spawnSync } = require('child_process'); | |
| 30 | - const stream = require('stream'); | ||
| 31 | 30 | const util = require('util'); | |
| 32 | 31 | const Timer = process.binding('timer_wrap').Timer; | |
| 33 | 32 | const { fixturesDir } = require('./fixtures'); | |
@@ -512,23 +511,6 @@ exports.skip = function(msg) { | |||
| 512 | 511 | process.exit(0); | |
| 513 | 512 | }; | |
| 514 | 513 | ||
| 515 | - // A stream to push an array into a REPL | ||
| 516 | - function ArrayStream() { | ||
| 517 | - this.run = function(data) { | ||
| 518 | - data.forEach((line) => { | ||
| 519 | - this.emit('data', `${line}\n`); | ||
| 520 | - }); | ||
| 521 | - }; | ||
| 522 | - } | ||
| 523 | - | ||
| 524 | - util.inherits(ArrayStream, stream.Stream); | ||
| 525 | - exports.ArrayStream = ArrayStream; | ||
| 526 | - ArrayStream.prototype.readable = true; | ||
| 527 | - ArrayStream.prototype.writable = true; | ||
| 528 | - ArrayStream.prototype.pause = noop; | ||
| 529 | - ArrayStream.prototype.resume = noop; | ||
| 530 | - ArrayStream.prototype.write = noop; | ||
| 531 | - | ||
| 532 | 514 | // Returns true if the exit code "exitCode" and/or signal name "signal" | |
| 533 | 515 | // represent the exit code and/or signal name of a node process that aborted, | |
| 534 | 516 | // false otherwise. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,11 +21,12 @@ | |||
| 21 | 21 | ||
| 22 | 22 | 'use strict'; | |
| 23 | 23 | const common = require('../common'); | |
| 24 | + const ArrayStream = require('../common/arraystream'); | ||
| 24 | 25 | const assert = require('assert'); | |
| 25 | 26 | const util = require('util'); | |
| 26 | 27 | const repl = require('repl'); | |
| 27 | 28 | ||
| 28 | - const putIn = new common.ArrayStream(); | ||
| 29 | + const putIn = new ArrayStream(); | ||
| 29 | 30 | repl.start('', putIn, null, true); | |
| 30 | 31 | ||
| 31 | 32 | test1(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,12 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - const common = require('../common'); | ||
| 2 | + require('../common'); | ||
| 3 | + const ArrayStream = require('../common/arraystream'); | ||
| 3 | 4 | const assert = require('assert'); | |
| 4 | 5 | const repl = require('repl'); | |
| 5 | 6 | const vm = require('vm'); | |
| 6 | 7 | ||
| 7 | 8 | // Create a dummy stream that does nothing. | |
| 8 | - const stream = new common.ArrayStream(); | ||
| 9 | + const stream = new ArrayStream(); | ||
| 9 | 10 | ||
| 10 | 11 | // Test context when useGlobal is false. | |
| 11 | 12 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,11 +20,12 @@ | |||
| 20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 21 | 21 | ||
| 22 | 22 | 'use strict'; | |
| 23 | - const common = require('../common'); | ||
| 23 | + require('../common'); | ||
| 24 | + const ArrayStream = require('../common/arraystream'); | ||
| 24 | 25 | ||
| 25 | 26 | const repl = require('repl'); | |
| 26 | 27 | ||
| 27 | - const putIn = new common.ArrayStream(); | ||
| 28 | + const putIn = new ArrayStream(); | ||
| 28 | 29 | repl.start('', putIn); | |
| 29 | 30 | ||
| 30 | 31 | putIn.write = function(data) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,9 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | - const common = require('../common'); | ||
| 3 | + require('../common'); | ||
| 4 | 4 | const assert = require('assert'); | |
| 5 | 5 | const repl = require('repl'); | |
| 6 | + const ArrayStream = require('../common/arraystream'); | ||
| 6 | 7 | ||
| 7 | 8 | // \u001b[1G - Moves the cursor to 1st column | |
| 8 | 9 | // \u001b[0J - Clear screen | |
@@ -11,7 +12,7 @@ const terminalCode = '\u001b[1G\u001b[0J> \u001b[3G'; | |||
| 11 | 12 | const terminalCodeRegex = new RegExp(terminalCode.replace(/\[/g, '\\['), 'g'); | |
| 12 | 13 | ||
| 13 | 14 | function run({ input, output, event, checkTerminalCodes = true }) { | |
| 14 | - const stream = new common.ArrayStream(); | ||
| 15 | + const stream = new ArrayStream(); | ||
| 15 | 16 | let found = ''; | |
| 16 | 17 | ||
| 17 | 18 | stream.write = (msg) => found += msg.replace('\r', ''); | |
@@ -74,8 +75,8 @@ tests.forEach(run); | |||
| 74 | 75 | ||
| 75 | 76 | // Auto code alignment for .editor mode | |
| 76 | 77 | function testCodeAligment({ input, cursor = 0, line = '' }) { | |
| 77 | - const stream = new common.ArrayStream(); | ||
| 78 | - const outputStream = new common.ArrayStream(); | ||
| 78 | + const stream = new ArrayStream(); | ||
| 79 | + const outputStream = new ArrayStream(); | ||
| 79 | 80 | ||
| 80 | 81 | stream.write = () => { throw new Error('Writing not allowed!'); }; | |
| 81 | 82 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,14 +20,15 @@ | |||
| 20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 21 | 21 | ||
| 22 | 22 | 'use strict'; | |
| 23 | - const common = require('../common'); | ||
| 23 | + require('../common'); | ||
| 24 | + const ArrayStream = require('../common/arraystream'); | ||
| 24 | 25 | const assert = require('assert'); | |
| 25 | 26 | const repl = require('repl'); | |
| 26 | 27 | let terminalExit = 0; | |
| 27 | 28 | let regularExit = 0; | |
| 28 | 29 | ||
| 29 | 30 | // Create a dummy stream that does nothing | |
| 30 | - const stream = new common.ArrayStream(); | ||
| 31 | + const stream = new ArrayStream(); | ||
| 31 | 32 | ||
| 32 | 33 | function testTerminalMode() { | |
| 33 | 34 | const r1 = repl.start({ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,10 +1,11 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | const common = require('../common'); | |
| 3 | + const ArrayStream = require('../common/arraystream'); | ||
| 3 | 4 | const assert = require('assert'); | |
| 4 | 5 | const repl = require('repl'); | |
| 5 | 6 | ||
| 6 | 7 | { | |
| 7 | - const stream = new common.ArrayStream(); | ||
| 8 | + const stream = new ArrayStream(); | ||
| 8 | 9 | const options = { | |
| 9 | 10 | eval: common.mustCall((cmd, context) => { | |
| 10 | 11 | assert.strictEqual(cmd, '.scope\n'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,14 +1,15 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const common = require('../common'); | |
| 4 | + const ArrayStream = require('../common/arraystream'); | ||
| 4 | 5 | const assert = require('assert'); | |
| 5 | 6 | const repl = require('repl'); | |
| 6 | 7 | ||
| 7 | 8 | common.skipIfInspectorDisabled(); | |
| 8 | 9 | ||
| 9 | 10 | // This test verifies that the V8 inspector API is usable in the REPL. | |
| 10 | 11 | ||
| 11 | - const putIn = new common.ArrayStream(); | ||
| 12 | + const putIn = new ArrayStream(); | ||
| 12 | 13 | let output = ''; | |
| 13 | 14 | putIn.write = function(data) { | |
| 14 | 15 | output += data; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments