- Move all co-located *.test.* files into sibling __tests__/ directories so the
layout is consistent across packages (159 renames + content-rewrite moves).
Updates relative imports, vi.mock specifiers, and __dirname/import.meta.url
path resolutions where tests read fixtures from disk.
- Drop tracked tsc-emit alongside engine .ts sources (auth-storage/logger/
skill-resolver/context-limit-detector/pi.{js,d.ts,*.map}). These were
accidentally committed in a merge and the stale pi.js was masking a real
test-mock vs source mismatch (tests imported "../pi.js" and vite preferred
the stale build over pi.ts).
- Add packages/engine/.gitignore to block future src/*.{js,d.ts,map}.
- Refactor plugin pi-module seams (openclaw/paperclip/hermes) to ESM-import
createFnAgent / promptWithFallback / describeModel from @fusion/engine
instead of require()-ing packages/engine/src/pi.js. Adds @fusion/engine to
the two plugin package.jsons that were missing it; exports describeModel
from the engine public API.
- Fix engine test mocks now that they run against current pi.ts: add
ModelRegistry.create static to mocks in pi.test.ts and pi-create-fn-agent
.test.ts; switch three boundary-result toEqual assertions to toMatchObject
so the new content/isError fields don't trip exact-match comparison.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
79 lines
2.0 KiB
TypeScript
79 lines
2.0 KiB
TypeScript
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
import { renderHook, act } from "@testing-library/react";
|
|
import { useFlashOnIncrease } from "../useFlashOnIncrease";
|
|
|
|
describe("useFlashOnIncrease", () => {
|
|
beforeEach(() => {
|
|
vi.useFakeTimers();
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
it("does not flash on initial render", () => {
|
|
const { result } = renderHook(() => useFlashOnIncrease(3));
|
|
expect(result.current).toBe(false);
|
|
});
|
|
|
|
it("flashes when count increases", () => {
|
|
const { result, rerender } = renderHook(
|
|
({ count }) => useFlashOnIncrease(count),
|
|
{ initialProps: { count: 3 } },
|
|
);
|
|
|
|
rerender({ count: 5 });
|
|
expect(result.current).toBe(true);
|
|
});
|
|
|
|
it("resets flashing after duration", () => {
|
|
const { result, rerender } = renderHook(
|
|
({ count }) => useFlashOnIncrease(count, 1400),
|
|
{ initialProps: { count: 3 } },
|
|
);
|
|
|
|
rerender({ count: 5 });
|
|
expect(result.current).toBe(true);
|
|
|
|
act(() => {
|
|
vi.advanceTimersByTime(1400);
|
|
});
|
|
expect(result.current).toBe(false);
|
|
});
|
|
|
|
it("does not flash when count decreases", () => {
|
|
const { result, rerender } = renderHook(
|
|
({ count }) => useFlashOnIncrease(count),
|
|
{ initialProps: { count: 5 } },
|
|
);
|
|
|
|
rerender({ count: 2 });
|
|
expect(result.current).toBe(false);
|
|
});
|
|
|
|
it("does not flash when count stays the same", () => {
|
|
const { result, rerender } = renderHook(
|
|
({ count }) => useFlashOnIncrease(count),
|
|
{ initialProps: { count: 5 } },
|
|
);
|
|
|
|
rerender({ count: 5 });
|
|
expect(result.current).toBe(false);
|
|
});
|
|
|
|
it("cleans up timer on unmount", () => {
|
|
const clearTimeoutSpy = vi.spyOn(global, "clearTimeout");
|
|
|
|
const { rerender, unmount } = renderHook(
|
|
({ count }) => useFlashOnIncrease(count),
|
|
{ initialProps: { count: 3 } },
|
|
);
|
|
|
|
rerender({ count: 5 });
|
|
unmount();
|
|
|
|
expect(clearTimeoutSpy).toHaveBeenCalled();
|
|
clearTimeoutSpy.mockRestore();
|
|
});
|
|
});
|