import assert from "node:assert/strict"; import { chmodSync, copyFileSync, existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync, } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import { afterEach, describe, it } from "vitest"; import { openHtmlFile } from "../open-browser.ts"; const roots: string[] = []; afterEach(() => { for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true }); }); describe("System browser opener", () => { it("opens through the native win32 URL handler without cmd", async () => { const root = mkdtempSync(path.join(tmpdir(), "system-browser-")); roots.push(root); const executable = path.join(root, "rundll32.exe"); const preload = path.join(root, "record.cjs"); const record = path.join(root, "args.json"); const temporaryRecord = path.join(root, "args.json.tmp"); const html = path.join(root, "system.html"); copyFileSync(process.execPath, executable); chmodSync(executable, 0o755); writeFileSync( preload, `const fs = require("node:fs"); fs.writeFileSync(${JSON.stringify(temporaryRecord)}, JSON.stringify(process.argv.slice(1))); fs.renameSync(${JSON.stringify(temporaryRecord)}, ${JSON.stringify(record)});`, ); writeFileSync(html, "