Skip to content

Commit 78e8aa8

Browse files
Trottevanlucas
authored andcommitted
test: refactor test-stream-pipe-after-end
* replace `process.on('exit', ...)` checks with `common.mustCall()` * assert.equal() -> assert.strictEqual() * provide duration of 1ms to timer without a duration * remove unused function argument PR-URL: #10483 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Italo A. Casas <[email protected]>
1 parent 7fbd12f commit 78e8aa8

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed
+7-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44
const Readable = require('_stream_readable');
55
const Writable = require('_stream_writable');
@@ -13,7 +13,7 @@ function TestReadable(opt) {
1313
this._ended = false;
1414
}
1515

16-
TestReadable.prototype._read = function(n) {
16+
TestReadable.prototype._read = function() {
1717
if (this._ended)
1818
this.emit('error', new Error('_read called twice'));
1919
this._ended = true;
@@ -35,31 +35,18 @@ TestWritable.prototype._write = function(chunk, encoding, cb) {
3535

3636
// this one should not emit 'end' until we read() from it later.
3737
const ender = new TestReadable();
38-
let enderEnded = false;
3938

4039
// what happens when you pipe() a Readable that's already ended?
4140
const piper = new TestReadable();
4241
// pushes EOF null, and length=0, so this will trigger 'end'
4342
piper.read();
4443

45-
setTimeout(function() {
46-
ender.on('end', function() {
47-
enderEnded = true;
48-
});
49-
assert(!enderEnded);
44+
setTimeout(common.mustCall(function() {
45+
ender.on('end', common.mustCall(function() {}));
5046
const c = ender.read();
51-
assert.equal(c, null);
47+
assert.strictEqual(c, null);
5248

5349
const w = new TestWritable();
54-
let writableFinished = false;
55-
w.on('finish', function() {
56-
writableFinished = true;
57-
});
50+
w.on('finish', common.mustCall(function() {}));
5851
piper.pipe(w);
59-
60-
process.on('exit', function() {
61-
assert(enderEnded);
62-
assert(writableFinished);
63-
console.log('ok');
64-
});
65-
});
52+
}), 1);

0 commit comments

Comments
 (0)