diff --git a/packages/core/src/fonts/deterministicFonts-systemTtc.test.ts b/packages/core/src/fonts/deterministicFonts-systemTtc.test.ts index 1fdf0a6492..2d541414aa 100644 --- a/packages/core/src/fonts/deterministicFonts-systemTtc.test.ts +++ b/packages/core/src/fonts/deterministicFonts-systemTtc.test.ts @@ -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(); + 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"), diff --git a/packages/core/src/fonts/systemFontLocator.innerName.test.ts b/packages/core/src/fonts/systemFontLocator.innerName.test.ts index e5eb5b8a26..d4e1e76c16 100644 --- a/packages/core/src/fonts/systemFontLocator.innerName.test.ts +++ b/packages/core/src/fonts/systemFontLocator.innerName.test.ts @@ -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(); + 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");