import {expect, test} from 'bun:test'; import { mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync, } from 'node:fs'; import {tmpdir} from 'node:os'; import path from 'node:path'; import { CodemodsInternals, insertBasicCaptions as insertCaptionsCodemod, type InsertBasicCaptionsOptions, } from '@remotion/codemods'; import type {SequenceNodePath} from 'remotion'; import { createFileWatcherRegistry, setFileWatcherRegistry, } from '../file-watcher'; import {setLiveEventsListener} from '../preview-server/live-events'; import {insertBasicCaptionsHandler} from '../preview-server/routes/insert-basic-captions'; import {getUndoStack} from '../preview-server/undo-stack'; import {lineContainingToNodePath} from './test-utils'; const {basicCaptionsElementSource, getBasicCaptionsElementFile} = CodemodsInternals; const insertBasicCaptions = ({ input, nodePath, ...options }: Omit< InsertBasicCaptionsOptions<{rootDir: string; files: Record}>, 'project' | 'node' > & {input: string; nodePath: SequenceNodePath}) => { const result = insertCaptionsCodemod({ ...options, project: {rootDir: '/', files: {'/Comp.tsx': input}}, node: {filePath: '/Comp.tsx', nodePath}, }); return { ...result, output: result.changes[0]?.nextContents ?? input, logLine: result.editDetails[0].logLine, }; }; test('transcription groups static Video and Audio with inline captions', async () => { const remotionRoot = mkdtempSync(path.join(tmpdir(), 'remotion-captions-')); const entryPoint = path.join(remotionRoot, 'Root.tsx'); const cleanupFileWatcher = setFileWatcherRegistry( createFileWatcherRegistry(), ); const cleanupLiveEvents = setLiveEventsListener({ sendEventToClient: () => undefined, sendEventToClientId: () => true, router: () => Promise.resolve(), closeConnections: () => Promise.resolve(), getClientIds: () => [], addNewClientListener: () => () => undefined, }); const captions = [ { text: ' Hello', startMs: 100, endMs: 400, timestampMs: 250, confidence: null, }, ]; try { (getUndoStack() as unknown as unknown[]).length = 0; writeFileSync( entryPoint, `import {Video, Audio} from '@remotion/media'; import {Composition} from 'remotion'; export const Comp = () => ( <>