Files
RuneStone/browser-runtime/test/interaction-engine.mjs
T
2026-11-16 04:21:21 -07:00

26 lines
1.4 KiB
JavaScript

// This IPC adapter exists only for the browser UI smoke test.
import { app } from 'electron';
import { createEngine } from '../src/engine.mjs';
app.enableSandbox();
app.setPath('userData', process.env.RS_INTERACTION_ROOT);
app.on('window-all-closed', () => {});
app.whenReady().then(async () => {
let framePending = false;
// The fixture server of the smoke test is on 127.0.0.1. The engine blocks local addresses for other hosts.
const engine = await createEngine({ directory: process.env.RS_INTERACTION_ROOT, allowedTestHosts: new Set(['127.0.0.1']), canEmitFrame: () => !framePending, emit: value => {
if (value.event === 'frame') framePending = true;
process.send?.({ event: value }, () => { if (value.event === 'frame') framePending = false; });
} });
process.on('message', async ({ id, command, args }) => {
try {
let result;
if (command === 'testEvaluate') result = await engine.tabs.get(args.tabId).view.webContents.executeJavaScript(args.code);
else if (command === 'shutdown') { await engine.shutdown(); process.send?.({ id, result: null }); app.exit(0); return; }
else result = await engine.command(command, args);
process.send?.({ id, result });
} catch (error) { process.send?.({ id, error: String(error) }); }
});
process.on('disconnect', () => { void engine.shutdown().finally(() => app.exit(0)); });
process.send?.({ ready: true });
});