0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-stream-transform-split-objectmode.js
Rich Trott 082cc8d6d8 test: remove unnecessary assignments
common.js needs to be loaded in all tests so that there is checking
for variable leaks and possibly other things. However, it does not
need to be assigned to a variable if nothing in common.js is referred
to elsewhere in the test.

PR-URL: https://github.com/nodejs/node/pull/4408
Reviewed-By: James M Snell <jasnell@gmail.com>
2015-12-26 18:00:02 -08:00

53 lines
1.2 KiB
JavaScript

'use strict';
require('../common');
var assert = require('assert');
var Transform = require('stream').Transform;
var parser = new Transform({ readableObjectMode : true });
assert(parser._readableState.objectMode);
assert(!parser._writableState.objectMode);
assert(parser._readableState.highWaterMark === 16);
assert(parser._writableState.highWaterMark === (16 * 1024));
parser._transform = function(chunk, enc, callback) {
callback(null, { val : chunk[0] });
};
var parsed;
parser.on('data', function(obj) {
parsed = obj;
});
parser.end(new Buffer([42]));
process.on('exit', function() {
assert(parsed.val === 42);
});
var serializer = new Transform({ writableObjectMode : true });
assert(!serializer._readableState.objectMode);
assert(serializer._writableState.objectMode);
assert(serializer._readableState.highWaterMark === (16 * 1024));
assert(serializer._writableState.highWaterMark === 16);
serializer._transform = function(obj, _, callback) {
callback(null, new Buffer([obj.val]));
};
var serialized;
serializer.on('data', function(chunk) {
serialized = chunk;
});
serializer.write({ val : 42 });
process.on('exit', function() {
assert(serialized[0] === 42);
});