refactor(web): test file cache identity through its public helpers (#10219)
This commit is contained in:
1 parent
c2cfe59ac3
commit
88fc41c1b9
2 files changed
+5
-13
No files matched your search
@@ -1,19 +1,11 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import {
|
||||
fileContentRevision,
|
||||
projectFileCacheKey,
|
||||
projectFileEditorCacheKey,
|
||||
} from "./fileContentRevision";
|
||||
import { projectFileCacheKey, projectFileEditorCacheKey } from "./fileContentRevision";
|
||||
|
||||
describe("fileContentRevision", () => {
|
||||
describe("file cache identity", () => {
|
||||
it("changes for same-length edits", () => {
|
||||
expect(fileContentRevision("nodeVersion")).not.toBe(fileContentRevision("nodeVeasdrs"));
|
||||
});
|
||||
|
||||
it("keeps identical contents stable", () => {
|
||||
expect(projectFileCacheKey("/repo", "file.json", "contents")).toBe(
|
||||
projectFileCacheKey("/repo", "file.json", "contents"),
|
||||
expect(projectFileCacheKey("/repo", "file.json", "nodeVersion")).not.toBe(
|
||||
projectFileCacheKey("/repo", "file.json", "nodeVeasdrs"),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export function fileContentRevision(contents: string): string {
|
||||
function fileContentRevision(contents: string): string {
|
||||
let hash = 2_166_136_261;
|
||||
for (let index = 0; index < contents.length; index += 1) {
|
||||
hash ^= contents.charCodeAt(index);
|
||||
|
||||
Reference in new issue
Block a user