runtime.test.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { expect, test } from "bun:test"
  2. import { createPluginRuntime } from "../../src/plugin/runtime"
  3. test("routes use the latest registration and restore previous registrations", () => {
  4. const runtime = createPluginRuntime()
  5. const first = () => "first"
  6. const second = () => "second"
  7. runtime.routes.register([{ name: "demo", render: first }])
  8. const dispose = runtime.routes.register([{ name: "demo", render: second }])
  9. expect(runtime.routes.get("demo")).toBe(second)
  10. dispose()
  11. expect(runtime.routes.get("demo")).toBe(first)
  12. })
  13. test("facade publishes and clears presentation state", async () => {
  14. const runtime = createPluginRuntime()
  15. runtime.update({
  16. commands: {
  17. async activate() {
  18. return true
  19. },
  20. async deactivate() {
  21. return true
  22. },
  23. async add() {
  24. return true
  25. },
  26. async install() {
  27. return { ok: true, dir: "/tmp", tui: true }
  28. },
  29. },
  30. status: [
  31. {
  32. id: "demo",
  33. source: "internal",
  34. spec: "demo",
  35. target: "demo",
  36. enabled: true,
  37. active: true,
  38. },
  39. ],
  40. })
  41. expect(await runtime.commands().activate("demo")).toBe(true)
  42. expect(runtime.status()).toHaveLength(1)
  43. runtime.clear()
  44. expect(await runtime.commands().activate("demo")).toBe(false)
  45. expect(runtime.status()).toEqual([])
  46. })