Compare commits

...

1 Commits

Author SHA1 Message Date
Claude Bot
bbbc832b1c fix(test): drain straggler HMR messages in rapid edits test
The "hmr handles rapid consecutive edits" test was flaky on Windows
because filesystem watcher batching can cause duplicate reloads for a
single file write. When the test loop broke after seeing "render 10",
a duplicate "render 10" message could arrive before the client was
disposed, causing the destructor to throw on unread messages.

Fix by draining any remaining in-flight messages after seeing the
final render, preventing the client destructor from failing on
harmless duplicate reload messages.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-11 20:04:34 +00:00

View File

@@ -260,13 +260,29 @@ devTest("hmr handles rapid consecutive edits", {
await Bun.sleep(1);
}
// Wait for the final render message event-driven. Due to filesystem watcher
// batching, a single write can trigger multiple reloads, so we may receive
// duplicate "render 10" messages. Drain all messages until we see the final
// render message and then drain any stragglers.
const finalRender = "render 10";
let sawFinal = false;
while (true) {
const message = await client.getStringMessage();
if (message === finalRender) break;
if (typeof message === "string" && message.includes("HMR_ERROR")) {
throw new Error("Unexpected HMR error message: " + message);
}
if (message === finalRender) {
sawFinal = true;
break;
}
}
// Drain any remaining in-flight messages (e.g. duplicate reloads) so
// the client destructor doesn't throw on unread messages.
if (sawFinal) {
// Give a small window for any in-flight messages to arrive.
await Bun.sleep(100);
client.messages.length = 0;
}
const hmrErrors = await client.js`return globalThis.__hmrErrors ? [...globalThis.__hmrErrors] : [];`;