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