test(core): font lookup tests read only their own fixture fonts, not the machine's (#8200)

This commit is contained in:
Miguel Ángel
2026-11-18 18:58:07 +00:00
committed by GitHub
parent a2830467e4
commit 284b28bfce
2 changed files with 25 additions and 2 deletions
@@ -1,9 +1,20 @@
// @vitest-environment node
import { writeFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { describe, expect, it, vi } from "vitest";
import { fixtureFontDir, makeTtc } from "./sfntFixture.js";
// Only the fixture's fonts: a folder outside the temp dir (the machine's own fonts) does not exist here.
vi.mock("node:fs", async (importOriginal) => {
const fs = await importOriginal<typeof import("node:fs")>();
const { tmpdir } = await import("node:os");
return {
...fs,
existsSync: (path: import("node:fs").PathLike) =>
String(path).startsWith(tmpdir()) && fs.existsSync(path),
};
});
const fonts = fixtureFontDir();
writeFileSync(
join(fonts, "PingFang.ttc"),
@@ -1,8 +1,20 @@
// @vitest-environment node
import { writeFileSync } from "node:fs";
import { join } from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { afterEach, describe, expect, it, vi } from "vitest";
import { fixtureFontDir, makeSfnt, makeTtc } from "./sfntFixture.js";
// Only the fixture's fonts: a folder outside the temp dir (the machine's own fonts) does not exist here.
vi.mock("node:fs", async (importOriginal) => {
const fs = await importOriginal<typeof import("node:fs")>();
const { tmpdir } = await import("node:os");
return {
...fs,
existsSync: (path: import("node:fs").PathLike) =>
String(path).startsWith(tmpdir()) && fs.existsSync(path),
};
});
const fonts = fixtureFontDir();
const { clearSystemFontCache, locateSystemFontVariants } = await import("./systemFontLocator.js");