Fix refresh plugin
Lint / lint (push) Failing after 39s

This commit is contained in:
Julien Valverdé
2026-07-25 22:27:11 +02:00
parent 462895a3c2
commit 23547afe91
6 changed files with 119 additions and 69 deletions
@@ -1,10 +1,11 @@
import { describe, expect, it, vi } from "vitest"
import type * as Component from "../src/Component.js"
import * as Refreshable from "../src/Refreshable.js"
describe("Refreshable", () => {
it("attaches a cell and notifies subscribers after a compatible update", async () => {
const first = {}
const first = {} as Component.Component.Any
const cell = Refreshable.makeCell(first, "hooks", false)
const listener = vi.fn()
@@ -13,9 +14,11 @@ describe("Refreshable", () => {
expect(attached).toBe(first)
expect(Refreshable.isRefreshable(first)).toBe(true)
expect(attached[Refreshable.RefreshableTypeId]).toBe(cell)
expect(Object.getPrototypeOf(attached).asFunctionComponent)
.toBe(Refreshable.RefreshablePrototype.asFunctionComponent)
cell.subscribe(listener)
const second = {}
const second = {} as Component.Component.Any
cell.update(second, "hooks", false)
expect(cell.current).toBe(second)
@@ -29,12 +32,29 @@ describe("Refreshable", () => {
})
it("requests a remount when a signature changes or reset is forced", () => {
const cell = Refreshable.makeCell({}, "one", false)
const component = {} as Component.Component.Any
const cell = Refreshable.makeCell(component, "one", false)
cell.update({}, "two", false)
cell.update({} as Component.Component.Any, "two", false)
expect(cell.snapshot.resetRevision).toBe(1)
cell.update({}, "two", true)
cell.update({} as Component.Component.Any, "two", true)
expect(cell.snapshot.resetRevision).toBe(2)
})
it("builds the refresh shell from the current descriptor implementation", () => {
const implementation = () => null
const makeFunctionComponent = vi.fn(() => implementation)
const component = {
makeFunctionComponent,
} as unknown as Component.ComponentImpl.Any
const contextRef = {
current: {},
} as never
const cell = Refreshable.makeCell(component, "hooks", false)
const attached = Refreshable.attach(component, cell)
expect(attached.asFunctionComponent(contextRef)).not.toBe(implementation)
expect(makeFunctionComponent).toHaveBeenCalledWith(contextRef)
})
})