mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-06-17 03:13:30 -07:00
refactor(main): split main.ts into focused runtime modules (#123)
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
buildFfmpegSubtitleExtractionArgs,
|
||||
extractInternalSubtitleTrackToTempFile,
|
||||
parseTrackId,
|
||||
} from './internal-subtitle-extraction';
|
||||
|
||||
test('buildFfmpegSubtitleExtractionArgs rejects output paths without an extension', () => {
|
||||
assert.throws(
|
||||
() => buildFfmpegSubtitleExtractionArgs('/tmp/video.mkv', 2, '/tmp/subtitle-output'),
|
||||
/outputPath.*file extension/,
|
||||
);
|
||||
});
|
||||
|
||||
test('parseTrackId rejects negative track ids', () => {
|
||||
assert.equal(parseTrackId(-1), null);
|
||||
assert.equal(parseTrackId(' -2 '), null);
|
||||
});
|
||||
|
||||
test('extractInternalSubtitleTrackToTempFile times out stalled ffmpeg process', async () => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-ffmpeg-timeout-'));
|
||||
const videoPath = path.join(root, 'video.mkv');
|
||||
fs.writeFileSync(videoPath, '');
|
||||
|
||||
try {
|
||||
await assert.rejects(
|
||||
() =>
|
||||
extractInternalSubtitleTrackToTempFile(
|
||||
process.execPath,
|
||||
videoPath,
|
||||
{ 'ff-index': 0, codec: 'ass' },
|
||||
{
|
||||
extractionTimeoutMs: 20,
|
||||
spawnArgsOverride: ['-e', 'setTimeout(() => {}, 1000);'],
|
||||
},
|
||||
),
|
||||
/ffmpeg extraction timed out/,
|
||||
);
|
||||
} finally {
|
||||
fs.rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user