Open History to see the last commit
1import { describe, expect, it } from "vitest";
2import { buildPatchCacheKey } from "./diffRendering";
3
4describe("buildPatchCacheKey", () => {
5 it("returns a stable cache key for identical content", () => {
6 const patch = "diff --git a/a.ts b/a.ts\n+console.log('hello')";
7
8 expect(buildPatchCacheKey(patch)).toBe(buildPatchCacheKey(patch));
9 });
10
11 it("normalizes outer whitespace before hashing", () => {
12 const patch = "diff --git a/a.ts b/a.ts\n+console.log('hello')";
13
14 expect(buildPatchCacheKey(`\n${patch}\n`)).toBe(buildPatchCacheKey(patch));
15 });
16
17 it("changes when diff content changes", () => {
18 const before = "diff --git a/a.ts b/a.ts\n+console.log('hello')";
19 const after = "diff --git a/a.ts b/a.ts\n+console.log('hello world')";
20
21 expect(buildPatchCacheKey(before)).not.toBe(buildPatchCacheKey(after));
22 });
23
24 it("changes when cache scope changes", () => {
25 const patch = "diff --git a/a.ts b/a.ts\n+console.log('hello')";
26
27 expect(buildPatchCacheKey(patch, "diff-panel:light")).not.toBe(
28 buildPatchCacheKey(patch, "diff-panel:dark"),
29 );
30 });
31});