From ef9ffcd1f4851e0602301bd87a46cc27d4026a40 Mon Sep 17 00:00:00 2001 From: Julien Malard-Adam Date: Sun, 16 Feb 2025 16:41:43 +0100 Subject: [PATCH] Add test for https://github.com/orbitdb/orbitdb/pull/1221 --- test/sync.test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/sync.test.js b/test/sync.test.js index b3d2190..5c2618e 100644 --- a/test/sync.test.js +++ b/test/sync.test.js @@ -720,5 +720,29 @@ describe('Sync protocol', function () { strictEqual(err.type, 'aborted') strictEqual(err.message, 'Read aborted') }) + + it('does not crash when no listeners are attached to the `error` event on `Sync.events`', async () => { + let err = null + + const onError = (error) => { + (!err) && (err = error) + } + + sync1 = await Sync({ ipfs: ipfs1, log: log1, timeout: timeoutTime }) + sync2 = await Sync({ ipfs: ipfs2, log: log2, start: false, timeout: timeoutTime }) + + // `sync1.events` has no listener on `error` + sync2.events.on('error', onError) + + await log1.append('hello1') + + await sync2.start() + + await waitFor(() => err !== null, () => true) + + notStrictEqual(err, null) + strictEqual(err.type, 'aborted') + strictEqual(err.message, 'Read aborted') + }) }) })