fix: complete Finder project workflow and add in-place output
This commit is contained in:
@@ -2,6 +2,7 @@ import { afterEach, describe, expect, it, mock } from "bun:test";
|
||||
import { promises as fs } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import type { RunFile } from "../src/lib/velum-project";
|
||||
|
||||
mock.module("@raycast/api", () => ({ environment: { supportPath: tmpdir() } }));
|
||||
const project = await import("../src/lib/velum-project");
|
||||
@@ -44,4 +45,41 @@ describe("Velum-Projektstände", () => {
|
||||
const spans = project.toUtf16Offsets(text, [{ id: "max", start: 2, end: 5, placeholder: "PERSON_01" }]);
|
||||
expect(project.replaceSpans(text, spans, new Set(["max"]))).toBe("😀 PERSON_01");
|
||||
});
|
||||
|
||||
it("ersetzt ausgewählte Projektdateien vor Ort und sichert die Originale außerhalb", async () => {
|
||||
const root = await fs.mkdtemp(join(tmpdir(), "velum-in-place-test-"));
|
||||
roots.push(root);
|
||||
const source = join(root, "Quelle");
|
||||
const support = join(root, "Raycast");
|
||||
await fs.mkdir(source);
|
||||
await fs.writeFile(join(source, "Bericht.txt"), "Max Mustermann");
|
||||
await fs.chmod(join(source, "Bericht.txt"), 0o640);
|
||||
await fs.writeFile(join(source, "Unberührt.txt"), "bleibt");
|
||||
const created = await project.createRun(source, support);
|
||||
await fs.writeFile(join(created.directory, "files", "PERSON_01.txt"), "PERSON_01");
|
||||
const files: RunFile[] = [{ source: "Bericht.txt", output: "PERSON_01.txt", kind: "text" }];
|
||||
await project.replaceProjectFilesInPlace(source, created.directory, files);
|
||||
expect(await fs.readFile(join(source, "PERSON_01.txt"), "utf8")).toBe("PERSON_01");
|
||||
expect((await fs.stat(join(source, "PERSON_01.txt"))).mode & 0o777).toBe(0o640);
|
||||
expect(await fs.readFile(join(created.directory, "backup", "Bericht.txt"), "utf8")).toBe("Max Mustermann");
|
||||
expect((await fs.stat(join(created.directory, "backup", "Bericht.txt"))).mode & 0o777).toBe(0o600);
|
||||
expect(await fs.readFile(join(source, "Unberührt.txt"), "utf8")).toBe("bleibt");
|
||||
await expect(fs.access(join(source, "Bericht.txt"))).rejects.toMatchObject({ code: "ENOENT" });
|
||||
});
|
||||
|
||||
it("verhindert Namenskollisionen vor dem Ersetzen", async () => {
|
||||
const root = await fs.mkdtemp(join(tmpdir(), "velum-in-place-collision-test-"));
|
||||
roots.push(root);
|
||||
const source = join(root, "Quelle");
|
||||
const support = join(root, "Raycast");
|
||||
await fs.mkdir(source);
|
||||
await fs.writeFile(join(source, "Bericht.txt"), "Original");
|
||||
await fs.writeFile(join(source, "PERSON_01.txt"), "Andere Datei");
|
||||
const created = await project.createRun(source, support);
|
||||
await fs.writeFile(join(created.directory, "files", "PERSON_01.txt"), "Pseudonym");
|
||||
await expect(project.replaceProjectFilesInPlace(source, created.directory,
|
||||
[{ source: "Bericht.txt", output: "PERSON_01.txt", kind: "text" }])).rejects.toThrow("Zielname bereits vorhanden");
|
||||
expect(await fs.readFile(join(source, "Bericht.txt"), "utf8")).toBe("Original");
|
||||
expect(await fs.readFile(join(source, "PERSON_01.txt"), "utf8")).toBe("Andere Datei");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user