Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor stream-*-constructor-set-methods #18817

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions test/parallel/test-stream-transform-constructor-set-methods.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
'use strict';
const common = require('../common');
const assert = require('assert');

const Transform = require('stream').Transform;
const { strictEqual } = require('assert');
const { Transform } = require('stream');

const _transform = common.mustCall(function _transform(d, e, n) {
n();
const _transform = common.mustCall((chunk, _, next) => {
next();
});

const _final = common.mustCall(function _final(n) {
n();
const _final = common.mustCall((next) => {
next();
});

const _flush = common.mustCall(function _flush(n) {
n();
const _flush = common.mustCall((next) => {
next();
});

const t = new Transform({
Expand All @@ -22,21 +22,19 @@ const t = new Transform({
final: _final
});

const t2 = new Transform({});
strictEqual(t._transform, _transform);
strictEqual(t._flush, _flush);
strictEqual(t._final, _final);

t.end(Buffer.from('blerg'));
t.resume();

const t2 = new Transform({});

common.expectsError(() => {
t2.end(Buffer.from('blerg'));
}, {
type: Error,
code: 'ERR_METHOD_NOT_IMPLEMENTED',
message: 'The _transform method is not implemented'
});

process.on('exit', () => {
assert.strictEqual(t._transform, _transform);
assert.strictEqual(t._flush, _flush);
assert.strictEqual(t._final, _final);
});
52 changes: 22 additions & 30 deletions test/parallel/test-stream-writable-constructor-set-methods.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,37 @@
'use strict';
const common = require('../common');
const assert = require('assert');

const Writable = require('stream').Writable;
const { strictEqual } = require('assert');
const { Writable } = require('stream');

let _writeCalled = false;
function _write(d, e, n) {
_writeCalled = true;
}
const _write = common.mustCall((chunk, _, next) => {
next();
});

const _writev = common.mustCall((chunks, next) => {
strictEqual(chunks.length, 2);
next();
});

const w = new Writable({ write: _write });
w.end(Buffer.from('blerg'));
const w = new Writable({ write: _write, writev: _writev });

let _writevCalled = false;
let dLength = 0;
function _writev(d, n) {
dLength = d.length;
_writevCalled = true;
}
strictEqual(w._write, _write);
strictEqual(w._writev, _writev);

const w2 = new Writable({ writev: _writev });
w2.cork();
w.write(Buffer.from('blerg'));

w2.write(Buffer.from('blerg'));
w2.write(Buffer.from('blerg'));
w2.end();
w.cork();
w.write(Buffer.from('blerg'));
w.write(Buffer.from('blerg'));

const w3 = new Writable();
w.end();

w3.on('error', common.expectsError({
const w2 = new Writable();

w2.on('error', common.expectsError({
type: Error,
code: 'ERR_METHOD_NOT_IMPLEMENTED',
message: 'The _write method is not implemented'
}));

w3.end(Buffer.from('blerg'));

process.on('exit', function() {
assert.strictEqual(w._write, _write);
assert(_writeCalled);
assert.strictEqual(w2._writev, _writev);
assert.strictEqual(dLength, 2);
assert(_writevCalled);
});
w2.end(Buffer.from('blerg'));