diff options
author | cjihrig <cjihrig@gmail.com> | 2017-06-15 18:03:37 -0400 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2017-06-19 16:04:00 -0400 |
commit | d3c668cead3d5baff03d795755e2ae1906408580 (patch) | |
tree | 84c2c3d160046f2e9bda9628f42825260cdd665f /test/parallel/test-stream2-transform.js | |
parent | 471e88feb47e8a711e395cf6167d723adf3d1b7a (diff) | |
download | node-new-d3c668cead3d5baff03d795755e2ae1906408580.tar.gz |
test: remove node-tap lookalike
This commit removes the small node-tap lookalike from several
of the streams2 tests. It's only used by six tests, and is
inconsistent with all other tests.
PR-URL: https://github.com/nodejs/node/pull/13707
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-stream2-transform.js')
-rw-r--r-- | test/parallel/test-stream2-transform.js | 338 |
1 files changed, 138 insertions, 200 deletions
diff --git a/test/parallel/test-stream2-transform.js b/test/parallel/test-stream2-transform.js index f9cbfa8d26..6b5593d93b 100644 --- a/test/parallel/test-stream2-transform.js +++ b/test/parallel/test-stream2-transform.js @@ -20,49 +20,13 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const PassThrough = require('_stream_passthrough'); const Transform = require('_stream_transform'); -// tiny node-tap lookalike. -const tests = []; -let count = 0; - -function test(name, fn) { - count++; - tests.push([name, fn]); -} - -function run() { - const next = tests.shift(); - if (!next) - return console.error('ok'); - - const name = next[0]; - const fn = next[1]; - console.log('# %s', name); - fn({ - same: assert.deepStrictEqual, - equal: assert.strictEqual, - ok: assert, - end: function() { - count--; - run(); - } - }); -} - -// ensure all tests have run -process.on('exit', function() { - assert.strictEqual(count, 0); -}); - -process.nextTick(run); - -///// - -test('writable side consumption', function(t) { +{ + // Verify writable side consumption const tx = new Transform({ highWaterMark: 10 }); @@ -79,17 +43,16 @@ test('writable side consumption', function(t) { } tx.end(); - t.equal(tx._readableState.length, 10); - t.equal(transformed, 10); - t.equal(tx._transformState.writechunk.length, 5); - t.same(tx._writableState.getBuffer().map(function(c) { + assert.strictEqual(tx._readableState.length, 10); + assert.strictEqual(transformed, 10); + assert.strictEqual(tx._transformState.writechunk.length, 5); + assert.deepStrictEqual(tx._writableState.getBuffer().map(function(c) { return c.chunk.length; }), [6, 7, 8, 9, 10]); +} - t.end(); -}); - -test('passthrough', function(t) { +{ + // Verify passthrough behavior const pt = new PassThrough(); pt.write(Buffer.from('foog')); @@ -98,14 +61,14 @@ test('passthrough', function(t) { pt.write(Buffer.from('kuel')); pt.end(); - t.equal(pt.read(5).toString(), 'foogb'); - t.equal(pt.read(5).toString(), 'arkba'); - t.equal(pt.read(5).toString(), 'zykue'); - t.equal(pt.read(5).toString(), 'l'); - t.end(); -}); + assert.strictEqual(pt.read(5).toString(), 'foogb'); + assert.strictEqual(pt.read(5).toString(), 'arkba'); + assert.strictEqual(pt.read(5).toString(), 'zykue'); + assert.strictEqual(pt.read(5).toString(), 'l'); +} -test('object passthrough', function(t) { +{ + // Verify object passthrough behavior const pt = new PassThrough({ objectMode: true }); pt.write(1); @@ -117,25 +80,24 @@ test('object passthrough', function(t) { pt.write({ a: 'b'}); pt.end(); - t.equal(pt.read(), 1); - t.equal(pt.read(), true); - t.equal(pt.read(), false); - t.equal(pt.read(), 0); - t.equal(pt.read(), 'foo'); - t.equal(pt.read(), ''); - t.same(pt.read(), { a: 'b'}); - t.end(); -}); - -test('passthrough constructor', function(t) { + assert.strictEqual(pt.read(), 1); + assert.strictEqual(pt.read(), true); + assert.strictEqual(pt.read(), false); + assert.strictEqual(pt.read(), 0); + assert.strictEqual(pt.read(), 'foo'); + assert.strictEqual(pt.read(), ''); + assert.deepStrictEqual(pt.read(), { a: 'b'}); +} + +{ + // Verify passthrough constructor behavior const pt = PassThrough(); assert(pt instanceof PassThrough); +} - t.end(); -}); - -test('simple transform', function(t) { +{ + // Perform a simple transform const pt = new Transform(); pt._transform = function(c, e, cb) { const ret = Buffer.alloc(c.length, 'x'); @@ -149,14 +111,14 @@ test('simple transform', function(t) { pt.write(Buffer.from('kuel')); pt.end(); - t.equal(pt.read(5).toString(), 'xxxxx'); - t.equal(pt.read(5).toString(), 'xxxxx'); - t.equal(pt.read(5).toString(), 'xxxxx'); - t.equal(pt.read(5).toString(), 'x'); - t.end(); -}); + assert.strictEqual(pt.read(5).toString(), 'xxxxx'); + assert.strictEqual(pt.read(5).toString(), 'xxxxx'); + assert.strictEqual(pt.read(5).toString(), 'xxxxx'); + assert.strictEqual(pt.read(5).toString(), 'x'); +} -test('simple object transform', function(t) { +{ + // Verify simple object transform const pt = new Transform({ objectMode: true }); pt._transform = function(c, e, cb) { pt.push(JSON.stringify(c)); @@ -172,17 +134,17 @@ test('simple object transform', function(t) { pt.write({ a: 'b'}); pt.end(); - t.equal(pt.read(), '1'); - t.equal(pt.read(), 'true'); - t.equal(pt.read(), 'false'); - t.equal(pt.read(), '0'); - t.equal(pt.read(), '"foo"'); - t.equal(pt.read(), '""'); - t.equal(pt.read(), '{"a":"b"}'); - t.end(); -}); - -test('async passthrough', function(t) { + assert.strictEqual(pt.read(), '1'); + assert.strictEqual(pt.read(), 'true'); + assert.strictEqual(pt.read(), 'false'); + assert.strictEqual(pt.read(), '0'); + assert.strictEqual(pt.read(), '"foo"'); + assert.strictEqual(pt.read(), '""'); + assert.strictEqual(pt.read(), '{"a":"b"}'); +} + +{ + // Verify async passthrough const pt = new Transform(); pt._transform = function(chunk, encoding, cb) { setTimeout(function() { @@ -197,16 +159,16 @@ test('async passthrough', function(t) { pt.write(Buffer.from('kuel')); pt.end(); - pt.on('finish', function() { - t.equal(pt.read(5).toString(), 'foogb'); - t.equal(pt.read(5).toString(), 'arkba'); - t.equal(pt.read(5).toString(), 'zykue'); - t.equal(pt.read(5).toString(), 'l'); - t.end(); - }); -}); + pt.on('finish', common.mustCall(function() { + assert.strictEqual(pt.read(5).toString(), 'foogb'); + assert.strictEqual(pt.read(5).toString(), 'arkba'); + assert.strictEqual(pt.read(5).toString(), 'zykue'); + assert.strictEqual(pt.read(5).toString(), 'l'); + })); +} -test('assymetric transform (expand)', function(t) { +{ + // Verify assymetric transform (expand) const pt = new Transform(); // emit each chunk 2 times. @@ -226,19 +188,19 @@ test('assymetric transform (expand)', function(t) { pt.write(Buffer.from('kuel')); pt.end(); - pt.on('finish', function() { - t.equal(pt.read(5).toString(), 'foogf'); - t.equal(pt.read(5).toString(), 'oogba'); - t.equal(pt.read(5).toString(), 'rkbar'); - t.equal(pt.read(5).toString(), 'kbazy'); - t.equal(pt.read(5).toString(), 'bazyk'); - t.equal(pt.read(5).toString(), 'uelku'); - t.equal(pt.read(5).toString(), 'el'); - t.end(); - }); -}); + pt.on('finish', common.mustCall(function() { + assert.strictEqual(pt.read(5).toString(), 'foogf'); + assert.strictEqual(pt.read(5).toString(), 'oogba'); + assert.strictEqual(pt.read(5).toString(), 'rkbar'); + assert.strictEqual(pt.read(5).toString(), 'kbazy'); + assert.strictEqual(pt.read(5).toString(), 'bazyk'); + assert.strictEqual(pt.read(5).toString(), 'uelku'); + assert.strictEqual(pt.read(5).toString(), 'el'); + })); +} -test('assymetric transform (compress)', function(t) { +{ + // Verify assymetric trasform (compress) const pt = new Transform(); // each output is the first char of 3 consecutive chunks, @@ -283,17 +245,17 @@ test('assymetric transform (compress)', function(t) { pt.end(); // 'abcdeabcdeabcd' - pt.on('finish', function() { - t.equal(pt.read(5).toString(), 'abcde'); - t.equal(pt.read(5).toString(), 'abcde'); - t.equal(pt.read(5).toString(), 'abcd'); - t.end(); - }); -}); + pt.on('finish', common.mustCall(function() { + assert.strictEqual(pt.read(5).toString(), 'abcde'); + assert.strictEqual(pt.read(5).toString(), 'abcde'); + assert.strictEqual(pt.read(5).toString(), 'abcd'); + })); +} // this tests for a stall when data is written to a full stream // that has empty transforms. -test('complex transform', function(t) { +{ + // Verify compex transform behavior let count = 0; let saved = null; const pt = new Transform({highWaterMark: 3}); @@ -314,118 +276,96 @@ test('complex transform', function(t) { pt.once('readable', function() { process.nextTick(function() { pt.write(Buffer.from('d')); - pt.write(Buffer.from('ef'), function() { + pt.write(Buffer.from('ef'), common.mustCall(function() { pt.end(); - t.end(); - }); - t.equal(pt.read().toString(), 'abcdef'); - t.equal(pt.read(), null); + })); + assert.strictEqual(pt.read().toString(), 'abcdef'); + assert.strictEqual(pt.read(), null); }); }); pt.write(Buffer.from('abc')); -}); +} -test('passthrough event emission', function(t) { +{ + // Verify passthrough event emission const pt = new PassThrough(); let emits = 0; pt.on('readable', function() { - console.error('>>> emit readable %d', emits); emits++; }); pt.write(Buffer.from('foog')); - - console.error('need emit 0'); pt.write(Buffer.from('bark')); - console.error('should have emitted readable now 1 === %d', emits); - t.equal(emits, 1); - - t.equal(pt.read(5).toString(), 'foogb'); - t.equal(String(pt.read(5)), 'null'); - - console.error('need emit 1'); + assert.strictEqual(emits, 1); + assert.strictEqual(pt.read(5).toString(), 'foogb'); + assert.strictEqual(String(pt.read(5)), 'null'); pt.write(Buffer.from('bazy')); - console.error('should have emitted, but not again'); pt.write(Buffer.from('kuel')); - console.error('should have emitted readable now 2 === %d', emits); - t.equal(emits, 2); - - t.equal(pt.read(5).toString(), 'arkba'); - t.equal(pt.read(5).toString(), 'zykue'); - t.equal(pt.read(5), null); - - console.error('need emit 2'); + assert.strictEqual(emits, 2); + assert.strictEqual(pt.read(5).toString(), 'arkba'); + assert.strictEqual(pt.read(5).toString(), 'zykue'); + assert.strictEqual(pt.read(5), null); pt.end(); - t.equal(emits, 3); + assert.strictEqual(emits, 3); + assert.strictEqual(pt.read(5).toString(), 'l'); + assert.strictEqual(pt.read(5), null); - t.equal(pt.read(5).toString(), 'l'); - t.equal(pt.read(5), null); - - console.error('should not have emitted again'); - t.equal(emits, 3); - t.end(); -}); + assert.strictEqual(emits, 3); +} -test('passthrough event emission reordered', function(t) { +{ + // Verify passthrough event emission reordering const pt = new PassThrough(); let emits = 0; pt.on('readable', function() { - console.error('emit readable', emits); emits++; }); pt.write(Buffer.from('foog')); - console.error('need emit 0'); pt.write(Buffer.from('bark')); - console.error('should have emitted readable now 1 === %d', emits); - t.equal(emits, 1); - t.equal(pt.read(5).toString(), 'foogb'); - t.equal(pt.read(5), null); - - console.error('need emit 1'); - pt.once('readable', function() { - t.equal(pt.read(5).toString(), 'arkba'); - - t.equal(pt.read(5), null); - - console.error('need emit 2'); - pt.once('readable', function() { - t.equal(pt.read(5).toString(), 'zykue'); - t.equal(pt.read(5), null); - pt.once('readable', function() { - t.equal(pt.read(5).toString(), 'l'); - t.equal(pt.read(5), null); - t.equal(emits, 4); - t.end(); - }); + assert.strictEqual(emits, 1); + assert.strictEqual(pt.read(5).toString(), 'foogb'); + assert.strictEqual(pt.read(5), null); + + pt.once('readable', common.mustCall(function() { + assert.strictEqual(pt.read(5).toString(), 'arkba'); + assert.strictEqual(pt.read(5), null); + + pt.once('readable', common.mustCall(function() { + assert.strictEqual(pt.read(5).toString(), 'zykue'); + assert.strictEqual(pt.read(5), null); + pt.once('readable', common.mustCall(function() { + assert.strictEqual(pt.read(5).toString(), 'l'); + assert.strictEqual(pt.read(5), null); + assert.strictEqual(emits, 4); + })); pt.end(); - }); + })); pt.write(Buffer.from('kuel')); - }); + })); pt.write(Buffer.from('bazy')); -}); +} -test('passthrough facaded', function(t) { - console.error('passthrough facaded'); +{ + // Verify passthrough facade const pt = new PassThrough(); const datas = []; pt.on('data', function(chunk) { datas.push(chunk.toString()); }); - pt.on('end', function() { - t.same(datas, ['foog', 'bark', 'bazy', 'kuel']); - t.end(); - }); + pt.on('end', common.mustCall(function() { + assert.deepStrictEqual(datas, ['foog', 'bark', 'bazy', 'kuel']); + })); pt.write(Buffer.from('foog')); setTimeout(function() { @@ -440,10 +380,10 @@ test('passthrough facaded', function(t) { }, 10); }, 10); }, 10); -}); +} -test('object transform (json parse)', function(t) { - console.error('json parse stream'); +{ + // Verify object transform (JSON parse) const jp = new Transform({ objectMode: true }); jp._transform = function(data, encoding, cb) { try { @@ -471,21 +411,20 @@ test('object transform (json parse)', function(t) { objects.forEach(function(obj) { jp.write(JSON.stringify(obj)); const res = jp.read(); - t.same(res, obj); + assert.deepStrictEqual(res, obj); }); jp.end(); // read one more time to get the 'end' event jp.read(); - process.nextTick(function() { - t.ok(ended); - t.end(); - }); -}); + process.nextTick(common.mustCall(function() { + assert.strictEqual(ended, true); + })); +} -test('object transform (json stringify)', function(t) { - console.error('json parse stream'); +{ + // Verify object transform (JSON stringify) const js = new Transform({ objectMode: true }); js._transform = function(data, encoding, cb) { try { @@ -513,15 +452,14 @@ test('object transform (json stringify)', function(t) { objects.forEach(function(obj) { js.write(obj); const res = js.read(); - t.equal(res, JSON.stringify(obj)); + assert.strictEqual(res, JSON.stringify(obj)); }); js.end(); // read one more time to get the 'end' event js.read(); - process.nextTick(function() { - t.ok(ended); - t.end(); - }); -}); + process.nextTick(common.mustCall(function() { + assert.strictEqual(ended, true); + })); +} |