node/test/parallel/test-stream2-base64-single-char-read-end.js
cjihrig 6510eb5ddc test: s/assert.fail/common.fail as appropriate
Many tests use assert.fail(null, null, msg) where it would be
simpler to use common.fail(msg). This is largely because
common.fail() is fairly new. This commit makes the replacement
when applicable.

PR-URL: https://github.com/nodejs/node/pull/7735
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2016-07-15 15:50:01 -04:00

38 lines
724 B
JavaScript

'use strict';
const common = require('../common');
var R = require('_stream_readable');
var W = require('_stream_writable');
var assert = require('assert');
var src = new R({encoding: 'base64'});
var dst = new W();
var hasRead = false;
var accum = [];
var timeout;
src._read = function(n) {
if (!hasRead) {
hasRead = true;
process.nextTick(function() {
src.push(Buffer.from('1'));
src.push(null);
});
}
};
dst._write = function(chunk, enc, cb) {
accum.push(chunk);
cb();
};
src.on('end', function() {
assert.equal(Buffer.concat(accum) + '', 'MQ==');
clearTimeout(timeout);
});
src.pipe(dst);
timeout = setTimeout(function() {
common.fail('timed out waiting for _write');
}, 100);