deno.land / std@0.166.0 / node / _tools / test / parallel / test-stream-construct.js
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288// deno-fmt-ignore-file// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.// Taken from Node 18.12.0// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');const { Writable, Readable, Duplex } = require('stream');const assert = require('assert');
{ // Multiple callback. new Writable({ construct: common.mustCall((callback) => { callback(); callback(); }) }).on('error', common.expectsError({ name: 'Error', code: 'ERR_MULTIPLE_CALLBACK' }));}
{ // Multiple callback. new Readable({ construct: common.mustCall((callback) => { callback(); callback(); }) }).on('error', common.expectsError({ name: 'Error', code: 'ERR_MULTIPLE_CALLBACK' }));}
{ // Synchronous error.
new Writable({ construct: common.mustCall((callback) => { callback(new Error('test')); }) }).on('error', common.expectsError({ name: 'Error', message: 'test' }));}
{ // Synchronous error.
new Readable({ construct: common.mustCall((callback) => { callback(new Error('test')); }) }).on('error', common.expectsError({ name: 'Error', message: 'test' }));}
{ // Asynchronous error.
new Writable({ construct: common.mustCall((callback) => { process.nextTick(callback, new Error('test')); }) }).on('error', common.expectsError({ name: 'Error', message: 'test' }));}
{ // Asynchronous error.
new Readable({ construct: common.mustCall((callback) => { process.nextTick(callback, new Error('test')); }) }).on('error', common.expectsError({ name: 'Error', message: 'test' }));}
function testDestroy(factory) { { let constructed = false; const s = factory({ construct: common.mustCall((cb) => { constructed = true; process.nextTick(cb); }) }); s.on('close', common.mustCall(() => { assert.strictEqual(constructed, true); })); s.destroy(); }
{ let constructed = false; const s = factory({ construct: common.mustCall((cb) => { constructed = true; process.nextTick(cb); }) }); s.on('close', common.mustCall(() => { assert.strictEqual(constructed, true); })); s.destroy(null, () => { assert.strictEqual(constructed, true); }); }
{ let constructed = false; const s = factory({ construct: common.mustCall((cb) => { constructed = true; process.nextTick(cb); }) }); s.on('close', common.mustCall(() => { assert.strictEqual(constructed, true); })); s.destroy(); }
{ let constructed = false; const s = factory({ construct: common.mustCall((cb) => { constructed = true; process.nextTick(cb); }) }); s.on('close', common.mustCall(() => { assert.strictEqual(constructed, true); })); s.on('error', common.mustCall((err) => { assert.strictEqual(err.message, 'kaboom'); })); s.destroy(new Error('kaboom'), (err) => { assert.strictEqual(err.message, 'kaboom'); assert.strictEqual(constructed, true); }); }
{ let constructed = false; const s = factory({ construct: common.mustCall((cb) => { constructed = true; process.nextTick(cb); }) }); s.on('error', common.mustCall(() => { assert.strictEqual(constructed, true); })); s.on('close', common.mustCall(() => { assert.strictEqual(constructed, true); })); s.destroy(new Error()); }}testDestroy((opts) => new Readable({ read: common.mustNotCall(), ...opts}));testDestroy((opts) => new Writable({ write: common.mustNotCall(), final: common.mustNotCall(), ...opts}));
{ let constructed = false; const r = new Readable({ autoDestroy: true, construct: common.mustCall((cb) => { constructed = true; process.nextTick(cb); }), read: common.mustCall(() => { assert.strictEqual(constructed, true); r.push(null); }) }); r.on('close', common.mustCall(() => { assert.strictEqual(constructed, true); })); r.on('data', common.mustNotCall());}
{ let constructed = false; const w = new Writable({ autoDestroy: true, construct: common.mustCall((cb) => { constructed = true; process.nextTick(cb); }), write: common.mustCall((chunk, encoding, cb) => { assert.strictEqual(constructed, true); process.nextTick(cb); }), final: common.mustCall((cb) => { assert.strictEqual(constructed, true); process.nextTick(cb); }) }); w.on('close', common.mustCall(() => { assert.strictEqual(constructed, true); })); w.end('data');}
{ let constructed = false; const w = new Writable({ autoDestroy: true, construct: common.mustCall((cb) => { constructed = true; process.nextTick(cb); }), write: common.mustNotCall(), final: common.mustCall((cb) => { assert.strictEqual(constructed, true); process.nextTick(cb); }) }); w.on('close', common.mustCall(() => { assert.strictEqual(constructed, true); })); w.end();}
{ new Duplex({ construct: common.mustCall() });}
{ // https://github.com/nodejs/node/issues/34448
let constructed = false; const d = new Duplex({ readable: false, construct: common.mustCall((callback) => { setImmediate(common.mustCall(() => { constructed = true; callback(); })); }), write(chunk, encoding, callback) { callback(); }, read() { this.push(null); } }); d.resume(); d.end('foo'); d.on('close', common.mustCall(() => { assert.strictEqual(constructed, true); }));}
{ // Construct should not cause stream to read. new Readable({ construct: common.mustCall((callback) => { callback(); }), read: common.mustNotCall() });}
Version Info