Merge pull request #8909 from uinstinct/retry-cli-tests
fix(cli): wait for tui to update in test
This commit is contained in:
commit
c1c885e8ca
1 changed files with 25 additions and 4 deletions
|
|
@ -1,4 +1,18 @@
|
|||
import { testBothModes, renderInMode } from "./TUIChat.dualModeHelper.js";
|
||||
import { renderInMode, testBothModes } from "./TUIChat.dualModeHelper.js";
|
||||
|
||||
async function waitForCondition(
|
||||
conditionFn: () => boolean,
|
||||
timeoutMs = 2000,
|
||||
intervalMs = 50,
|
||||
): Promise<void> {
|
||||
const startTime = Date.now();
|
||||
while (Date.now() - startTime < timeoutMs) {
|
||||
if (conditionFn()) {
|
||||
return;
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Integration tests for the message edit feature in TUIChat
|
||||
|
|
@ -10,7 +24,6 @@ import { testBothModes, renderInMode } from "./TUIChat.dualModeHelper.js";
|
|||
* 4. History is rewound and new message is submitted
|
||||
* 5. Chat updates correctly
|
||||
*/
|
||||
|
||||
describe("TUIChat - Message Edit Feature", () => {
|
||||
testBothModes("double Esc should open edit selector", async (mode) => {
|
||||
const { lastFrame, stdin } = renderInMode(mode);
|
||||
|
|
@ -119,7 +132,11 @@ describe("TUIChat - Message Edit Feature", () => {
|
|||
// Perform various operations
|
||||
stdin.write("\u001b");
|
||||
stdin.write("\u001b"); // Open edit with separate Esc presses
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
// Wait for selector to open (poll instead of fixed timeout)
|
||||
await waitForCondition(
|
||||
() => lastFrame()?.includes("No user messages to edit") ?? false,
|
||||
);
|
||||
|
||||
// Verify selector opened
|
||||
let frame = lastFrame();
|
||||
|
|
@ -130,7 +147,11 @@ describe("TUIChat - Message Edit Feature", () => {
|
|||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
|
||||
stdin.write("\u001b"); // Close
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
// Wait for selector to close (poll instead of fixed timeout)
|
||||
await waitForCondition(
|
||||
() => !(lastFrame()?.includes("No user messages to edit") ?? true),
|
||||
);
|
||||
|
||||
frame = lastFrame();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue