import path from 'node:path'; import { expect, test } from 'vitest'; import { Input } from '../../src/input.js'; import { FilePathSource } from '../../src/source.js'; import { ALL_FORMATS } from '../../src/input-format.js'; import { Output } from '../../src/output.js'; import { BufferTarget } from '../../src/target.js'; import { Mp4OutputFormat } from '../../src/output-format.js'; import { Conversion } from '../../src/conversion.js'; const __dirname = new URL('.', import.meta.url).pathname; const samplePath = path.join(__dirname, '../public/video.mp4'); test('BufferTarget onFinalize callback', async () => { let received: ArrayBuffer | null = null; let asyncCallbackDone = false; using input = new Input({ source: new FilePathSource(samplePath), formats: ALL_FORMATS, }); const output = new Output({ format: new Mp4OutputFormat(), target: new BufferTarget({ onFinalize: async (buffer) => { received = buffer; await new Promise(resolve => setTimeout(resolve, 20)); asyncCallbackDone = true; }, }), }); const conversion = await Conversion.init({ input, output, showWarnings: false }); await conversion.execute(); expect(received).not.toBeNull(); expect(received).toBe(output.target.buffer); expect(asyncCallbackDone).toBe(true); expect(output.target.buffer!.byteLength).toBeGreaterThan(0); });