Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

fileContentRevision.test.ts

34 lines1.2 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { projectFileCacheKey, projectFileEditorCacheKey } from "./fileContentRevision";
4​
5describe("file cache identity", () => {
6 it("changes for same-length edits", () => {
7 expect(projectFileCacheKey("/repo", "file.json", "nodeVersion")).not.toBe(
8 projectFileCacheKey("/repo", "file.json", "nodeVeasdrs"),
9 );
10 });
11​
12 it("keeps editor identity stable for locally edited contents", () => {
13 const cacheKey = projectFileEditorCacheKey("local", "/repo", "file.json", "after", undefined);
14​
15 expect(
16 projectFileEditorCacheKey("local", "/repo", "file.json", "after edit", {
17 cacheKey,
18 contents: "after edit",
19 }),
20 ).toBe(cacheKey);
21 });
22​
23 it("rotates editor identity for external contents and environments", () => {
24 const cacheKey = projectFileEditorCacheKey("local", "/repo", "file.json", "before", undefined);
25 const editorFile = { cacheKey, contents: "before" };
26​
27 expect(
28 projectFileEditorCacheKey("local", "/repo", "file.json", "external edit", editorFile),
29 ).not.toBe(cacheKey);
30 expect(projectFileEditorCacheKey("remote", "/repo", "file.json", "before", undefined)).not.toBe(
31 cacheKey,
32 );
33 });
34});