import { test } from "node:test"; import assert from "node:assert/strict"; import { mkdtemp, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import { umtoolUrl } from "./umtoolUrl"; test("umtoolUrl: UMTOOL_URL without its trailing slashes, null when unset; a test's loopback origin from the file", async () => { assert.equal(umtoolUrl({}), null); assert.equal(umtoolUrl({ UMTOOL_URL: " " }), null); assert.equal(umtoolUrl({ UMTOOL_URL: "http://localhost:3050//" }), "http://localhost:3050"); const dir = await mkdtemp(path.join(tmpdir(), "umtool-url-")); try { const file = path.join(dir, ".fake-umtool-origin"); const env = { E2E_UMTOOL_ORIGIN_FILE: file, UMTOOL_URL: "http://localhost:3050" }; assert.equal(umtoolUrl(env), "http://localhost:3050", "no file yet"); await writeFile(file, "http://127.0.0.1:41234/\n"); assert.equal(umtoolUrl(env), "http://127.0.0.1:41234"); await writeFile(file, "https://umtool.example.com"); assert.equal(umtoolUrl(env), "http://localhost:3050", "not loopback: ignored"); } finally { await rm(dir, { recursive: true, force: true }); } });