Files
paseo/packages/desktop/src/features/editor-targets/runtime.test.ts
T
Mohamed Boudra f4509fe044 Open files in more installed editors (#2119)
* feat(desktop): open files in more installed editors

Detect bundled app commands as well as PATH launchers and preserve file positions through editor-specific launches.

* fix(desktop): preserve editor target compatibility

Keep existing file-manager preference ids, retain project context for file launches, and recognize Windows 64-bit IDE commands.
2026-07-16 14:39:55 +02:00

61 lines
1.8 KiB
TypeScript

import type { SpawnOptions } from "node:child_process";
import { describe, expect, it } from "vitest";
import { createEditorTargetRuntime } from "./runtime.js";
interface SpawnRecord {
command: string;
args: string[];
options: SpawnOptions;
unrefed: boolean;
}
describe("editor target runtime", () => {
it("resolves command aliases and safely launches Windows command scripts", async () => {
const records: SpawnRecord[] = [];
const runtime = createEditorTargetRuntime({
platform: "win32",
env: {
PATH: "C:/Program Files/Editors & Tools/bin",
ELECTRON_RUN_AS_NODE: "1",
},
pathExists: (targetPath) => targetPath === "C:/Program Files/Editors & Tools/bin/code.cmd",
spawn: (command, args, options) => {
const record = { command, args, options, unrefed: false };
records.push(record);
const child = {
once(event: "error" | "spawn", handler: (error?: Error) => void) {
if (event === "spawn") queueMicrotask(() => handler());
return child;
},
unref() {
record.unrefed = true;
},
};
return child;
},
});
const command = runtime.resolveCommand(["missing", "code"]);
if (!command) throw new Error("Expected the editor command to resolve");
await runtime.spawnDetached({
command,
args: ["C:/repo & workspace", "C:/repo/src/file & calculator.ts"],
});
expect(records).toEqual([
{
command: '"C:/Program Files/Editors & Tools/bin/code.cmd"',
args: ['"C:/repo & workspace"', '"C:/repo/src/file & calculator.ts"'],
options: {
detached: true,
env: { PATH: "C:/Program Files/Editors & Tools/bin" },
shell: true,
stdio: "ignore",
},
unrefed: true,
},
]);
});
});