Skip to content

Build your personal knowledge base with Trilium Notes

test(highlightjs): cover a failed syncMimeTypes call

Elian Doran0f226cc853bb
diff --git a/packages/highlightjs/src/index.spec.ts b/packages/highlightjs/src/index.spec.ts
index 913fec0f38..4fb5dca19e 100644
--- a/packages/highlightjs/src/index.spec.ts
+++ b/packages/highlightjs/src/index.spec.ts
@@ -79,6 +79,26 @@ describe("ensureMimeTypes", () => {
expect(getLanguage("text-x-python")).toBeUndefined();
});
+ it("syncMimeTypes keeps running calls after one fails", async () => {
+ const pythonLoader = vi.fn()
+ .mockRejectedValueOnce(new Error("offline"))
+ .mockImplementation(() => import("highlight.js/lib/languages/python"));
+ vi.doMock("./syntax_highlighting.js", async (importOriginal) => {
+ const original = await importOriginal<typeof import("./syntax_highlighting.js")>();
+ return { default: { ...original.default, "text-x-python": pythonLoader } };
+ });
+
+ try {
+ const { syncMimeTypes, getLanguage } = await freshModule();
+
+ await expect(syncMimeTypes([ mime("text/x-python") ])).rejects.toThrow("offline");
+ await syncMimeTypes([ mime("text/x-python") ]);
+ expect(getLanguage("text-x-python")).toBeDefined();
+ } finally {
+ vi.doUnmock("./syntax_highlighting.js");
+ }
+ });
+
it("remembers a mime type with no highlight.js definition as unsupported", async () => {
const { ensureMimeTypes, highlight } = await freshModule();
const warn = vi.spyOn(console, "warn").mockImplementation(() => undefined);