diff --git a/packages/app/package.json b/packages/app/package.json index 08fe999299d0f..80b0c5ac563fb 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -20,9 +20,9 @@ "build": "vite build", "serve": "vite preview", "test": "bun run test:unit && bun run test:browser", - "test:unit": "bun test --conditions=solid --only-failures --isolate --preload ../ui/test/solid-jsx.ts --preload ./happydom.ts ./src", + "test:unit": "bun test --conditions=browser --only-failures --isolate --preload ../ui/test/solid-jsx.ts --preload ./happydom.ts ./src", "test:browser": "bun test --conditions=browser --isolate --preload ../ui/test/solid-jsx.ts --preload ./happydom.ts ./test-browser", - "test:unit:watch": "bun test --conditions=solid --watch --isolate --preload ../ui/test/solid-jsx.ts --preload ./happydom.ts ./src", + "test:unit:watch": "bun test --conditions=browser --watch --isolate --preload ../ui/test/solid-jsx.ts --preload ./happydom.ts ./src", "test:e2e": "playwright test", "test:e2e:built": "PLAYWRIGHT_BUILD=1 playwright test", "test:e2e:local": "playwright test", diff --git a/packages/app/src/composer/editor/actions.test.ts b/packages/app/src/composer/editor/actions.test.ts index 09fb2920468be..4041942788c74 100644 --- a/packages/app/src/composer/editor/actions.test.ts +++ b/packages/app/src/composer/editor/actions.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test } from "bun:test" -import { createStore } from "solid-js/store" +import { createStore, unwrap } from "solid-js/store" import { Skill } from "@opencode/schema/skill" import type { ComposerPersistedState } from "../types" import { createComposerEditorActions } from "./actions" @@ -123,7 +123,7 @@ describe("Composer store", () => { }, { start: 0, end: 0 }, ) - expect(prompt.state.prompt).toMatchObject([ + expect(unwrap(prompt.state.prompt)).toMatchObject([ { type: "skill", id: "show-me", content: "@show-me", start: 0, end: 8 }, { type: "text", content: " ", start: 8, end: 9 }, { type: "file", path: "one", content: "@one", start: 9, end: 13 }, diff --git a/packages/app/src/composer/submit.test.ts b/packages/app/src/composer/submit.test.ts index 7e41e28cac443..0ebaae6d0cef7 100644 --- a/packages/app/src/composer/submit.test.ts +++ b/packages/app/src/composer/submit.test.ts @@ -1,4 +1,5 @@ import { describe, expect, jest, test } from "bun:test" +import { unwrap } from "solid-js/store" import type { ModelSelection } from "@/providers/models/selection" import type { SessionMessageHandoff } from "@/session/handoff" import { Skill } from "@opencode/schema/skill" @@ -376,7 +377,7 @@ describe("Composer submission", () => { expect(await pending).toBe(false) expect(errors).toHaveLength(1) expect(state.current()).toEqual([{ type: "text", content: "Keep this draft", start: 0, end: 15 }]) - expect(state.context.items()).toMatchObject([ + expect(unwrap(state.context.items())).toMatchObject([ { key: "quote:c=selected", text: "Selected passage", comment: "Latest comment" }, ]) expect(calls.filter((call) => call === "send")).toHaveLength(2) @@ -927,7 +928,7 @@ describe("Composer submission", () => { expect(statuses).toEqual(["running", "idle", "running", "idle"]) expect(state.current()).toEqual(prompt) // In the order it was sent, so the resend's request matches the first. - expect(state.context.items()).toMatchObject([ + expect(unwrap(state.context.items())).toMatchObject([ { type: "file", path: "notes.md", description: "the failing version" }, note, ]) @@ -967,8 +968,8 @@ describe("Composer submission", () => { ).submit(new Event("submit")) await failed.promise - expect(promoted.current()).toMatchObject([{ type: "text", content: "first prompt" }]) - expect(promoted.context.items()).toMatchObject([{ type: "file", path: "src/app.ts", comment: "Keep this comment" }]) + expect(unwrap(promoted.current())).toMatchObject([{ type: "text", content: "first prompt" }]) + expect(unwrap(promoted.context.items())).toMatchObject([{ type: "file", path: "src/app.ts", comment: "Keep this comment" }]) expect(promoted.mode.current()).toBe("shell") }) @@ -1009,7 +1010,7 @@ describe("Composer submission", () => { await failed.promise expect(text(promoted)).toBe("first prompt\n\nfollow-up") - expect(promoted.context.items()).toMatchObject([{ key, type: "quote", text: "quoted passage" }]) + expect(unwrap(promoted.context.items())).toMatchObject([{ key, type: "quote", text: "quoted passage" }]) expect(promoted.quoteSource.state.sources[key]).toEqual(source) // A recovered follow-up changes the payload, so it is not a retry of the failed admission. expect(promoted.retry.current()).toBeUndefined() diff --git a/packages/app/src/solid-build.test.ts b/packages/app/src/solid-build.test.ts new file mode 100644 index 0000000000000..d87ecce5c8db4 --- /dev/null +++ b/packages/app/src/solid-build.test.ts @@ -0,0 +1,17 @@ +import { expect, test } from "bun:test" +import { createMemo, createRoot, createSignal } from "solid-js" + +// The unit runner has to load solid-js's client build. `--conditions=solid` matches no export in solid-js, so bun +// resolves `node` and loads `dist/server.js`, where memos and effects never re-run: a reactive test then proves +// nothing. This fails on that build and passes on the client one. +test("memos update in the unit runner", () => { + createRoot((dispose) => { + const [value, setValue] = createSignal(1) + const double = createMemo(() => value() * 2) + + expect(double()).toBe(2) + setValue(2) + expect(double()).toBe(4) + dispose() + }) +})