Skip to content

Commit 546049f

Browse files
authored
fix(repl-bench): wait directly for the next mounted reading (#1533)
1 parent 568d98a commit 546049f

4 files changed

Lines changed: 31 additions & 9 deletions

File tree

‎examples/repl-bench/journeys/repl-mounted.test.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
<Terminal.Type text="-after" />
2222
<Terminal.Region name="sidekick-composer">
2323
<Terminal.WaitForText text="mounted-marker-after" />
24+
<Terminal.Key key="Backspace" />
25+
<Terminal.Key key="Backspace" />
26+
<Terminal.Scroll pattern="." />
27+
<Terminal.WaitForText text="mounted-marker-aft" />
28+
<Terminal.WaitForText text="mounted-marker-afte" present={false} />
2429
</Terminal.Region>
2530
</XMD.Repl>
2631
</Terminal>

‎examples/repl-bench/lib/driver-mounted.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,7 @@ function* answer(page: ReplPage, command: Command, pendingInput: PendingInput):
131131
if (from !== undefined) {
132132
// Input clamped against a boundary can paint nothing, so the wait
133133
// for its frame is bounded rather than required.
134-
yield* race([
135-
page.until("the frame of a key or wheel burst", (one) => one.index > from),
136-
sleep(INPUT_FRAME_MS),
137-
]);
134+
yield* race([page.after(from), sleep(INPUT_FRAME_MS)]);
138135
}
139136
yield* sleep(command.ticks * command.tick);
140137
return null;

‎packages/cli/tests/repl-page.test.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import { beforeEach, describe, it } from "@executablemd/test-support/bdd";
1616
import { journalBeforeEach } from "@executablemd/test-support/failure-journal";
1717
import { expect } from "@executablemd/test-support/expect";
18+
import { spawn } from "effection";
1819
import type { Operation } from "effection";
1920

2021
import { useReplPage } from "./support/repl-page.ts";
@@ -198,11 +199,18 @@ describe("REPL page — resize, a modal, and writes that never land", () => {
198199
expect(page.screen().index).toBe(held);
199200
expect(page.screen().shows("held while writing")).toBe(false);
200201

202+
let resumed = false;
203+
const pending = yield* spawn(function* () {
204+
yield* page.after(held);
205+
resumed = true;
206+
});
207+
expect(resumed).toBe(false);
208+
201209
terminal.holdPresent?.release();
202-
const landed = yield* page.until("the held write landing", (one) =>
203-
one.shows("held while writing"),
204-
);
205-
expect(landed.index).toBeGreaterThan(held);
210+
yield* pending;
211+
expect(page.screen().index).toBeGreaterThan(held);
212+
expect(page.screen().shows("held while writing")).toBe(true);
213+
yield* page.after(held);
206214
});
207215
});
208216

‎packages/cli/tests/support/repl-page.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ export interface ReplPage {
153153
* deadline passes first.
154154
*/
155155
until(what: string, holds: (reading: ScreenReading) => boolean): Operation<ScreenReading>;
156+
/** Wait for the next captured reading after this index, or fail if the command ends. */
157+
after(index: number): Operation<void>;
156158
/** Press the pointer at the first cell of this label. Waits for nothing. */
157159
press(label: string, scope?: ScreenScope): Operation<void>;
158160
/** Send one named key. Waits for nothing. */
@@ -387,6 +389,16 @@ export function* useReplPage(
387389
return latest;
388390
};
389391

392+
function* after(index: number): Operation<void> {
393+
yield* next(index);
394+
if (count <= index && repl.terminal.ending !== undefined) {
395+
throw (
396+
repl.terminal.ending.failure ??
397+
new Error(`the command ended before the next reading. ${describe()}`)
398+
);
399+
}
400+
}
401+
390402
function* until(what: string, holds: (one: ScreenReading) => boolean): Operation<ScreenReading> {
391403
return yield* race([
392404
(function* (): Operation<ScreenReading> {
@@ -444,5 +456,5 @@ export function* useReplPage(
444456
(one) => one.shows("[exit]") || one.shows("needs at least"),
445457
);
446458

447-
return { repl, screen, until, press, key: sendKey, wheel, type, resize, describe };
459+
return { repl, screen, until, after, press, key: sendKey, wheel, type, resize, describe };
448460
}

0 commit comments

Comments
 (0)