mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-08-07 05:18:53 +00:00
* docs: design frontend performance remediation * docs: plan frontend performance remediation * test(frontend): add route asset performance budgets * perf(nginx): compress textual responses safely * perf(frontend): lazy load case study media * perf(frontend): bound static demo file tracing * perf(frontend): restore static locale boundaries * perf(frontend): defer closed workspace panels * perf(frontend): split editors and deduplicate highlighting * perf(frontend): index incremental message derivation * perf(frontend): stabilize paged history cache policy * perf(frontend): bound streaming markdown renders * perf(frontend): virtualize message history * perf(frontend): bound and virtualize chat lists * perf(frontend): suspend inactive decorative animation * perf(browser): stream latest frames as binary * perf(artifacts): stream bounded text previews * docs: finalize performance runtime boundaries * style(backend): apply test formatting * fix(frontend): keep translation functions client-side * perf(frontend): defer decorative animation bundles * test(frontend): lock optimized route budgets * fix: harden frontend performance boundaries * test(frontend): update i18n provider fixture * fix(frontend): preserve sidebar pagination position * style(backend): format artifact range test
58 lines
2.0 KiB
TypeScript
58 lines
2.0 KiB
TypeScript
import { beforeEach, describe, expect, it, rs } from "@rstest/core";
|
|
|
|
const codeToHtml = rs.fn(async () => '<pre class="shiki">code</pre>');
|
|
rs.mock("shiki", () => ({ codeToHtml }));
|
|
|
|
describe("highlightCode", () => {
|
|
beforeEach(async () => {
|
|
codeToHtml.mockClear();
|
|
const { clearHighlightCacheForTests } =
|
|
await import("@/components/ai-elements/shiki-highlight");
|
|
clearHighlightCacheForTests();
|
|
});
|
|
|
|
it("creates one dual-theme highlighted tree", async () => {
|
|
const { highlightCode } =
|
|
await import("@/components/ai-elements/shiki-highlight");
|
|
|
|
expect(await highlightCode("const n = 1", "typescript", true)).toContain(
|
|
'class="shiki"',
|
|
);
|
|
expect(codeToHtml).toHaveBeenCalledTimes(1);
|
|
expect(codeToHtml).toHaveBeenCalledWith(
|
|
"const n = 1",
|
|
expect.objectContaining({
|
|
themes: { light: "one-light", dark: "one-dark-pro" },
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("reuses results and evicts the least recently used entry at the bound", async () => {
|
|
const { HIGHLIGHT_CACHE_LIMIT, highlightCode } =
|
|
await import("@/components/ai-elements/shiki-highlight");
|
|
|
|
await highlightCode("first", "typescript");
|
|
await highlightCode("first", "typescript");
|
|
expect(codeToHtml).toHaveBeenCalledTimes(1);
|
|
|
|
for (let index = 1; index <= HIGHLIGHT_CACHE_LIMIT; index += 1) {
|
|
await highlightCode(`code-${index}`, "typescript");
|
|
}
|
|
expect(codeToHtml).toHaveBeenCalledTimes(HIGHLIGHT_CACHE_LIMIT + 1);
|
|
|
|
await highlightCode("first", "typescript");
|
|
expect(codeToHtml).toHaveBeenCalledTimes(HIGHLIGHT_CACHE_LIMIT + 2);
|
|
});
|
|
|
|
it("does not retain oversized source strings in the highlight cache", async () => {
|
|
const { HIGHLIGHT_CACHE_MAX_CODE_LENGTH, highlightCode } =
|
|
await import("@/components/ai-elements/shiki-highlight");
|
|
const oversizedCode = "x".repeat(HIGHLIGHT_CACHE_MAX_CODE_LENGTH + 1);
|
|
|
|
await highlightCode(oversizedCode, "typescript");
|
|
await highlightCode(oversizedCode, "typescript");
|
|
|
|
expect(codeToHtml).toHaveBeenCalledTimes(2);
|
|
});
|
|
});
|