From 07e0251659bdb3056c3edd9cbb1ae8530f57423a Mon Sep 17 00:00:00 2001 From: Wassim SAMAD Date: Tue, 22 Sep 2026 14:27:52 -0400 Subject: [PATCH] test(core): stop the draft attachment snapshot leaning on a leaked rAF `updateNode` batches its dirty-node flush through `requestAnimationFrame`, which bun's test runtime has no DOM to supply. Seven other core tests that reach this path stub it; this one did not, and passed only when bun happened to run one of them first and leak the global. On a runner that ordered the files differently it failed with a bare ReferenceError, and running the file on its own failed every time. Stubs rAF for the duration of the test and restores it in the existing finally, matching how the neighbouring store tests do it. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01Jmmz2AMwTzcnKsSHHPEMhN --- .../core/src/store/draft-attachment-snapshot.test.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/core/src/store/draft-attachment-snapshot.test.ts b/packages/core/src/store/draft-attachment-snapshot.test.ts index 7a808dbc95..7476cce6ed 100644 --- a/packages/core/src/store/draft-attachment-snapshot.test.ts +++ b/packages/core/src/store/draft-attachment-snapshot.test.ts @@ -39,6 +39,15 @@ test('draft snapshots do not enumerate unaffected procedural attachment maps', ( ] }), ]) as Record + // `updateNode` batches its dirty-node flush through rAF, which bun's test + // runtime has no DOM to supply. Every other core test that reaches this path + // stubs it; this one used to pass only when one of them happened to run first + // and leak the global, so on a runner that ordered the files differently it + // failed with a bare ReferenceError. + const savedRaf = globalThis.requestAnimationFrame + const savedCancelRaf = globalThis.cancelAnimationFrame + globalThis.requestAnimationFrame = (() => 0) as typeof requestAnimationFrame + globalThis.cancelAnimationFrame = (() => {}) as typeof cancelAnimationFrame const stop = subscribeSceneCommits((commit) => { expect(commit.current.nodes[draft.id]).toBeUndefined() expect((commit.current.nodes['procedural-item_0'] as ProceduralItemNode).attachments).toBe( @@ -68,5 +77,7 @@ test('draft snapshots do not enumerate unaffected procedural attachment maps', ( useScene.setState(saved) useScene.temporal.getState().clear() useScene.temporal.getState().resume() + globalThis.requestAnimationFrame = savedRaf + globalThis.cancelAnimationFrame = savedCancelRaf } })