31 lines · 1.1 KB · TypeScript
RawDownload
import { describe, expect, it } from "vitest";import { buildPatchCacheKey } from "./diffRendering"; describe("buildPatchCacheKey", () => {  it("returns a stable cache key for identical content", () => {    const patch = "diff --git a/a.ts b/a.ts\n+console.log('hello')";     expect(buildPatchCacheKey(patch)).toBe(buildPatchCacheKey(patch));  });   it("normalizes outer whitespace before hashing", () => {    const patch = "diff --git a/a.ts b/a.ts\n+console.log('hello')";     expect(buildPatchCacheKey(`\n${patch}\n`)).toBe(buildPatchCacheKey(patch));  });   it("changes when diff content changes", () => {    const before = "diff --git a/a.ts b/a.ts\n+console.log('hello')";    const after = "diff --git a/a.ts b/a.ts\n+console.log('hello world')";     expect(buildPatchCacheKey(before)).not.toBe(buildPatchCacheKey(after));  });   it("changes when cache scope changes", () => {    const patch = "diff --git a/a.ts b/a.ts\n+console.log('hello')";     expect(buildPatchCacheKey(patch, "diff-panel:light")).not.toBe(      buildPatchCacheKey(patch, "diff-panel:dark"),    );  });});