From f43ea2a6aebee751076f37323f096359320af5fe Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 2 Jan 2017 22:27:40 -0800 Subject: [PATCH] test: refactor test-stream-transform-object * use common.mustCall() as appropriate * eliminate exit handler * var -> const/let * provide duration for setInterval() PR-URL: https://github.com/nodejs/node/pull/10588 Reviewed-By: Italo A. Casas Reviewed-By: Gibson Fahnestock Reviewed-By: James M Snell Reviewed-By: Sakthipriyan Vairamani --- ...tream-transform-objectmode-falsey-value.js | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/test/parallel/test-stream-transform-objectmode-falsey-value.js b/test/parallel/test-stream-transform-objectmode-falsey-value.js index c2c3886506..9a05034b20 100644 --- a/test/parallel/test-stream-transform-objectmode-falsey-value.js +++ b/test/parallel/test-stream-transform-objectmode-falsey-value.js @@ -1,33 +1,30 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const stream = require('stream'); -var PassThrough = stream.PassThrough; +const PassThrough = stream.PassThrough; -var src = new PassThrough({ objectMode: true }); -var tx = new PassThrough({ objectMode: true }); -var dest = new PassThrough({ objectMode: true }); +const src = new PassThrough({ objectMode: true }); +const tx = new PassThrough({ objectMode: true }); +const dest = new PassThrough({ objectMode: true }); -var expect = [ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; -var results = []; -process.on('exit', function() { - assert.deepStrictEqual(results, expect); - console.log('ok'); -}); +const expect = [ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; +const results = []; -dest.on('data', function(x) { +dest.on('data', common.mustCall(function(x) { results.push(x); -}); +}, expect.length)); src.pipe(tx).pipe(dest); -var i = -1; -var int = setInterval(function() { - if (i > 10) { +let i = -1; +const int = setInterval(common.mustCall(function() { + if (results.length === expect.length) { src.end(); clearInterval(int); + assert.deepStrictEqual(results, expect); } else { src.write(i++); } -}); +}, expect.length + 1), 1);