diff --git a/index.js b/index.js index d794d7d..4b27091 100644 --- a/index.js +++ b/index.js @@ -77,6 +77,12 @@ const destroyCircular = ({ continue; } + // TODO: Use `stream.isReadable()` when targeting Node.js 18. + if (typeof value === 'object' && typeof value.pipe === 'function') { + to[key] = '[object Stream]'; + continue; + } + if (typeof value === 'function') { continue; } diff --git a/test.js b/test.js index 0e45c35..d53d574 100644 --- a/test.js +++ b/test.js @@ -1,4 +1,5 @@ import {Buffer} from 'node:buffer'; +import Stream from 'node:stream'; import test from 'ava'; import {serializeError, deserializeError} from './index.js'; @@ -82,6 +83,15 @@ test('should discard buffers', t => { t.deepEqual(serialized, {a: '[object Buffer]'}); }); +test('should discard streams', t => { + t.deepEqual(serializeError({s: new Stream.Stream()}), {s: '[object Stream]'}, 'Stream.Stream'); + t.deepEqual(serializeError({s: new Stream.Readable()}), {s: '[object Stream]'}, 'Stream.Readable'); + t.deepEqual(serializeError({s: new Stream.Writable()}), {s: '[object Stream]'}, 'Stream.Writable'); + t.deepEqual(serializeError({s: new Stream.Duplex()}), {s: '[object Stream]'}, 'Stream.Duplex'); + t.deepEqual(serializeError({s: new Stream.Transform()}), {s: '[object Stream]'}, 'Stream.Transform'); + t.deepEqual(serializeError({s: new Stream.PassThrough()}), {s: '[object Stream]'}, 'Stream.PassThrough'); +}); + test('should replace top-level functions with a helpful string', t => { function a() {} function b() {}