import { renderHtmlFromDocument } from "@comark/html";
import { parseMarkdown } from "comark";
import shiki from "comark/plugins/shiki";
import { describe, expect, it } from "vite-plus/test";
import diffPlugin, { components } from "../src/html.ts";
const fence = "```";
const gitDiff = `diff --git a/src/upload.ts b/src/upload.ts
index 3b18e51..a9c2f0d 100644
--- a/src/upload.ts
+++ b/src/upload.ts
@@ -10,5 +10,6 @@ export async function upload(file: File) {
const body = new FormData();
body.append("file", file);
- const response = await fetch(url, { method: "POST", body });
+ const response = await retry(() => fetch(url, { method: "POST", body }));
+ if (!response.ok) throw new Error(response.statusText);
return response.json();
}
diff --git a/src/retry.ts b/src/retry.ts
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/retry.ts
@@ -0,0 +1,3 @@
+export async function retry(run: () => Promise) {
+ return run().catch(() => run());
+}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 1..2 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1,2 +1,2 @@
-lockfileVersion: '9.0'
+lockfileVersion: '9.1'
settings: {}
`;
async function run(markdown: string, highlight = false) {
const document = await parseMarkdown(markdown, {
plugins: highlight ? [diffPlugin(), shiki()] : [diffPlugin()],
});
const html = await renderHtmlFromDocument(document, { components });
return {
issues: document.meta.issues,
rules: document.meta.issueRules,
html: html.replace(/