|
1 | 1 | 'use strict';
|
2 | 2 | const common = require('../common');
|
3 |
| -const assert = require('assert'); |
4 | 3 |
|
5 |
| -const Writable = require('stream').Writable; |
| 4 | +const { strictEqual } = require('assert'); |
| 5 | +const { Writable } = require('stream'); |
6 | 6 |
|
7 |
| -let _writeCalled = false; |
8 |
| -function _write(d, e, n) { |
9 |
| - _writeCalled = true; |
10 |
| -} |
| 7 | +const _write = common.mustCall((chunk, _, next) => { |
| 8 | + next(); |
| 9 | +}); |
| 10 | + |
| 11 | +const _writev = common.mustCall((chunks, next) => { |
| 12 | + strictEqual(chunks.length, 2); |
| 13 | + next(); |
| 14 | +}); |
11 | 15 |
|
12 |
| -const w = new Writable({ write: _write }); |
13 |
| -w.end(Buffer.from('blerg')); |
| 16 | +const w = new Writable({ write: _write, writev: _writev }); |
14 | 17 |
|
15 |
| -let _writevCalled = false; |
16 |
| -let dLength = 0; |
17 |
| -function _writev(d, n) { |
18 |
| - dLength = d.length; |
19 |
| - _writevCalled = true; |
20 |
| -} |
| 18 | +strictEqual(w._write, _write); |
| 19 | +strictEqual(w._writev, _writev); |
21 | 20 |
|
22 |
| -const w2 = new Writable({ writev: _writev }); |
23 |
| -w2.cork(); |
| 21 | +w.write(Buffer.from('blerg')); |
24 | 22 |
|
25 |
| -w2.write(Buffer.from('blerg')); |
26 |
| -w2.write(Buffer.from('blerg')); |
27 |
| -w2.end(); |
| 23 | +w.cork(); |
| 24 | +w.write(Buffer.from('blerg')); |
| 25 | +w.write(Buffer.from('blerg')); |
28 | 26 |
|
29 |
| -const w3 = new Writable(); |
| 27 | +w.end(); |
30 | 28 |
|
31 |
| -w3.on('error', common.expectsError({ |
| 29 | +const w2 = new Writable(); |
| 30 | + |
| 31 | +w2.on('error', common.expectsError({ |
32 | 32 | type: Error,
|
33 | 33 | code: 'ERR_METHOD_NOT_IMPLEMENTED',
|
34 | 34 | message: 'The _write method is not implemented'
|
35 | 35 | }));
|
36 | 36 |
|
37 |
| -w3.end(Buffer.from('blerg')); |
38 |
| - |
39 |
| -process.on('exit', function() { |
40 |
| - assert.strictEqual(w._write, _write); |
41 |
| - assert(_writeCalled); |
42 |
| - assert.strictEqual(w2._writev, _writev); |
43 |
| - assert.strictEqual(dLength, 2); |
44 |
| - assert(_writevCalled); |
45 |
| -}); |
| 37 | +w2.end(Buffer.from('blerg')); |
0 commit comments