Archived
test: make server tests pass on Windows
This commit is contained in:
@@ -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 });
|
||||
|
||||
|
||||
@@ -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"));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user