-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #18817 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
- Loading branch information
1 parent
f18c801
commit b4510f7
Showing
2 changed files
with
35 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 22 additions & 30 deletions
52
test/parallel/test-stream-writable-constructor-set-methods.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 _writev = common.mustCall((chunks, next) => { | ||
strictEqual(chunks.length, 2); | ||
next(); | ||
}); | ||
|
||
const w = new Writable({ write: _write }); | ||
w.end(Buffer.from('blerg')); | ||
const w = new Writable({ write: _write, writev: _writev }); | ||
|
||
let _writevCalled = false; | ||
let dLength = 0; | ||
function _writev(d, n) { | ||
dLength = d.length; | ||
_writevCalled = true; | ||
} | ||
strictEqual(w._write, _write); | ||
strictEqual(w._writev, _writev); | ||
|
||
const w2 = new Writable({ writev: _writev }); | ||
w2.cork(); | ||
w.write(Buffer.from('blerg')); | ||
|
||
w2.write(Buffer.from('blerg')); | ||
w2.write(Buffer.from('blerg')); | ||
w2.end(); | ||
w.cork(); | ||
w.write(Buffer.from('blerg')); | ||
w.write(Buffer.from('blerg')); | ||
|
||
const w3 = new Writable(); | ||
w.end(); | ||
|
||
w3.on('error', common.expectsError({ | ||
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')); |