Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
129 lines
3.9 KiB
TypeScript
129 lines
3.9 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
CHROME_THEME_CSS_CACHE_MAX_ENTRIES,
|
|
_cacheChromeThemeCssForTests,
|
|
_getChromeThemeCssCacheStatsForTests,
|
|
scheduleChromeLayoutAnimation,
|
|
syncActiveChromeTheme,
|
|
themeFingerprint,
|
|
} from "./useActiveChromeTheme.ts";
|
|
import { TERMINAL_THEMES } from "../../infrastructure/config/terminalThemes.ts";
|
|
import { readFileSync } from "node:fs";
|
|
|
|
function createInlineStyle() {
|
|
const values = new Map<string, string>();
|
|
return {
|
|
getPropertyValue: (name: string) => values.get(name) ?? "",
|
|
setProperty: (name: string, value: string) => values.set(name, value),
|
|
removeProperty: (name: string) => values.delete(name),
|
|
};
|
|
}
|
|
|
|
function createRafRoot() {
|
|
const callbacks = new Map<number, FrameRequestCallback>();
|
|
let nextId = 1;
|
|
const view = {
|
|
requestAnimationFrame: (callback: FrameRequestCallback) => {
|
|
const id = nextId++;
|
|
callbacks.set(id, callback);
|
|
return id;
|
|
},
|
|
cancelAnimationFrame: (id: number) => {
|
|
callbacks.delete(id);
|
|
},
|
|
};
|
|
const root = {
|
|
ownerDocument: { defaultView: view },
|
|
} as unknown as HTMLElement;
|
|
|
|
const flushFrame = () => {
|
|
const [id, callback] = callbacks.entries().next().value ?? [];
|
|
if (!id || !callback) return false;
|
|
callbacks.delete(id);
|
|
callback(0);
|
|
return true;
|
|
};
|
|
|
|
return { root, flushFrame };
|
|
}
|
|
|
|
test("chrome layout animations wait until theme settle frames complete", () => {
|
|
const { root, flushFrame } = createRafRoot();
|
|
let ran = false;
|
|
|
|
const cancel = scheduleChromeLayoutAnimation(() => {
|
|
ran = true;
|
|
}, root);
|
|
|
|
while (!ran && flushFrame()) {
|
|
// Drain scheduled animation frames.
|
|
}
|
|
assert.equal(ran, true);
|
|
cancel();
|
|
});
|
|
|
|
test("syncActiveChromeTheme skips surface refresh when the active theme fingerprint is unchanged", () => {
|
|
const globalWithDocument = globalThis as typeof globalThis & { document?: Document };
|
|
const originalDocument = globalWithDocument.document;
|
|
const theme = TERMINAL_THEMES[0];
|
|
assert.ok(theme);
|
|
const topTabsRoot = {
|
|
style: createInlineStyle(),
|
|
};
|
|
const documentElement = {
|
|
dataset: { activeChromeTheme: themeFingerprint(theme) },
|
|
};
|
|
const fakeDocument = {
|
|
documentElement,
|
|
querySelector: (selector: string) => selector === "[data-top-tabs-root]" ? topTabsRoot : null,
|
|
};
|
|
globalWithDocument.document = fakeDocument as unknown as Document;
|
|
|
|
try {
|
|
syncActiveChromeTheme(theme, () => {
|
|
throw new Error("app theme should not be restored for an unchanged active chrome theme");
|
|
});
|
|
|
|
assert.equal(topTabsRoot.style.getPropertyValue("--top-tabs-bg"), "");
|
|
assert.equal(topTabsRoot.style.getPropertyValue("--top-tabs-active-bg"), "");
|
|
assert.equal(topTabsRoot.style.getPropertyValue("--top-tabs-accent"), "");
|
|
} finally {
|
|
if (originalDocument) {
|
|
globalWithDocument.document = originalDocument;
|
|
} else {
|
|
delete globalWithDocument.document;
|
|
}
|
|
}
|
|
});
|
|
|
|
test("active chrome theme foreground uses contrast calculation", () => {
|
|
const source = readFileSync(new URL("./useActiveChromeTheme.ts", import.meta.url), "utf8");
|
|
|
|
assert.match(source, /resolveReadableForegroundForHsl\(cursor\)/);
|
|
assert.doesNotMatch(source, /cursorLightness > 55/);
|
|
});
|
|
|
|
test("edited theme previews cannot grow the chrome CSS cache without bound", () => {
|
|
const base = TERMINAL_THEMES[0];
|
|
assert.ok(base);
|
|
let latestFingerprint = "";
|
|
for (let index = 0; index < CHROME_THEME_CSS_CACHE_MAX_ENTRIES * 2; index += 1) {
|
|
const theme = {
|
|
...base,
|
|
id: `edited-preview-${index}`,
|
|
colors: {
|
|
...base.colors,
|
|
background: `#${index.toString(16).padStart(6, "0")}`,
|
|
},
|
|
};
|
|
latestFingerprint = themeFingerprint(theme);
|
|
_cacheChromeThemeCssForTests(theme);
|
|
}
|
|
|
|
const stats = _getChromeThemeCssCacheStatsForTests();
|
|
assert.equal(stats.size, CHROME_THEME_CSS_CACHE_MAX_ENTRIES);
|
|
assert.equal(stats.keys.at(-1), latestFingerprint);
|
|
});
|