mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-08-28 14:27:08 +00:00
refactor: consume Commonlib as a package
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
import { mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { fsPromises, os, path } from "@vrtmrz/livesync-commonlib/node";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { FilePath } from "@lib/common/types";
|
||||
import type { FilePath } from "@vrtmrz/livesync-commonlib/compat/common/types";
|
||||
import { NodeFileSystemAdapter } from "./NodeFileSystemAdapter";
|
||||
import { NodeVaultAdapter } from "./NodeVaultAdapter";
|
||||
|
||||
describe("NodeVaultAdapter.rename", () => {
|
||||
it("changes the directory entry case without changing the content", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "livesync-case-rename-"));
|
||||
const directory = await fsPromises.mkdtemp(path.join(os.tmpdir(), "livesync-case-rename-"));
|
||||
try {
|
||||
await writeFile(join(directory, "Calculus.md"), "content", "utf8");
|
||||
await fsPromises.writeFile(path.join(directory, "Calculus.md"), "content", "utf8");
|
||||
const adapter = new NodeVaultAdapter(directory);
|
||||
const file = {
|
||||
path: "Calculus.md" as FilePath,
|
||||
@@ -19,20 +17,20 @@ describe("NodeVaultAdapter.rename", () => {
|
||||
|
||||
await adapter.rename(file, "calculus.md");
|
||||
|
||||
expect(await readdir(directory)).toEqual(["calculus.md"]);
|
||||
expect(await readFile(join(directory, "calculus.md"), "utf8")).toBe("content");
|
||||
expect(await fsPromises.readdir(directory)).toEqual(["calculus.md"]);
|
||||
expect(await fsPromises.readFile(path.join(directory, "calculus.md"), "utf8")).toBe("content");
|
||||
expect(file.path).toBe("calculus.md");
|
||||
} finally {
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
await fsPromises.rm(directory, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("NodeFileSystemAdapter path case", () => {
|
||||
it("finds the stored case and refreshes the cache after a case-only rename", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "livesync-case-cache-"));
|
||||
const directory = await fsPromises.mkdtemp(path.join(os.tmpdir(), "livesync-case-cache-"));
|
||||
try {
|
||||
await writeFile(join(directory, "Calculus.md"), "content", "utf8");
|
||||
await fsPromises.writeFile(path.join(directory, "Calculus.md"), "content", "utf8");
|
||||
const adapter = new NodeFileSystemAdapter(directory);
|
||||
|
||||
await expect(adapter.getAbstractFileByPath("calculus.md")).resolves.toBeNull();
|
||||
@@ -43,9 +41,9 @@ describe("NodeFileSystemAdapter path case", () => {
|
||||
|
||||
expect(renamedFile.path).toBe("calculus.md");
|
||||
expect((await adapter.getFiles()).map((file) => file.path)).toEqual(["calculus.md"]);
|
||||
expect(await readdir(directory)).toEqual(["calculus.md"]);
|
||||
expect(await fsPromises.readdir(directory)).toEqual(["calculus.md"]);
|
||||
} finally {
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
await fsPromises.rm(directory, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user