52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { patchAlphaHubAuthSource } from "../scripts/lib/alpha-hub-auth-patch.mjs";
|
|
|
|
test("patchAlphaHubAuthSource fixes browser open logic for WSL and Windows", () => {
|
|
const input = [
|
|
"function openBrowser(url) {",
|
|
" try {",
|
|
" const plat = platform();",
|
|
" if (plat === 'darwin') execSync(`open \"${url}\"`);",
|
|
" else if (plat === 'linux') execSync(`xdg-open \"${url}\"`);",
|
|
" else if (plat === 'win32') execSync(`start \"\" \"${url}\"`);",
|
|
" } catch {}",
|
|
"}",
|
|
].join("\n");
|
|
|
|
const patched = patchAlphaHubAuthSource(input);
|
|
|
|
assert.match(patched, /const isWsl = plat === 'linux'/);
|
|
assert.match(patched, /wslview/);
|
|
assert.match(patched, /cmd\.exe \/c start/);
|
|
assert.match(patched, /cmd \/c start/);
|
|
});
|
|
|
|
test("patchAlphaHubAuthSource includes the auth URL in login output", () => {
|
|
const input = "process.stderr.write('Opening browser for alphaXiv login...\\n');";
|
|
|
|
const patched = patchAlphaHubAuthSource(input);
|
|
|
|
assert.match(patched, /Auth URL: \$\{authUrl\.toString\(\)\}/);
|
|
});
|
|
|
|
test("patchAlphaHubAuthSource is idempotent", () => {
|
|
const input = [
|
|
"function openBrowser(url) {",
|
|
" try {",
|
|
" const plat = platform();",
|
|
" if (plat === 'darwin') execSync(`open \"${url}\"`);",
|
|
" else if (plat === 'linux') execSync(`xdg-open \"${url}\"`);",
|
|
" else if (plat === 'win32') execSync(`start \"\" \"${url}\"`);",
|
|
" } catch {}",
|
|
"}",
|
|
"process.stderr.write('Opening browser for alphaXiv login...\\n');",
|
|
].join("\n");
|
|
|
|
const once = patchAlphaHubAuthSource(input);
|
|
const twice = patchAlphaHubAuthSource(once);
|
|
|
|
assert.equal(twice, once);
|
|
});
|