| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 55377db commit a06419b
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,77 +1,63 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 3 | - var assert = require('assert'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const Readable = require('_stream_readable'); | ||
| 5 | + const Writable = require('_stream_writable'); | ||
| 6 | + const EE = require('events').EventEmitter; | ||
| 4 | 7 | ||
| 5 | - var Readable = require('_stream_readable'); | ||
| 6 | - var Writable = require('_stream_writable'); | ||
| 7 | - var EE = require('events').EventEmitter; | ||
| 8 | - | ||
| 9 | - var testRuns = 0, completedRuns = 0; | ||
| 10 | 8 | function runTest(highWaterMark, objectMode, produce) { | |
| 11 | - testRuns++; | ||
| 12 | 9 | ||
| 13 | - var old = new EE(); | ||
| 14 | - var r = new Readable({ highWaterMark: highWaterMark, | ||
| 15 | - objectMode: objectMode }); | ||
| 16 | - assert.equal(r, r.wrap(old)); | ||
| 10 | + const old = new EE(); | ||
| 11 | + const r = new Readable({ highWaterMark: highWaterMark, | ||
| 12 | + objectMode: objectMode }); | ||
| 13 | + assert.strictEqual(r, r.wrap(old)); | ||
| 17 | 14 | ||
| 18 | - var ended = false; | ||
| 19 | - r.on('end', function() { | ||
| 20 | - ended = true; | ||
| 21 | - }); | ||
| 15 | + r.on('end', common.mustCall(function() {})); | ||
| 22 | 16 | ||
| 23 | 17 | old.pause = function() { | |
| 24 | - console.error('old.pause()'); | ||
| 25 | 18 | old.emit('pause'); | |
| 26 | 19 | flowing = false; | |
| 27 | 20 | }; | |
| 28 | 21 | ||
| 29 | 22 | old.resume = function() { | |
| 30 | - console.error('old.resume()'); | ||
| 31 | 23 | old.emit('resume'); | |
| 32 | 24 | flow(); | |
| 33 | 25 | }; | |
| 34 | 26 | ||
| 35 | - var flowing; | ||
| 36 | - var chunks = 10; | ||
| 37 | - var oldEnded = false; | ||
| 38 | - var expected = []; | ||
| 27 | + let flowing; | ||
| 28 | + let chunks = 10; | ||
| 29 | + let oldEnded = false; | ||
| 30 | + const expected = []; | ||
| 39 | 31 | function flow() { | |
| 40 | 32 | flowing = true; | |
| 41 | 33 | while (flowing && chunks-- > 0) { | |
| 42 | - var item = produce(); | ||
| 34 | + const item = produce(); | ||
| 43 | 35 | expected.push(item); | |
| 44 | - console.log('old.emit', chunks, flowing); | ||
| 45 | 36 | old.emit('data', item); | |
| 46 | - console.log('after emit', chunks, flowing); | ||
| 47 | 37 | } | |
| 48 | 38 | if (chunks <= 0) { | |
| 49 | 39 | oldEnded = true; | |
| 50 | - console.log('old end', chunks, flowing); | ||
| 51 | 40 | old.emit('end'); | |
| 52 | 41 | } | |
| 53 | 42 | } | |
| 54 | 43 | ||
| 55 | - var w = new Writable({ highWaterMark: highWaterMark * 2, | ||
| 56 | - objectMode: objectMode }); | ||
| 57 | - var written = []; | ||
| 44 | + const w = new Writable({ highWaterMark: highWaterMark * 2, | ||
| 45 | + objectMode: objectMode }); | ||
| 46 | + const written = []; | ||
| 58 | 47 | w._write = function(chunk, encoding, cb) { | |
| 59 | - console.log('_write', chunk); | ||
| 60 | 48 | written.push(chunk); | |
| 61 | - setTimeout(cb); | ||
| 49 | + setTimeout(cb, 1); | ||
| 62 | 50 | }; | |
| 63 | 51 | ||
| 64 | - w.on('finish', function() { | ||
| 65 | - completedRuns++; | ||
| 52 | + w.on('finish', common.mustCall(function() { | ||
| 66 | 53 | performAsserts(); | |
| 67 | - }); | ||
| 54 | + })); | ||
| 68 | 55 | ||
| 69 | 56 | r.pipe(w); | |
| 70 | 57 | ||
| 71 | 58 | flow(); | |
| 72 | 59 | ||
| 73 | 60 | function performAsserts() { | |
| 74 | - assert(ended); | ||
| 75 | 61 | assert(oldEnded); | |
| 76 | 62 | assert.deepStrictEqual(written, expected); | |
| 77 | 63 | } | |
@@ -81,10 +67,5 @@ runTest(100, false, function() { return Buffer.allocUnsafe(100); }); | |||
| 81 | 67 | runTest(10, false, function() { return Buffer.from('xxxxxxxxxx'); }); | |
| 82 | 68 | runTest(1, true, function() { return { foo: 'bar' }; }); | |
| 83 | 69 | ||
| 84 | - var objectChunks = [ 5, 'a', false, 0, '', 'xyz', { x: 4 }, 7, [], 555 ]; | ||
| 70 | + const objectChunks = [ 5, 'a', false, 0, '', 'xyz', { x: 4 }, 7, [], 555 ]; | ||
| 85 | 71 | runTest(1, true, function() { return objectChunks.shift(); }); | |
| 86 | - | ||
| 87 | - process.on('exit', function() { | ||
| 88 | - assert.equal(testRuns, completedRuns); | ||
| 89 | - console.log('ok'); | ||
| 90 | - }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments