Skip to content

Commit c930ce0

Browse files
committed
fix percentage
1 parent 377929c commit c930ce0

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/codeblocks.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ function logStatus(event: EditorStatus): void {
463463
console.info("[CodeBlocks] Monaco loaded");
464464
} else if (event.type === "clangd-downloading") {
465465
const progress = event.total
466-
? `${Math.round((event.loaded / event.total) * 100)}%`
467-
: `${event.loaded} bytes`;
466+
? `${formatMegabytes(event.loaded)} MB / ${formatMegabytes(event.total)} MB`
467+
: `${formatMegabytes(event.loaded)} MB downloaded`;
468468
console.info(`[CodeBlocks] clangd downloading: ${progress}`);
469469
} else if (event.type === "clangd-starting") {
470470
console.info("[CodeBlocks] clangd starting");
@@ -477,6 +477,10 @@ function logStatus(event: EditorStatus): void {
477477
}
478478
}
479479

480+
function formatMegabytes(bytes: number): string {
481+
return (bytes / (1024 * 1024)).toFixed(1);
482+
}
483+
480484
interface CompilerLine { text: string }
481485
interface CompilerResult {
482486
didExecute: boolean;

tests/runtime.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ test("code help works under the opt-in isolation service worker", async ({ page
167167
expect(errors).toEqual([]);
168168
expect(messages).toEqual(expect.arrayContaining([
169169
expect.stringContaining("[CodeBlocks] Monaco loaded"),
170+
expect.stringMatching(
171+
/\[CodeBlocks\] clangd downloading: \d+\.\d MB \/ \d+\.\d MB/,
172+
),
170173
expect.stringContaining("[CodeBlocks] clangd starting"),
171174
expect.stringContaining("[CodeBlocks] clangd loaded"),
172175
expect.stringContaining("[CodeBlocks] clangd activated"),

0 commit comments

Comments
 (0)