test: refactor stream-*-constructor-set-methods
- Use `common.mustCall()` to ensure that callbacks are called. - Remove no longer needed variables. - Remove unnecessary `process.on('exit')` usage. PR-URL: https://github.com/nodejs/node/pull/18817 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
81232320aa
commit
33103e9758
@ -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({
|
||||
@ -22,11 +22,15 @@ 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'));
|
||||
}, {
|
||||
@ -34,9 +38,3 @@ common.expectsError(() => {
|
||||
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);
|
||||
});
|
||||
|
@ -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 w = new Writable({ write: _write });
|
||||
w.end(Buffer.from('blerg'));
|
||||
const _writev = common.mustCall((chunks, next) => {
|
||||
strictEqual(chunks.length, 2);
|
||||
next();
|
||||
});
|
||||
|
||||
let _writevCalled = false;
|
||||
let dLength = 0;
|
||||
function _writev(d, n) {
|
||||
dLength = d.length;
|
||||
_writevCalled = true;
|
||||
}
|
||||
const w = new Writable({ write: _write, writev: _writev });
|
||||
|
||||
const w2 = new Writable({ writev: _writev });
|
||||
w2.cork();
|
||||
strictEqual(w._write, _write);
|
||||
strictEqual(w._writev, _writev);
|
||||
|
||||
w2.write(Buffer.from('blerg'));
|
||||
w2.write(Buffer.from('blerg'));
|
||||
w2.end();
|
||||
w.write(Buffer.from('blerg'));
|
||||
|
||||
const w3 = new Writable();
|
||||
w.cork();
|
||||
w.write(Buffer.from('blerg'));
|
||||
w.write(Buffer.from('blerg'));
|
||||
|
||||
w3.on('error', common.expectsError({
|
||||
w.end();
|
||||
|
||||
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'));
|
||||
|
Loading…
x
Reference in New Issue
Block a user