Files
mediabunny/test/node/input.test.ts
T
Jonny BurgerandGitHub 0da1107858 [AI-generated] Fix unhandled rejection when disposing invalid input (#413)
* Fix input dispose rejection handling

* Move input disposal regression test
2026-06-15 16:25:02 +02:00

29 lines
915 B
TypeScript

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([]);
});