node/test/parallel/test-stream-writable-constructor-set-methods.js
Luigi Pinca 6f0ec79e42 http,stream: make virtual methods throw an error
Make virtual methods throw an ERR_METHOD_NOT_IMPLEMENTED error instead
of emitting it.

The error is not recoverable and the only way to handle it is to
override the method.

PR-URL: https://github.com/nodejs/node/pull/31912
Refs: https://github.com/nodejs/node/pull/31818#pullrequestreview-359403469
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-03-07 07:27:02 +01:00

42 lines
785 B
JavaScript

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