|
1 | 1 | 'use strict'; |
2 | | -require('../common'); |
| 2 | +const common = require('../common'); |
3 | 3 | const assert = require('assert'); |
4 | | - |
5 | 4 | const Readable = require('_stream_readable'); |
6 | 5 | const Writable = require('_stream_writable'); |
7 | 6 | const EE = require('events').EventEmitter; |
8 | 7 |
|
9 | | -let testRuns = 0, completedRuns = 0; |
10 | 8 | function runTest(highWaterMark, objectMode, produce) { |
11 | | - testRuns++; |
12 | 9 |
|
13 | 10 | const old = new EE(); |
14 | 11 | const r = new Readable({ highWaterMark: highWaterMark, |
15 | 12 | objectMode: objectMode }); |
16 | 13 | assert.strictEqual(r, r.wrap(old)); |
17 | 14 |
|
18 | | - let 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 | }; |
@@ -41,13 +33,10 @@ function runTest(highWaterMark, objectMode, produce) { |
41 | 33 | while (flowing && chunks-- > 0) { |
42 | 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 | } |
@@ -56,22 +45,19 @@ function runTest(highWaterMark, objectMode, produce) { |
56 | 45 | objectMode: objectMode }); |
57 | 46 | const written = []; |
58 | 47 | w._write = function(chunk, encoding, cb) { |
59 | | - console.log('_write', chunk); |
60 | 48 | written.push(chunk); |
61 | 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 | } |
@@ -83,8 +69,3 @@ runTest(1, true, function() { return { foo: 'bar' }; }); |
83 | 69 |
|
84 | 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.strictEqual(testRuns, completedRuns); |
89 | | - console.log('ok'); |
90 | | -}); |