mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 11:26:02 +00:00
test(core): font lookup tests read only their own fixture fonts, not the machine's (#8200)
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user