Файли
openidea/src/platform/consoleColumns.test.ts
T
l0ng-ai 4f0ab6c968 fix(debugger): bound the debug console's output backlog under a log flood (#5847)
Debug output arriving faster than the console parsed it piled up in the per-frame queue, and each frame re-measured the widest line of all 50,000 lines because the growing last line is replaced by a copy. Pending output is now capped at 4 MiB per session (oldest whole lines first), the widest-line measure resumes by line id, lines over 8,000 characters are broken up as in the Run console, and dropped lines are counted and shown as "N earlier lines were discarded".

Fixes #5769
2026-11-25 17:09:51 +08:00

47 рядки
1.8 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import { textColumns, WidestColumns } from "./consoleColumns";
describe("console columns", () => {
it("counts tabs to the next stop and wide characters twice", () => {
expect(textColumns("abc", 4)).toBe(3);
expect(textColumns("a\tb", 4)).toBe(5);
expect(textColumns("\t\t", 4)).toBe(8);
expect(textColumns("中文ok", 4)).toBe(6);
expect(textColumns("😀", 4)).toBe(2);
expect(textColumns("long line\nshort\n", 4)).toBe(9);
});
it("measures only new lines and the growing last one", () => {
const widest = new WidestColumns();
const lines = [{ text: "12345" }, { text: "12" }];
expect(widest.measure(lines)).toBe(5);
lines[1]!.text = "1234567";
expect(widest.measure(lines)).toBe(7);
// Dropping lines from the front keeps the width.
lines.splice(0, 1);
lines.push({ text: "1" });
expect(widest.measure(lines)).toBe(7);
// A new array of the same line objects (an immutable append) continues from the last one.
const next = [...lines, { text: "123456789" }];
expect(widest.measure(next)).toBe(9);
// A cleared console starts over.
expect(widest.measure([])).toBe(0);
expect(widest.measure([{ text: "abc" }])).toBe(3);
});
});
it("resumes from a growing last line the store replaced with a copy", () => {
const widest = new WidestColumns();
const first = [
{ id: 1, text: "abc\n" },
{ id: 2, text: "de" },
];
expect(widest.measure(first)).toBe(3);
const text = vi.spyOn(String.prototype, "codePointAt");
// Line 2 grew into a new object; only it and the lines after it are measured.
const next = [first[0]!, { id: 2, text: "defgh\n" }, { id: 3, text: "ij\n" }];
expect(widest.measure(next)).toBe(5);
expect(text.mock.calls.length).toBe("defgh\n".length + "ij\n".length);
text.mockRestore();
});