refactor: 收敛渲染链路共享抽象
This commit is contained in:
@@ -287,6 +287,58 @@ describe("预览 API", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("缓存主题目录扫描并支持主动失效", async () => {
|
||||
temporaryDirectory = await mkdtemp(join(tmpdir(), "md-to-pdf-theme-"));
|
||||
const bundledRoot = join(temporaryDirectory, "bundled");
|
||||
const localRoot = join(temporaryDirectory, "local");
|
||||
const firstThemeRoot = join(localRoot, "first-theme");
|
||||
const secondThemeRoot = join(localRoot, "second-theme");
|
||||
await mkdir(bundledRoot, { recursive: true });
|
||||
await mkdir(firstThemeRoot, { recursive: true });
|
||||
await writeFile(
|
||||
join(firstThemeRoot, "theme.json"),
|
||||
JSON.stringify(localThemeManifest("first-theme")),
|
||||
"utf8"
|
||||
);
|
||||
await writeFile(
|
||||
join(firstThemeRoot, "theme.css"),
|
||||
"#write { color: #333; }",
|
||||
"utf8"
|
||||
);
|
||||
|
||||
const registry = createThemeRegistry({
|
||||
bundledRoot,
|
||||
localRoot,
|
||||
cacheTtlMs: 60_000
|
||||
});
|
||||
await expect(registry.list()).resolves.toHaveLength(1);
|
||||
|
||||
await mkdir(secondThemeRoot, { recursive: true });
|
||||
await writeFile(
|
||||
join(secondThemeRoot, "theme.json"),
|
||||
JSON.stringify(localThemeManifest("second-theme")),
|
||||
"utf8"
|
||||
);
|
||||
await writeFile(
|
||||
join(secondThemeRoot, "theme.css"),
|
||||
"#write { color: #666; }",
|
||||
"utf8"
|
||||
);
|
||||
await expect(registry.list()).resolves.toHaveLength(1);
|
||||
|
||||
registry.invalidate();
|
||||
await expect(registry.list()).resolves.toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
manifest: expect.objectContaining({ id: "first-theme" })
|
||||
}),
|
||||
expect.objectContaining({
|
||||
manifest: expect.objectContaining({ id: "second-theme" })
|
||||
})
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
it("拒绝主题 CSS 导入外部地址", async () => {
|
||||
temporaryDirectory = await mkdtemp(join(tmpdir(), "md-to-pdf-theme-"));
|
||||
const bundledRoot = join(temporaryDirectory, "bundled");
|
||||
|
||||
Reference in New Issue
Block a user