import { expect, test } from 'vitest'; import { Input, UnsupportedInputFormatError } from '../../src/input.js'; import { ALL_FORMATS } from '../../src/input-format.js'; import { BufferSource } from '../../src/source.js'; test('Disposing after failed format detection does not emit an unhandled rejection', async () => { const input = new Input({ source: new BufferSource(new Uint8Array([1, 2, 3, 4])), formats: ALL_FORMATS, }); await expect(input.getFormat()).rejects.toThrow(UnsupportedInputFormatError); const unhandledRejections: unknown[] = []; const onUnhandledRejection = (reason: unknown) => { unhandledRejections.push(reason); }; process.on('unhandledRejection', onUnhandledRejection); try { input.dispose(); await new Promise(resolve => setTimeout(resolve, 0)); } finally { process.off('unhandledRejection', onUnhandledRejection); } expect(unhandledRejections).toEqual([]); });