appQuickPickCommandStability.test.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { readFileSync } from "node:fs";
  2. import { describe, expect, it } from "vitest";
  3. function readAppSource(): string {
  4. return readFileSync(new URL("../src/App.tsx", import.meta.url), "utf8");
  5. }
  6. function getQuickPickCommandsMemoBlock(source: string): string {
  7. const start = source.indexOf("const quickPickCommands = useMemo");
  8. const end = source.indexOf(" );", start);
  9. expect(start).toBeGreaterThanOrEqual(0);
  10. expect(end).toBeGreaterThan(start);
  11. return source.slice(start, end);
  12. }
  13. describe("App quick pick command render stability", () => {
  14. it("does not recreate quick pick commands when only the user object reference changes", () => {
  15. const memoBlock = getQuickPickCommandsMemoBlock(readAppSource());
  16. // 性能回归保护:commands 会一路传给 CommandCenterDialog。
  17. // 这里只需要登录态布尔值,不应订阅完整 user 对象引用。
  18. expect(memoBlock).toContain("isLoggedIn");
  19. expect(memoBlock).not.toMatch(/\n\s+user,\n/);
  20. });
  21. it("memoizes task find dialog props before passing them to the shell layout", () => {
  22. const source = readAppSource();
  23. // 性能回归保护:taskFindDialogProps 是对象 prop,内联创建会让 WorkspaceShellLayout
  24. // 在无关流式刷新中看到新引用并继续向下重渲染。
  25. expect(source).toContain("const taskFindDialogProps = useMemo<TaskFindDialogProps>");
  26. expect(source).toContain("taskFindDialogProps={taskFindDialogProps}");
  27. });
  28. });