import { describe, expect, it } from "vitest"; import { eslint } from "./lintProbe.testkit"; // eslint.config.js: a bare `fetchNextPage()` cancels the page already loading and sends it again. // Pins that the rule keeping every call on NEXT_PAGE actually fires. const MESSAGE = "fetchNextPage() cancels"; async function hits(source: string): Promise { const [result] = await eslint.lintText(source, { filePath: "src/components/__probe.tsx" }); return (result?.messages ?? []).filter((m) => m.message.startsWith(MESSAGE)).length; } describe("a next-page fetch", () => { it("is refused bare, on the query or destructured", async () => { expect( await hits("export const a = (q: { fetchNextPage(): void }) => q.fetchNextPage();\n"), ).toBe(1); expect(await hits("export const b = (fetchNextPage: () => void) => fetchNextPage();\n")).toBe( 1, ); }); it("passes with NEXT_PAGE", async () => { expect( await hits( 'import { NEXT_PAGE } from "../lib/nextPage";\nexport const c = (q: { fetchNextPage(o: unknown): void }) => q.fetchNextPage(NEXT_PAGE);\n', ), ).toBe(0); }); });