From 5e54e5742d3256568be2bcfc10e3248c793bd261 Mon Sep 17 00:00:00 2001 From: Yunfei He Date: Mon, 25 May 2026 23:28:06 +0800 Subject: [PATCH] refactor: replace ref() with shallowRef() in all test files AGENTS.md requires shallowRef by default. All test state uses reassignment (not mutation), so shallowRef is correct. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../integration/components/box.test.tsx | 4 ++-- .../integration/components/conditional-list.test.tsx | 8 ++++---- .../integration/components/static.test.tsx | 12 ++++++------ .../integration/composables/use-input.test.tsx | 6 +++--- packages/runtime-tests/integration/counter.test.tsx | 4 ++-- .../integration/focus/programmatic-focus.test.tsx | 8 ++++---- .../integration/focus/raw-mode-swap.test.tsx | 4 ++-- .../integration/lifecycle/error-handling.test.tsx | 4 ++-- .../integration/lifecycle/leak.test.tsx | 4 ++-- .../runtime-tests/integration/quickstart.test.tsx | 4 ++-- .../runtime-tests/integration/scheduler.test.tsx | 6 +++--- packages/testing/tests/render.test.tsx | 4 ++-- 12 files changed, 34 insertions(+), 34 deletions(-) diff --git a/packages/runtime-tests/integration/components/box.test.tsx b/packages/runtime-tests/integration/components/box.test.tsx index eeb1c70..7489106 100644 --- a/packages/runtime-tests/integration/components/box.test.tsx +++ b/packages/runtime-tests/integration/components/box.test.tsx @@ -1,4 +1,4 @@ -import { defineComponent, nextTick, ref } from "vue"; +import { defineComponent, nextTick, shallowRef } from "vue"; import { expect, test } from "vite-plus/test"; import { render } from "@vue-tui/testing"; import { Box, Text } from "@vue-tui/runtime"; @@ -41,7 +41,7 @@ test("borderBottom:false suppresses bottom edge", async () => { }); test("reactive borderTop:false update removes top edge", async () => { - const showTop = ref(true); + const showTop = shallowRef(true); const App = defineComponent(() => { return () => ; }); diff --git a/packages/runtime-tests/integration/components/conditional-list.test.tsx b/packages/runtime-tests/integration/components/conditional-list.test.tsx index 3db40e2..d6f01f5 100644 --- a/packages/runtime-tests/integration/components/conditional-list.test.tsx +++ b/packages/runtime-tests/integration/components/conditional-list.test.tsx @@ -1,10 +1,10 @@ -import { defineComponent, nextTick, ref } from "vue"; +import { defineComponent, nextTick, shallowRef } from "vue"; import { expect, test } from "vite-plus/test"; import { render } from "@vue-tui/testing"; import { Box, Text } from "@vue-tui/runtime"; test("v-if toggle preserves sibling order", async () => { - const show = ref(true); + const show = shallowRef(true); const App = defineComponent(() => { return () => ( @@ -37,7 +37,7 @@ test("v-if toggle preserves sibling order", async () => { }); test("keyed v-for reorder renders in new order", async () => { - const items = ref([1, 2, 3]); + const items = shallowRef([1, 2, 3]); const App = defineComponent(() => { return () => ( @@ -63,7 +63,7 @@ test("keyed v-for reorder renders in new order", async () => { }); test("repeated list shuffles don't crash", async () => { - const items = ref([1, 2, 3, 4, 5]); + const items = shallowRef([1, 2, 3, 4, 5]); const App = defineComponent(() => { return () => ( diff --git a/packages/runtime-tests/integration/components/static.test.tsx b/packages/runtime-tests/integration/components/static.test.tsx index f0e420b..c8bcb69 100644 --- a/packages/runtime-tests/integration/components/static.test.tsx +++ b/packages/runtime-tests/integration/components/static.test.tsx @@ -1,11 +1,11 @@ import { PassThrough } from "node:stream"; -import { defineComponent, nextTick, ref } from "vue"; +import { defineComponent, nextTick, shallowRef } from "vue"; import { expect, test } from "vite-plus/test"; import { render } from "@vue-tui/testing"; import { Box, Text, Static, createApp } from "@vue-tui/runtime"; test("Static appends new items above the dynamic frame", async () => { - const items = ref([]); + const items = shallowRef([]); const App = defineComponent(() => { return () => ( @@ -34,8 +34,8 @@ test("Static appends new items above the dynamic frame", async () => { }); test("Static preserves prior items when new ones are added", async () => { - const logs = ref([]); - const status = ref("idle"); + const logs = shallowRef([]); + const status = shallowRef("idle"); const App = defineComponent(() => { return () => ( @@ -89,7 +89,7 @@ test("Static flush clears the dynamic frame first (non-debug mode)", async () => }, }); - const items = ref([]); + const items = shallowRef([]); const App = defineComponent(() => () => ( @@ -177,7 +177,7 @@ test.todo( ); test("Static items do not add blank lines to the dynamic frame", async () => { - const items = ref([]); + const items = shallowRef([]); const App = defineComponent(() => () => ( diff --git a/packages/runtime-tests/integration/composables/use-input.test.tsx b/packages/runtime-tests/integration/composables/use-input.test.tsx index b673b97..d9c43e5 100644 --- a/packages/runtime-tests/integration/composables/use-input.test.tsx +++ b/packages/runtime-tests/integration/composables/use-input.test.tsx @@ -1,4 +1,4 @@ -import { defineComponent, ref } from "vue"; +import { defineComponent, shallowRef } from "vue"; import { expect, test } from "vite-plus/test"; import { render } from "@vue-tui/testing"; import { Text, useInput, useStdout, type Key } from "@vue-tui/runtime"; @@ -29,7 +29,7 @@ test("useInput receives arrow keys", async () => { test("useInput respects isActive ref", async () => { const calls: string[] = []; - const active = ref(false); + const active = shallowRef(false); const App = defineComponent(() => { useInput((input) => calls.push(input), { isActive: active }); return () => x; @@ -192,7 +192,7 @@ test("useInput - ignore input if not active (isActive: false)", async () => { test("useInput - ignore input if not active (isActive ref toggled)", async () => { const calls: string[] = []; - const active = ref(false); + const active = shallowRef(false); const App = defineComponent(() => { useInput((input) => calls.push(input), { isActive: active }); return () => x; diff --git a/packages/runtime-tests/integration/counter.test.tsx b/packages/runtime-tests/integration/counter.test.tsx index 76c6aee..1a0b3d8 100644 --- a/packages/runtime-tests/integration/counter.test.tsx +++ b/packages/runtime-tests/integration/counter.test.tsx @@ -1,11 +1,11 @@ -import { defineComponent, ref } from "vue"; +import { defineComponent, shallowRef } from "vue"; import { expect, test } from "vite-plus/test"; import { render } from "@vue-tui/testing"; import { Box, Text, useInput } from "@vue-tui/runtime"; test("counter responds to + and - keys", async () => { const Counter = defineComponent(() => { - const count = ref(0); + const count = shallowRef(0); useInput((input) => { if (input === "+") count.value++; if (input === "-") count.value--; diff --git a/packages/runtime-tests/integration/focus/programmatic-focus.test.tsx b/packages/runtime-tests/integration/focus/programmatic-focus.test.tsx index b7eb971..1e532b4 100644 --- a/packages/runtime-tests/integration/focus/programmatic-focus.test.tsx +++ b/packages/runtime-tests/integration/focus/programmatic-focus.test.tsx @@ -1,4 +1,4 @@ -import { defineComponent, nextTick, ref, shallowRef } from "vue"; +import { defineComponent, nextTick, shallowRef } from "vue"; import { expect, test } from "vite-plus/test"; import { render } from "@vue-tui/testing"; import { Box, Text, useFocus, useFocusManager } from "@vue-tui/runtime"; @@ -41,7 +41,7 @@ test("focus(id) programmatically focuses another component", async () => { }); test("isActive=false prevents component from receiving focus", async () => { - const active = ref(false); + const active = shallowRef(false); const Item = defineComponent({ props: { id: { type: String, required: true } }, @@ -76,7 +76,7 @@ test("isActive=false prevents component from receiving focus", async () => { }); test("autoFocus + isActive=false does not focus at mount", async () => { - const active = ref(false); + const active = shallowRef(false); const App = defineComponent(() => { const { isFocused } = useFocus({ id: "item", autoFocus: true, isActive: active }); @@ -93,7 +93,7 @@ test("autoFocus + isActive=false does not focus at mount", async () => { }); test("flipping isActive to false on focused item blurs it", async () => { - const active = ref(true); + const active = shallowRef(true); const App = defineComponent(() => { const { isFocused } = useFocus({ id: "item", autoFocus: true, isActive: active }); diff --git a/packages/runtime-tests/integration/focus/raw-mode-swap.test.tsx b/packages/runtime-tests/integration/focus/raw-mode-swap.test.tsx index 9a7001e..f179e09 100644 --- a/packages/runtime-tests/integration/focus/raw-mode-swap.test.tsx +++ b/packages/runtime-tests/integration/focus/raw-mode-swap.test.tsx @@ -1,10 +1,10 @@ -import { defineComponent, nextTick, ref } from "vue"; +import { defineComponent, nextTick, shallowRef } from "vue"; import { expect, test } from "vite-plus/test"; import { render } from "@vue-tui/testing"; import { Text, useFocus } from "@vue-tui/runtime"; test("swapping focusable components never disables raw mode", async () => { - const showA = ref(true); + const showA = shallowRef(true); const Item = defineComponent(() => { useFocus(); diff --git a/packages/runtime-tests/integration/lifecycle/error-handling.test.tsx b/packages/runtime-tests/integration/lifecycle/error-handling.test.tsx index 73ebcfe..ea00065 100644 --- a/packages/runtime-tests/integration/lifecycle/error-handling.test.tsx +++ b/packages/runtime-tests/integration/lifecycle/error-handling.test.tsx @@ -1,4 +1,4 @@ -import { defineComponent, nextTick, ref } from "vue"; +import { defineComponent, nextTick, shallowRef } from "vue"; import { expect, test } from "vite-plus/test"; import { render } from "@vue-tui/testing"; import { Text, useExit } from "@vue-tui/runtime"; @@ -11,7 +11,7 @@ test("setup() throw rejects render()", async () => { }); test("render-time throw does not prevent unmount", async () => { - const trigger = ref(false); + const trigger = shallowRef(false); const App = defineComponent(() => { return () => { if (trigger.value) throw new Error("render boom"); diff --git a/packages/runtime-tests/integration/lifecycle/leak.test.tsx b/packages/runtime-tests/integration/lifecycle/leak.test.tsx index 7ada70e..1386a43 100644 --- a/packages/runtime-tests/integration/lifecycle/leak.test.tsx +++ b/packages/runtime-tests/integration/lifecycle/leak.test.tsx @@ -1,4 +1,4 @@ -import { defineComponent, nextTick, ref } from "vue"; +import { defineComponent, nextTick, shallowRef } from "vue"; import { expect, test } from "vite-plus/test"; import { render } from "@vue-tui/testing"; import { Box, Text, useInput } from "@vue-tui/runtime"; @@ -33,7 +33,7 @@ test("100 render/unmount cycles leak zero yoga nodes", async () => { }); test("raw mode stays on when one of two useInput components unmounts", async () => { - const showB = ref(true); + const showB = shallowRef(true); const Listener = defineComponent(() => { useInput(() => {}); diff --git a/packages/runtime-tests/integration/quickstart.test.tsx b/packages/runtime-tests/integration/quickstart.test.tsx index 4c39965..15308b1 100644 --- a/packages/runtime-tests/integration/quickstart.test.tsx +++ b/packages/runtime-tests/integration/quickstart.test.tsx @@ -1,11 +1,11 @@ -import { defineComponent, ref } from "vue"; +import { defineComponent, shallowRef } from "vue"; import { expect, test } from "vite-plus/test"; import { render } from "@vue-tui/testing"; import { Box, Text, useInput } from "@vue-tui/runtime"; test("README quickstart code runs to a Count: 0 frame", async () => { const Counter = defineComponent(() => { - const count = ref(0); + const count = shallowRef(0); useInput((input) => { if (input === "+") count.value++; if (input === "-") count.value--; diff --git a/packages/runtime-tests/integration/scheduler.test.tsx b/packages/runtime-tests/integration/scheduler.test.tsx index 9a6ec63..75222d4 100644 --- a/packages/runtime-tests/integration/scheduler.test.tsx +++ b/packages/runtime-tests/integration/scheduler.test.tsx @@ -1,10 +1,10 @@ -import { defineComponent, nextTick, ref, watch } from "vue"; +import { defineComponent, nextTick, shallowRef, watch } from "vue"; import { expect, test } from "vite-plus/test"; import { render } from "@vue-tui/testing"; import { Box, Text } from "@vue-tui/runtime"; test("multiple mutations in one tick produce at most 1 new frame", async () => { - const count = ref(0); + const count = shallowRef(0); const App = defineComponent(() => { return () => {String(count.value)}; }); @@ -23,7 +23,7 @@ test("multiple mutations in one tick produce at most 1 new frame", async () => { }); test("post-flush watch sees the same value the commit paints", async () => { - const count = ref(0); + const count = shallowRef(0); let observed = 0; const App = defineComponent(() => { diff --git a/packages/testing/tests/render.test.tsx b/packages/testing/tests/render.test.tsx index 53f006d..ecbee0e 100644 --- a/packages/testing/tests/render.test.tsx +++ b/packages/testing/tests/render.test.tsx @@ -1,4 +1,4 @@ -import { nextTick, ref } from "vue"; +import { nextTick, shallowRef } from "vue"; import { expect, test } from "vite-plus/test"; import { render } from "../src/index.ts"; import { Text } from "@vue-tui/runtime"; @@ -9,7 +9,7 @@ test("lastFrame captures rendered output", async () => { }); test("frames accumulate on reactive updates", async () => { - const message = ref("first"); + const message = shallowRef("first"); const { lastFrame, frames } = await render(() => {message.value}); const initialCount = frames.length; expect(lastFrame()).toContain("first");