docs(tests): clarify legacy canvas DOM scenario coverage
This commit is contained in:
@@ -19,7 +19,7 @@ const { build, stop } = tools("esbuild");
|
||||
// 独立 DOM 和 localhost origin 提供 localStorage 等环境,不请求 localhost 服务。
|
||||
const dom = new JSDOM('<!doctype html><html><body><div id="app"></div></body></html>', { url: "http://localhost", pretendToBeVisual: true });
|
||||
const { window } = dom;
|
||||
// React's async act creates MessageChannels; track and close test-owned ports.
|
||||
// 记录此进程后来创建的 MessageChannel;React 异步 act 可持有这些端口,最终关闭以免测试进程悬挂。
|
||||
const NativeMessageChannel = globalThis.MessageChannel;
|
||||
const channels = [];
|
||||
globalThis.MessageChannel = class extends NativeMessageChannel { constructor() { super(); channels.push(this); } };
|
||||
@@ -109,7 +109,8 @@ try {
|
||||
let calls = 0, controls, renders = 0;
|
||||
apiMock = async () => { calls++; return Response.json({ runs: [] }); };
|
||||
const tree = { busy: false, writers: { current: new Map() } };
|
||||
// 挂载 AI hook 并计数渲染,检查空结果轮询既不重复请求也不造成额外渲染。
|
||||
// 挂载 AI hook 并计数 Probe 函数调用,检查截止时间前触发的空闲回调不请求也不增加调用次数。
|
||||
// 这是函数执行计数,不是 React DOM commit 次数;未推进墙上时间便手动触发 timer,验证的是 deadline 门禁。
|
||||
function Probe() { renders++; controls = useCanvasAI("w", "root", true, tree); return null; }
|
||||
try {
|
||||
await act(async () => { root.render(h(Probe)); await tick(); });
|
||||
@@ -257,7 +258,8 @@ try {
|
||||
const { feedbackScenario } = await import("./feedback-scenario.mjs");
|
||||
await feedbackScenario({ root, act, h, AppFeedback, IconButton, notify, dismissNotification, GraphCanvas, window, makeCanvasNode, emptyCanvas, event, tick });
|
||||
await act(async () => { root.unmount(); await tick(); });
|
||||
// 清理临时打包文件、JSDOM、esbuild 及 act 创建的 MessageChannel 端口,恢复原通道构造器。
|
||||
// 断言失败也会进入以下清理;root.unmount 只在正常路径执行,finally 仍关闭 JSDOM、esbuild 和记录到的通道。
|
||||
// 清理临时打包文件并恢复原通道构造器,不逐项恢复仅供此独立进程使用的 DOM 全局替身。
|
||||
} finally {
|
||||
await rm(folder, { recursive: true, force: true }); window.close(); stop();
|
||||
for (const channel of channels) { channel.port1.close(); channel.port2.close(); }
|
||||
|
||||
Reference in New Issue
Block a user