Fix tests
Lint / lint (push) Failing after 39s

This commit is contained in:
Julien Valverdé
2026-07-25 23:52:11 +02:00
parent 65e90325d0
commit 73399c1b24
2 changed files with 18 additions and 6 deletions
+8 -2
View File
@@ -1,9 +1,15 @@
import path from "node:path"
import type { Plugin, TransformPluginContext } from "vite"
import type { Plugin } from "vite"
import { describe, expect, it } from "vitest"
import { effectViewPlugin } from "./index.js"
type TransformHook = Extract<
NonNullable<Plugin["transform"]>,
(...args: never[]) => unknown
>
type TransformPluginContext = ThisParameterType<TransformHook>
const runTransform = async (
plugin: Plugin,
code: string,
@@ -19,7 +25,7 @@ const runTransform = async (
if (!result)
return undefined
return typeof result === "string" ? result : result.code
return typeof result === "string" ? result : result.code?.toString()
}
const transform = (
+10 -4
View File
@@ -8,6 +8,12 @@ describe("refresh runtime", () => {
const component = <A extends object>(value: A): A & Component.Component.Any =>
value as A & Component.Component.Any
const refreshCell = (value: Component.Component.Any): Refreshable.Cell => {
if (!Refreshable.isRefreshable(value))
throw new Error("Expected a refreshable component")
return value[Refreshable.RefreshableTypeId]
}
it("retains a cell and notifies subscribers for compatible updates", async () => {
const hot = {
data: {},
@@ -15,12 +21,12 @@ describe("refresh runtime", () => {
invalidate: vi.fn(),
}
const first = register(component({ body: "first" }), hot, "module:View", "hooks")
const cell = (first as Record<PropertyKey, unknown>)[Refreshable.RefreshableTypeId] as Refreshable.Cell
const cell = refreshCell(first)
const listener = vi.fn()
cell.subscribe(listener)
const second = register(component({ body: "second" }), hot, "module:View", "hooks")
const secondCell = (second as Record<PropertyKey, unknown>)[Refreshable.RefreshableTypeId]
const secondCell = refreshCell(second)
expect(secondCell).toBe(cell)
expect(cell.current).toBe(second)
@@ -40,7 +46,7 @@ describe("refresh runtime", () => {
invalidate: vi.fn(),
}
const first = register(component({}), hot, "module:View", "one")
const cell = (first as Record<PropertyKey, unknown>)[Refreshable.RefreshableTypeId] as Refreshable.Cell
const cell = refreshCell(first)
register(component({}), hot, "module:View", "two")
expect(cell.snapshot.resetRevision).toBe(1)
@@ -52,7 +58,7 @@ describe("refresh runtime", () => {
it("is inert outside a Vite hot context", () => {
const descriptor = component({})
expect(register(descriptor, undefined, "module:View", "hooks")).toBe(descriptor)
expect((descriptor as Record<PropertyKey, unknown>)[Refreshable.RefreshableTypeId]).toBeUndefined()
expect(Refreshable.isRefreshable(descriptor)).toBe(false)
})
it("invalidates when the module's View IDs change", () => {