mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-30 06:12:06 -07:00
refactor(main): extract remaining inline runtime logic from main
This commit is contained in:
80
src/main/runtime/youtube-playback-runtime.test.ts
Normal file
80
src/main/runtime/youtube-playback-runtime.test.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createYoutubePlaybackRuntime } from './youtube-playback-runtime';
|
||||
|
||||
test('youtube playback runtime resets flow ownership after a successful run', async () => {
|
||||
const calls: string[] = [];
|
||||
let appOwnedFlowInFlight = false;
|
||||
let timeoutCallback: (() => void) | null = null;
|
||||
|
||||
const runtime = createYoutubePlaybackRuntime({
|
||||
platform: 'linux',
|
||||
directPlaybackFormat: 'best',
|
||||
mpvYtdlFormat: 'bestvideo+bestaudio',
|
||||
autoLaunchTimeoutMs: 2_000,
|
||||
connectTimeoutMs: 1_000,
|
||||
socketPath: '/tmp/mpv.sock',
|
||||
getMpvConnected: () => true,
|
||||
invalidatePendingAutoplayReadyFallbacks: () => {
|
||||
calls.push('invalidate-autoplay');
|
||||
},
|
||||
setAppOwnedFlowInFlight: (next) => {
|
||||
appOwnedFlowInFlight = next;
|
||||
calls.push(`app-owned:${next}`);
|
||||
},
|
||||
ensureYoutubePlaybackRuntimeReady: async () => {
|
||||
calls.push('ensure-runtime-ready');
|
||||
},
|
||||
resolveYoutubePlaybackUrl: async () => {
|
||||
throw new Error('linux path should not resolve direct playback url');
|
||||
},
|
||||
launchWindowsMpv: () => ({ ok: false }),
|
||||
waitForYoutubeMpvConnected: async (timeoutMs) => {
|
||||
calls.push(`wait-connected:${timeoutMs}`);
|
||||
return true;
|
||||
},
|
||||
prepareYoutubePlaybackInMpv: async ({ url }) => {
|
||||
calls.push(`prepare:${url}`);
|
||||
return true;
|
||||
},
|
||||
runYoutubePlaybackFlow: async ({ url, mode }) => {
|
||||
calls.push(`run-flow:${url}:${mode}`);
|
||||
},
|
||||
logInfo: (message) => {
|
||||
calls.push(`info:${message}`);
|
||||
},
|
||||
logWarn: (message) => {
|
||||
calls.push(`warn:${message}`);
|
||||
},
|
||||
schedule: (callback) => {
|
||||
timeoutCallback = callback;
|
||||
calls.push('schedule-arm');
|
||||
return 1 as never;
|
||||
},
|
||||
clearScheduled: () => {
|
||||
calls.push('clear-scheduled');
|
||||
},
|
||||
});
|
||||
|
||||
await runtime.runYoutubePlaybackFlow({
|
||||
url: 'https://youtu.be/demo',
|
||||
mode: 'download',
|
||||
source: 'initial',
|
||||
});
|
||||
|
||||
assert.equal(appOwnedFlowInFlight, false);
|
||||
assert.equal(runtime.getQuitOnDisconnectArmed(), false);
|
||||
assert.deepEqual(calls.slice(0, 6), [
|
||||
'invalidate-autoplay',
|
||||
'app-owned:true',
|
||||
'ensure-runtime-ready',
|
||||
'wait-connected:1000',
|
||||
'schedule-arm',
|
||||
'prepare:https://youtu.be/demo',
|
||||
]);
|
||||
|
||||
assert.ok(timeoutCallback);
|
||||
const scheduledCallback = timeoutCallback as () => void;
|
||||
scheduledCallback();
|
||||
assert.equal(runtime.getQuitOnDisconnectArmed(), true);
|
||||
});
|
||||
Reference in New Issue
Block a user