Rewrite the launcher in MoonBit (old code moves to legacy/) (#1)
Launcher / test (push) Successful in 1m20s
Launcher / apk (push) Successful in 37s

This commit was merged in pull request #1.
This commit is contained in:
nandi committed 2026-11-23 01:57:10 +00:00
1 parent 7d2bf5996f
commit 2fa7bd745b
150 files changed
+8319 -462

No files matched your search

+36 -8
View File
@@ -1,12 +1,33 @@
// Browser smoke test for the launcher's web UI, against the demo apps.json and widgets.json.
// pixi run test (or: pixi run serve & then node tests/e2e.cjs)
// Browser test of the launcher page built from MoonBit (dist/web, see scripts/build-web.sh),
// against the demo apps.json and widgets.json: the same flows legacy/tests/e2e.cjs drove.
// scripts/build-web.sh --demo && node tests/e2e.cjs
// Serves dist/web itself unless BASE points at a running copy. PLAYWRIGHT names the
// playwright module to load when it is not installed next to the repo; SHOTS=dir saves screenshots.
const assert = require("assert");
const fs = require("fs");
const http = require("http");
const path = require("path");
const { chromium } = require(process.env.PLAYWRIGHT || "playwright");
const BASE = process.env.BASE || "http://localhost:8000";
const serve = () => new Promise((resolve) => {
const root = path.join(__dirname, "..", "dist", "web");
const types = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".json": "application/json" };
const srv = http.createServer((req, res) => {
const f = path.join(root, req.url.split("?")[0] === "/" ? "index.html" : req.url.split("?")[0]);
fs.readFile(f, (err, data) => {
if (err) { res.writeHead(404); res.end(); return; }
res.writeHead(200, { "content-type": types[path.extname(f)] || "application/octet-stream" });
res.end(data);
});
}).listen(0, () => resolve([srv, `http://localhost:${srv.address().port}`]));
});
(async () => {
const b = await chromium.launch();
const p = await b.newPage();
const [srv, served] = process.env.BASE ? [null, process.env.BASE] : await serve();
const BASE = served;
const shot = async (p, name) => { if (process.env.SHOTS) await p.screenshot({ path: path.join(process.env.SHOTS, name + ".png") }); };
const b = await chromium.launch({ executablePath: process.env.CHROMIUM_PATH || undefined });
const p = await b.newPage({ viewport: { width: 390, height: 780 } });
p.on("pageerror", (e) => { console.error("page error:", e.message); process.exitCode = 1; });
const settle = () => p.waitForTimeout(250); // renders land on the next frame, which can lag here
@@ -15,6 +36,7 @@ const BASE = process.env.BASE || "http://localhost:8000";
await p.evaluate(() => localStorage.clear());
await p.reload();
await p.waitForSelector(".hint");
await shot(p, "00-blank-home");
assert.ok(!(await p.$(".clock")), "home has no built-in clock");
const longpress = async (sel, fy = 0.5) => {
const r = await p.locator(sel).first().boundingBox();
@@ -35,6 +57,7 @@ const BASE = process.env.BASE || "http://localhost:8000";
assert.equal(await p.$$eval(".apps .tile.on", (ts) => ts.length), 3);
await p.click(".drawer-head >> text=Done"); await settle();
assert.deepEqual(await homeApps(), ["Chrome", "Gmail", "Phone"]);
await shot(p, "01-home-with-apps");
// add a widget: long press on blank home, below the apps
await longpress(".home", 0.95);
await p.click(".sheet-item >> text=Add widget");
@@ -50,6 +73,7 @@ const BASE = process.env.BASE || "http://localhost:8000";
await p.fill(".widget-search", ""); await settle();
await p.click(".widget-list li:first-child"); await settle();
assert.equal(await p.getAttribute(".widget-slot", "data-wid"), "100");
await shot(p, "02-widget-placeholder");
assert.equal(await p.textContent(".widget-label"), "Clock");
// hold a home app and drag it: reorder
const drag = async (from, to) => {
@@ -100,11 +124,12 @@ const BASE = process.env.BASE || "http://localhost:8000";
// swipe down opens the drawer (and takes the widget off screen), search, long press adds
const swipe = (y0, y1) => p.evaluate(([y0, y1]) => {
const at = (y) => new Touch({ identifier: 1, target: document.body, clientX: 200, clientY: y });
dispatchEvent(new TouchEvent("touchstart", { touches: [at(y0)], changedTouches: [at(y0)] }));
dispatchEvent(new TouchEvent("touchend", { touches: [], changedTouches: [at(y1)] }));
document.body.dispatchEvent(new TouchEvent("touchstart", { bubbles: true, touches: [at(y0)], changedTouches: [at(y0)] }));
document.body.dispatchEvent(new TouchEvent("touchend", { bubbles: true, touches: [], changedTouches: [at(y1)] }));
}, [y0, y1]);
await swipe(200, 500);
await p.waitForSelector(".drawer", { timeout: 2000 });
await shot(p, "03-drawer");
assert.equal(await p.$$eval("[data-wid]", (ws) => ws.length), 0);
assert.ok(await p.$eval(".drawer input", (i) => i === document.activeElement), "opening the drawer focuses its search");
await p.fill(".drawer input", "ma"); await settle();
@@ -116,6 +141,7 @@ const BASE = process.env.BASE || "http://localhost:8000";
await p.waitForSelector(".drawer .tile", { timeout: 2000 });
await longpress(".apps .tile:first-child");
assert.deepEqual(await p.$$eval(".sheet-item", (bs) => bs.map((b) => b.textContent)), ["Add to home", "App info", "Uninstall"]);
await shot(p, "04-drawer-app-menu");
await p.click(".sheet-item:has-text('Uninstall')"); await settle();
assert.equal(await p.textContent("#toast"), "Uninstall com.example.calculator/.MainActivity");
assert.ok(!(await p.$(".sheet")) && (await p.$(".drawer")), "uninstalling closes the menu, not the drawer");
@@ -138,6 +164,7 @@ const BASE = process.env.BASE || "http://localhost:8000";
await longpress(".widget-slot");
assert.ok(!(await p.$(".sheet")), "a widget gets handles, not the menu");
assert.ok(await p.$(".widget-slot.resizing .resize-handle[data-edge=rb]"));
await shot(p, "05-resize-handles");
const size = () => p.$eval(".widget-slot", (w) => [Math.round(w.getBoundingClientRect().width), Math.round(w.getBoundingClientRect().height)]);
const [w0] = await size();
const tile = await p.locator(".slots .tile").first().boundingBox();
@@ -181,9 +208,10 @@ const BASE = process.env.BASE || "http://localhost:8000";
assert.ok(!(await p.$(".sheet")));
await p.click(".resize-bar >> text=Remove"); await settle();
assert.ok(!(await p.$(".widget-slot")));
await p.evaluate(() => { window.ultraHome.reload(); }); await settle();
await p.evaluate(() => { window.launcher.reload(); }); await settle();
assert.equal(await p.$$eval(".slots > li", (ls) => ls.length), 4);
console.log("launcher ok");
await b.close();
if (srv) srv.close();
})().catch((e) => { console.error(e); process.exit(1); });