test: make server tests pass on Windows

This commit is contained in:
Marc Kassubeck
2026-05-26 13:04:00 +02:00
parent 0405b384b1
commit 3270619f24
3 changed files with 20 additions and 6 deletions
+1 -1
View File
@@ -78,7 +78,7 @@ describe("PiWebPluginService", () => {
files: { "pi-web-plugin.js": "export default { apiVersion: 1, name: 'Dev', activate: () => ({ contributions: {} }) };" },
});
await mkdir(join(tempDir, "plugins"), { recursive: true });
await symlink(pluginDir, join(tempDir, "plugins", "dev"), "dir");
await symlink(pluginDir, join(tempDir, "plugins", "dev"), process.platform === "win32" ? "junction" : "dir");
const service = new PiWebPluginService({ roots: [{ path: join(tempDir, "plugins"), source: "test", scope: "local" }], packageProvider: false });
+3 -3
View File
@@ -1,13 +1,13 @@
import { join } from "node:path";
import { resolve } from "node:path";
import { describe, expect, it } from "vitest";
import { projectStorePath } from "./projectStore.js";
describe("projectStorePath", () => {
it("uses PI_WEB_DATA_DIR by default", () => {
expect(projectStorePath({ PI_WEB_DATA_DIR: "demo-data" }, "/tmp/pi-web")).toBe(join("/tmp/pi-web", "demo-data", "projects.json"));
expect(projectStorePath({ PI_WEB_DATA_DIR: "demo-data" }, "/tmp/pi-web")).toBe(resolve("/tmp/pi-web", "demo-data", "projects.json"));
});
it("uses PI_WEB_PROJECTS_FILE when configured", () => {
expect(projectStorePath({ PI_WEB_PROJECTS_FILE: "demo/projects.json" }, "/tmp/pi-web")).toBe(join("/tmp/pi-web", "demo/projects.json"));
expect(projectStorePath({ PI_WEB_PROJECTS_FILE: "demo/projects.json" }, "/tmp/pi-web")).toBe(resolve("/tmp/pi-web", "demo/projects.json"));
});
});
+16 -2
View File
@@ -25,7 +25,7 @@ describe("listWorkspaceTree", () => {
await mkdir(join(root, "node_modules"));
await writeFile(join(root, "b.txt"), "b");
await writeFile(join(root, "a.txt"), "a");
await symlink(join(root, "a.txt"), join(root, "link.txt"));
const createdSymlink = await trySymlink(join(root, "a.txt"), join(root, "link.txt"));
const tree = await listWorkspaceTree(root, undefined);
@@ -36,7 +36,7 @@ describe("listWorkspaceTree", () => {
["z-dir", "directory"],
["a.txt", "file"],
["b.txt", "file"],
["link.txt", "symlink"],
...(createdSymlink ? [["link.txt", "symlink"]] : []),
]);
expect(Date.parse(tree.scannedAt)).not.toBeNaN();
});
@@ -73,3 +73,17 @@ describe("listWorkspaceTree", () => {
expect(tree.truncated).toBe(true);
});
});
async function trySymlink(target: string, path: string): Promise<boolean> {
try {
await symlink(target, path);
return true;
} catch (error) {
if (isNodeErrorWithCode(error, "EPERM")) return false;
throw error;
}
}
function isNodeErrorWithCode(error: unknown, code: string): error is NodeJS.ErrnoException {
return error instanceof Error && "code" in error && error.code === code;
}