@@ -43,7 +43,14 @@ export interface LaunchElectronAppOptions {
4343 envOverrides ?: Record < string , string > ;
4444}
4545
46- /** Wait for the WebSocket server to be ready on the specified port. */
46+ /**
47+ * Wait for the WebSocket server to be ready on the specified port.
48+ *
49+ * @param port Port number to connect to.
50+ * @param timeout Maximum time in milliseconds to wait before throwing.
51+ * @returns Resolves when a WebSocket connection to the port succeeds.
52+ * @throws {Error } If the WebSocket server is not ready within `timeout` milliseconds.
53+ */
4754async function waitForWebSocketReady ( port : number , timeout : number ) : Promise < void > {
4855 const startTime = Date . now ( ) ;
4956
@@ -79,8 +86,12 @@ async function waitForWebSocketReady(port: number, timeout: number): Promise<voi
7986
8087/**
8188 * Launch a fresh Electron instance (paranext-core) with the interlinearizer extension loaded via
82- * `--extensionDirs`. Returns the app handle, the temp directory path, and a promise that resolves
83- * when the app closes.
89+ * `--extensions`.
90+ *
91+ * @param opts Optional launch options (e.g. environment variable overrides).
92+ * @returns The app handle, the isolated user-data directory path, and a promise that resolves when
93+ * the app closes.
94+ * @throws If Electron fails to launch or the WebSocket server does not become ready.
8495 */
8596export async function launchElectronWithExtension (
8697 opts : LaunchElectronAppOptions = { } ,
@@ -161,6 +172,9 @@ export async function launchElectronWithExtension(
161172/**
162173 * Tear down an Electron instance: kill the process group, wait for close, and clean up the isolated
163174 * user-data directory.
175+ *
176+ * @param ctx The app context returned by {@link launchElectronWithExtension}.
177+ * @returns Resolves when the Electron process has been killed and user-data cleaned up.
164178 */
165179export async function teardownElectronApp ( ctx : ElectronAppContext ) : Promise < void > {
166180 const { electronApp, userDataDir, appClosed } = ctx ;
@@ -218,6 +232,15 @@ export async function teardownElectronApp(ctx: ElectronAppContext): Promise<void
218232/**
219233 * One JSON-RPC 2.0 request over WebSocket: open, send, wait for response id `1`, close. Ignores
220234 * unrelated messages until the matching response arrives.
235+ *
236+ * @param method JSON-RPC method name to invoke.
237+ * @param timeoutErrorMessage Custom error message on timeout; defaults to a standard timeout
238+ * message.
239+ * @param params Positional parameters to send with the request.
240+ * @param port WebSocket port to connect to.
241+ * @param perRequestTimeoutMs Milliseconds before the request times out.
242+ * @returns The `result` field of the JSON-RPC response, typed as `T`.
243+ * @throws {Error } If the request times out or the server returns a JSON-RPC error.
221244 */
222245async function sendPapiJsonRpcOnce < T > (
223246 method : string ,
@@ -278,6 +301,13 @@ async function sendPapiJsonRpcOnce<T>(
278301/**
279302 * Send a single JSON-RPC request where `method` is a PAPI request type (e.g. `rpc.discover`). Opens
280303 * a connection, sends one request, waits for the matching response id, then closes.
304+ *
305+ * @param method PAPI request type to invoke (e.g. `rpc.discover`).
306+ * @param params Positional parameters to send with the request.
307+ * @param port WebSocket port to connect to.
308+ * @param perRequestTimeoutMs Milliseconds before the request times out.
309+ * @returns The `result` field of the JSON-RPC response, typed as `T`.
310+ * @throws {Error } If the request times out or the server returns a JSON-RPC error.
281311 */
282312export async function sendPapiRequestOnce < T > (
283313 method : string ,
@@ -288,7 +318,15 @@ export async function sendPapiRequestOnce<T>(
288318 return sendPapiJsonRpcOnce < T > ( method , undefined , params , port , perRequestTimeoutMs ) ;
289319}
290320
291- /** Poll `rpc.discover` until `methodName` appears in `result.methods` or `timeoutMs` elapses. */
321+ /**
322+ * Poll `rpc.discover` until `methodName` appears in `result.methods` or `timeoutMs` elapses.
323+ *
324+ * @param methodName The fully-qualified PAPI method name to wait for (e.g. `command:foo.bar`).
325+ * @param port WebSocket port to connect to.
326+ * @param timeoutMs Maximum time in milliseconds to poll before throwing.
327+ * @returns Resolves when the method appears in `rpc.discover`.
328+ * @throws {Error } If the method is not registered within `timeoutMs` milliseconds.
329+ */
292330export async function waitForPapiMethodRegistered (
293331 methodName : string ,
294332 port : number = DEFAULT_WEBSOCKET_PORT ,
@@ -320,6 +358,12 @@ export async function waitForPapiMethodRegistered(
320358/**
321359 * Wait for the Platform.Bible UI to be fully ready: dock layout appears and `platform.about`
322360 * command is registered (dialog service has finished initializing).
361+ *
362+ * @param page The Playwright `Page` for the Platform.Bible renderer window.
363+ * @param timeout Maximum time in milliseconds to wait before throwing.
364+ * @returns Resolves when the dock layout is visible and `platform.about` is registered.
365+ * @throws If the dock layout or `platform.about` command does not appear within `timeout`
366+ * milliseconds.
323367 */
324368export async function waitForAppReady ( page : Page , timeout = 60_000 ) : Promise < void > {
325369 const start = Date . now ( ) ;
@@ -334,6 +378,10 @@ export async function waitForAppReady(page: Page, timeout = 60_000): Promise<voi
334378/**
335379 * Wait for the interlinearizer extension to finish activating by polling `rpc.discover` until
336380 * `interlinearizer.openForWebView` is listed.
381+ *
382+ * @param timeoutMs Maximum time in milliseconds to poll before throwing.
383+ * @returns Resolves when `interlinearizer.openForWebView` is listed in `rpc.discover`.
384+ * @throws {Error } If the extension does not register within `timeoutMs` milliseconds.
337385 */
338386export async function waitForInterlinearizerReady ( timeoutMs = 90_000 ) : Promise < void > {
339387 await waitForPapiMethodRegistered (
0 commit comments