mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-15 22:08:03 +00:00
* test(cli): CLI tests run with a home folder of their own, never the user's * style(cli): format the test home check * test(cli): the skills test lane also runs with a home folder of its own * style(cli): format the test home check * ci: the test reachability map follows the skills lane's new command
42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
import { existsSync, realpathSync, rmSync } from "node:fs";
|
|
import { homedir, tmpdir, userInfo } from "node:os";
|
|
import { join, sep } from "node:path";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { fetchRegistryManifest } from "./registry/remote.js";
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
describe("the CLI test run", () => {
|
|
it("has a home folder of its own, not the user's", () => {
|
|
expect(realpathSync(homedir()).startsWith(realpathSync(tmpdir()) + sep)).toBe(true);
|
|
expect(homedir()).not.toBe(userInfo().homedir);
|
|
});
|
|
|
|
it("caches a registry read in that home", async () => {
|
|
const registry = `https://test.invalid/${crypto.randomUUID()}`;
|
|
const items: unknown[] = [];
|
|
const $schema = "https://hyperframes.heygen.com/schema/registry.json";
|
|
const manifest = { $schema, name: "t", homepage: "https://example.com", items };
|
|
vi.stubGlobal(
|
|
"fetch",
|
|
vi.fn(async (input: string | URL) =>
|
|
String(input) === `${registry}/registry.json`
|
|
? new Response(JSON.stringify(manifest))
|
|
: new Response("not found", { status: 404 }),
|
|
),
|
|
);
|
|
|
|
await fetchRegistryManifest(registry);
|
|
|
|
const slug = registry.replace(/[^a-zA-Z0-9]/g, "_");
|
|
const cacheFile = (home: string) =>
|
|
join(home, ".hyperframes", "cache", `${slug}__registry.json`);
|
|
const leaked = existsSync(cacheFile(userInfo().homedir));
|
|
rmSync(cacheFile(userInfo().homedir), { force: true });
|
|
expect(existsSync(cacheFile(homedir()))).toBe(true);
|
|
expect(leaked).toBe(false);
|
|
});
|
|
});
|