summaryrefslogtreecommitdiff
path: root/test/parallel/test-stream-writable-constructor-set-methods.js
blob: 41779d7e519db40a32332073b68af3b64d847cac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'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'
}));

const bufferBlerg = Buffer.from('blerg');

w.end(bufferBlerg);

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(bufferBlerg);

w2.cork();
w2.write(bufferBlerg);
w2.write(bufferBlerg);

w2.end();