mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
* Fix input dispose rejection handling * Move input disposal regression test
29 lines
915 B
TypeScript
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([]);
|
|
});
|