@@ -1,21 +1,25 @@
|
||||
import type * as Component from "effect-fc-next/Component"
|
||||
import * as Refreshable from "effect-fc-next/Refreshable"
|
||||
import { describe, expect, it, vi } from "vitest"
|
||||
import { accept, register } from "../src/runtime.js"
|
||||
|
||||
|
||||
describe("refresh runtime", () => {
|
||||
const component = <A extends object>(value: A): A & Component.Component.Any =>
|
||||
value as A & Component.Component.Any
|
||||
|
||||
it("retains a cell and notifies subscribers for compatible updates", async () => {
|
||||
const hot = {
|
||||
data: {},
|
||||
accept: vi.fn(),
|
||||
invalidate: vi.fn(),
|
||||
}
|
||||
const first = register({ body: "first" }, hot, "module:View", "hooks")
|
||||
const first = register(component({ body: "first" }), hot, "module:View", "hooks")
|
||||
const cell = (first as Record<PropertyKey, unknown>)[Refreshable.RefreshableTypeId] as Refreshable.Cell
|
||||
const listener = vi.fn()
|
||||
cell.subscribe(listener)
|
||||
|
||||
const second = register({ body: "second" }, hot, "module:View", "hooks")
|
||||
const second = register(component({ body: "second" }), hot, "module:View", "hooks")
|
||||
const secondCell = (second as Record<PropertyKey, unknown>)[Refreshable.RefreshableTypeId]
|
||||
|
||||
expect(secondCell).toBe(cell)
|
||||
@@ -35,20 +39,20 @@ describe("refresh runtime", () => {
|
||||
accept: vi.fn(),
|
||||
invalidate: vi.fn(),
|
||||
}
|
||||
const first = register({}, hot, "module:View", "one")
|
||||
const first = register(component({}), hot, "module:View", "one")
|
||||
const cell = (first as Record<PropertyKey, unknown>)[Refreshable.RefreshableTypeId] as Refreshable.Cell
|
||||
|
||||
register({}, hot, "module:View", "two")
|
||||
register(component({}), hot, "module:View", "two")
|
||||
expect(cell.snapshot.resetRevision).toBe(1)
|
||||
|
||||
register({}, hot, "module:View", "two", true)
|
||||
register(component({}), hot, "module:View", "two", true)
|
||||
expect(cell.snapshot.resetRevision).toBe(2)
|
||||
})
|
||||
|
||||
it("is inert outside a Vite hot context", () => {
|
||||
const component = {}
|
||||
expect(register(component, undefined, "module:View", "hooks")).toBe(component)
|
||||
expect((component as Record<PropertyKey, unknown>)[Refreshable.RefreshableTypeId]).toBeUndefined()
|
||||
const descriptor = component({})
|
||||
expect(register(descriptor, undefined, "module:View", "hooks")).toBe(descriptor)
|
||||
expect((descriptor as Record<PropertyKey, unknown>)[Refreshable.RefreshableTypeId]).toBeUndefined()
|
||||
})
|
||||
|
||||
it("invalidates when the module's View IDs change", () => {
|
||||
|
||||
Reference in New Issue
Block a user