LibreChat/e2e/specs/mock/lia.helpers.ts
Marco Beretta f36fa7c15f
🎨 feat: Add Lia's Pixel Art Renderer (#16682)
* feat: Add Lia's Pixel Art Renderer

Lia is a small CRT monitor mascot with a face on its screen. This adds the canvas renderer: the body, feet and arm poses, body poses, 62 expressions built from eyes, mouths, brows and extras, and the built-in screens for booting, sending and crashing. Nothing renders it yet.

* test: Assert Each Built-In Lia Screen Draws Its Own Picture

* test: Include the Cached Face Image in Lia's Drawing Signatures

* fix: Clip Lia's Glitch Strips to Her Screen and End the Hide Pose Fully Hidden

* test: Check Lia's Pixel Art in a Real Browser Canvas

* test: Share the Page That Serves Lia's Engine to Browser Specs

* test: Bound-Check Where Lia's Images Land, Not Just Her Rectangles

* test: Check Lia's Face Bounds for Every Gaze Direction

* fix: Drop Lia's Sunglasses In From the Top Row of Her Screen

* test: Check Where Lia's Glitch Strips Are Copied From, Not Only Where They Land
2026-10-03 23:29:51 +02:00

35 lines
1.4 KiB
TypeScript

import fs from 'fs';
import path from 'path';
import ts from 'typescript';
import type { Page } from '@playwright/test';
const ENGINE = path.resolve(__dirname, '../../../client/src/components/Lia/engine');
const ORIGIN = 'http://lia.test';
/**
* Serves Lia's engine modules to a blank page and exposes them as `window.lia[name]`, so a spec
* can drive the renderer and the engine with a real browser canvas and animation frames.
*/
export async function openLiaEngine(page: Page, modules: readonly string[]) {
await page.route(`${ORIGIN}/**`, (route) => {
const name = new URL(route.request().url()).pathname.slice(1);
if (!name) {
return route.fulfill({ contentType: 'text/html', body: '<!doctype html><body></body>' });
}
if (!/^[a-z]+$/.test(name)) {
return route.fulfill({ status: 404 });
}
const source = fs.readFileSync(path.join(ENGINE, `${name}.ts`), 'utf8');
const { outputText } = ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2022 },
});
return route.fulfill({ contentType: 'text/javascript', body: outputText });
});
await page.goto(`${ORIGIN}/`);
const imports = modules.map((name) => `import * as ${name} from '/${name}';`).join(' ');
await page.addScriptTag({
type: 'module',
content: `${imports} window.lia = { ${modules.join(', ')} };`,
});
await page.waitForFunction(() => 'lia' in window);
}