0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-stream-writable-constructor-set-methods.js
Luigi Pinca c9794880e8 stream: make virtual methods errors consistent
Use the same error code and always emit the error instead of
throwing it.

PR-URL: https://github.com/nodejs/node/pull/18813
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michaë Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-03-12 14:24:34 +01:00

38 lines
756 B
JavaScript

'use strict';
const common = require('../common');
const { strictEqual } = require('assert');
const { Writable } = require('stream');
const w = new Writable();
w.on('error', common.expectsError({
type: Error,
code: 'ERR_METHOD_NOT_IMPLEMENTED',
message: 'The _write() method is not implemented'
}));
w.end(Buffer.from('blerg'));
const _write = common.mustCall((chunk, _, next) => {
next();
});
const _writev = common.mustCall((chunks, next) => {
strictEqual(chunks.length, 2);
next();
});
const w2 = new Writable({ write: _write, writev: _writev });
strictEqual(w2._write, _write);
strictEqual(w2._writev, _writev);
w2.write(Buffer.from('blerg'));
w2.cork();
w2.write(Buffer.from('blerg'));
w2.write(Buffer.from('blerg'));
w2.end();