Skip to content

Commit 7524095

Browse files
committed
test(tui): expose native render stats on the harness
1 parent 2b42830 commit 7524095

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎src/tui/harness.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,38 @@ describe("withTestRenderer", () => {
5656
expect(ctrlC.ctrl).toBe(true);
5757
});
5858
});
59+
60+
test("surfaces native stats and advances nativeFrameCount across renderOnce", async () => {
61+
await withTestRenderer(
62+
async (h) => {
63+
expect(typeof h.waitForVisualIdle).toBe("function");
64+
expect(typeof h.externalOutput.take).toBe("function");
65+
expect(h.externalOutput.take()).toEqual([]);
66+
67+
const before = h.getNativeStats();
68+
expect(typeof before.nativeLastFrameTime).toBe("number");
69+
expect(typeof before.nativeAverageFrameTime).toBe("number");
70+
expect(typeof before.cellsUpdated).toBe("number");
71+
expect(typeof before.averageCellsUpdated).toBe("number");
72+
73+
const box = new BoxRenderable(h.renderer, {
74+
id: "stats",
75+
width: "100%",
76+
height: "100%",
77+
});
78+
box.add(
79+
new TextRenderable(h.renderer, {
80+
content: "native-stats",
81+
}),
82+
);
83+
h.root.add(box);
84+
85+
await h.renderOnce();
86+
const after = h.getNativeStats();
87+
expect(after.nativeFrameCount).toBeGreaterThan(before.nativeFrameCount);
88+
await h.waitForVisualIdle();
89+
},
90+
{ width: 40, height: 10 },
91+
);
92+
});
5993
});

‎src/tui/harness.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ export interface Harness {
119119
readonly flush: TestRendererSetup["flush"];
120120
readonly waitFor: TestRendererSetup["waitFor"];
121121
readonly waitForFrame: TestRendererSetup["waitForFrame"];
122+
readonly waitForVisualIdle: TestRendererSetup["waitForVisualIdle"];
123+
/** Recorded external stdout commits from the test renderer. */
124+
readonly externalOutput: TestRendererSetup["externalOutput"];
125+
readonly getNativeStats: TestRendererSetup["getNativeStats"];
122126
readonly captureCharFrame: () => string;
123127
readonly captureSpans: TestRendererSetup["captureSpans"];
124128
readonly resize: (width: number, height: number) => void;
@@ -196,6 +200,9 @@ export async function createHarness(
196200
flush: setup.flush,
197201
waitFor: setup.waitFor,
198202
waitForFrame: setup.waitForFrame,
203+
waitForVisualIdle: setup.waitForVisualIdle,
204+
externalOutput: setup.externalOutput,
205+
getNativeStats: setup.getNativeStats,
199206
captureCharFrame: setup.captureCharFrame,
200207
captureSpans: setup.captureSpans,
201208
resize: setup.resize,

0 commit comments

Comments
 (0)