Debug log adds each line instead of drawing the whole panel (closes #131)
check / check (push) Waiting to run
check / check (push) Waiting to run
With the debug log open, every line written drew the panel again with up to 1000 lines, and a check that ends while the page draws is timed only when the drawing is done, so latencies measured with the panel open read too high. Each line is now appended to the open panel and its first line dropped once it holds more than maxLogEntries; the whole panel is drawn only when it is opened. Scrolling to the newest line reads the panel's height, which lays out all its lines, so it runs once a frame, with at most one frame request waiting. Model: opus-5-5
This commit was merged in pull request #135.
This commit is contained in:
+46
-8
@@ -13,20 +13,22 @@ import {
|
||||
humanDuration,
|
||||
latencyClass,
|
||||
latencyHex,
|
||||
log,
|
||||
measureLatency,
|
||||
Reporter,
|
||||
tick,
|
||||
} from "../../web/src/main.js";
|
||||
|
||||
// There is no page here, so the tests stand in for it. The debug log looks
|
||||
// for its panel by id and finds none. Each element of a host's row that
|
||||
// tick or greyOutUI draws into is a plain object, made the first time a
|
||||
// test looks it up and kept in elements under its selector until the next
|
||||
// test starts. As on a page, writing its text replaces its markup; the
|
||||
// status dot greyOutUI looks for in it is not there. Drawing a sparkline
|
||||
// does nothing; it looks for the pixel ratio on window and finds none. In
|
||||
// each test, console.error and console.info print nothing and keep what
|
||||
// they are given.
|
||||
// for its panel by id and finds none, an element the page creates is a
|
||||
// plain object, and no frame the page asks for ever comes. Each element of
|
||||
// a host's row that tick or greyOutUI draws into is a plain object, made
|
||||
// the first time a test looks it up and kept in elements under its
|
||||
// selector until the next test starts. As on a page, writing its text
|
||||
// replaces its markup; the status dot greyOutUI looks for in it is not
|
||||
// there. Drawing a sparkline does nothing; it looks for the pixel ratio on
|
||||
// window and finds none. In each test, console.error and console.info
|
||||
// print nothing and keep what they are given.
|
||||
const doNothing = () => {};
|
||||
let elements;
|
||||
beforeEach((t) => {
|
||||
@@ -46,8 +48,11 @@ const canvasContext = {
|
||||
arc: doNothing,
|
||||
};
|
||||
globalThis.window = {};
|
||||
globalThis.requestAnimationFrame = doNothing;
|
||||
globalThis.cancelAnimationFrame = doNothing;
|
||||
globalThis.document = {
|
||||
getElementById: () => null,
|
||||
createElement: () => ({}),
|
||||
querySelector: (selector) =>
|
||||
(elements[selector] ??= {
|
||||
getContext: () => canvasContext,
|
||||
@@ -471,6 +476,39 @@ test("of the checks interval changes cleared before they were reported, the next
|
||||
assert.equal(sent.at(-1).t, 120000);
|
||||
});
|
||||
|
||||
// panel stands in for the open debug log panel, and for the element in it
|
||||
// that holds its lines, whichever the page looks up by id; the lines are
|
||||
// kept in order in lines. Drawing the whole panel, as opening it does,
|
||||
// replaces every line with a new one.
|
||||
test("with the debug log open, writing more lines than it keeps adds each to the panel and leaves the lines already shown as they are", (t) => {
|
||||
const lines = [];
|
||||
const panel = {
|
||||
classList: { contains: () => false },
|
||||
children: lines,
|
||||
get firstElementChild() {
|
||||
return lines[0];
|
||||
},
|
||||
append: (line) => lines.push(line),
|
||||
removeChild: (line) => lines.splice(lines.indexOf(line), 1),
|
||||
replaceChildren: (...newLines) =>
|
||||
lines.splice(0, lines.length, ...newLines),
|
||||
};
|
||||
t.mock.method(globalThis.document, "getElementById", () => panel);
|
||||
const kept = CONFIG.maxLogEntries;
|
||||
|
||||
for (let i = 1; i <= kept; i++) log.info(`line ${i}`);
|
||||
const shown = [...lines];
|
||||
for (let i = kept + 1; i <= kept + 5; i++) log.info(`line ${i}`);
|
||||
|
||||
assert.deepEqual(
|
||||
lines.map((line) => line.textContent.match(/line \d+$/)?.[0]),
|
||||
Array.from({ length: kept }, (_, i) => `line ${i + 6}`),
|
||||
);
|
||||
// The first five lines shown were dropped, and the rest are the same
|
||||
// lines, not drawn again.
|
||||
shown.slice(5).forEach((line, i) => assert.equal(lines[i], line));
|
||||
});
|
||||
|
||||
// The page shows < > " & and ' in a row's markup as
|
||||
// < > " & and '.
|
||||
test(`a target whose name and URL hold < > " & and ' shows those characters in its row`, () => {
|
||||
|
||||
Reference in New Issue
Block a user