Skip to content

Commit f43ea2a

Browse files
committed
test: refactor test-stream-transform-object
* use common.mustCall() as appropriate * eliminate exit handler * var -> const/let * provide duration for setInterval() PR-URL: #10588 Reviewed-By: Italo A. Casas <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent 132e44b commit f43ea2a

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44

55
const stream = require('stream');
6-
var PassThrough = stream.PassThrough;
6+
const PassThrough = stream.PassThrough;
77

8-
var src = new PassThrough({ objectMode: true });
9-
var tx = new PassThrough({ objectMode: true });
10-
var dest = new PassThrough({ objectMode: true });
8+
const src = new PassThrough({ objectMode: true });
9+
const tx = new PassThrough({ objectMode: true });
10+
const dest = new PassThrough({ objectMode: true });
1111

12-
var expect = [ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
13-
var results = [];
14-
process.on('exit', function() {
15-
assert.deepStrictEqual(results, expect);
16-
console.log('ok');
17-
});
12+
const expect = [ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
13+
const results = [];
1814

19-
dest.on('data', function(x) {
15+
dest.on('data', common.mustCall(function(x) {
2016
results.push(x);
21-
});
17+
}, expect.length));
2218

2319
src.pipe(tx).pipe(dest);
2420

25-
var i = -1;
26-
var int = setInterval(function() {
27-
if (i > 10) {
21+
let i = -1;
22+
const int = setInterval(common.mustCall(function() {
23+
if (results.length === expect.length) {
2824
src.end();
2925
clearInterval(int);
26+
assert.deepStrictEqual(results, expect);
3027
} else {
3128
src.write(i++);
3229
}
33-
});
30+
}, expect.length + 1), 1);

0 commit comments

Comments
 (0)