mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
[AI-generated] Fix unhandled rejection when disposing invalid input (#413)
* Fix input dispose rejection handling * Move input disposal regression test
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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([]);
|
||||
});
|
||||
Reference in New Issue
Block a user