Skip to content

Commit 327c2ca

Browse files
committed
Fix text poster rendering when preload=true
1 parent 7a34041 commit 327c2ca

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

src/core.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ class Core {
345345
this.play();
346346
} else if (this.poster.type === "text") {
347347
this._feed(this.poster.value);
348+
this.needsClear = true;
348349
}
349350
}
350351

@@ -508,8 +509,11 @@ class Core {
508509
this._initializeVt(this.cols, this.rows);
509510

510511
if (meta.poster !== undefined) {
511-
this.needsClear = true;
512512
meta.poster.forEach((text) => this.vt.feed(text));
513+
this.needsClear = true;
514+
} else if (this.poster.type === "text") {
515+
this.vt.feed(this.poster.value);
516+
this.needsClear = true;
513517
}
514518

515519
this._dispatchEvent("metadata", {
@@ -579,7 +583,6 @@ class Core {
579583
this.vt = this.wasm.create(cols, rows, 100, this.boldIsBright);
580584
this.vt.cols = cols;
581585
this.vt.rows = rows;
582-
583586
}
584587

585588
_parsePoster(poster) {

tests/player.spec.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,37 @@ test("explicit theme", async ({ page }) => {
399399
}
400400
});
401401

402+
test("poster - npt", async ({ page }) => {
403+
await createPlayer(page, "/assets/long.cast", {
404+
poster: "npt:7",
405+
});
406+
407+
await page.waitForTimeout(500);
408+
409+
await expectTermText(page, ["start", "one", "six"]);
410+
});
411+
412+
test("poster - data:text/plain", async ({ page }) => {
413+
await createPlayer(page, "/assets/long.cast", {
414+
poster: "data:text/plain,hello world",
415+
});
416+
417+
await page.waitForTimeout(500);
418+
419+
await expectTermText(page, "hello world");
420+
});
421+
422+
test("poster - data:text/plain - with preload", async ({ page }) => {
423+
await createPlayer(page, "/assets/long.cast", {
424+
poster: "data:text/plain,hello world",
425+
preload: true,
426+
});
427+
428+
await page.waitForTimeout(500);
429+
430+
await expectTermText(page, "hello world");
431+
});
432+
402433
const PLAYER_EVENTS = ["play", "playing", "pause", "ended", "input", "marker"];
403434

404435
async function createPlayer(page, src, opts = {}) {
@@ -511,6 +542,22 @@ function expectTermSize(terminal, cols, rows) {
511542
.toEqual({ cols, rows });
512543
}
513544

545+
async function expectTermText(page, fragments, timeout = 1000) {
546+
const termText = page.locator(".ap-term-text");
547+
await termText.waitFor();
548+
const expected = Array.isArray(fragments) ? fragments : [fragments];
549+
550+
await expect
551+
.poll(
552+
async () => {
553+
const text = await termText.innerText();
554+
return expected.every((fragment) => text.includes(fragment));
555+
},
556+
{ timeout },
557+
)
558+
.toBe(true);
559+
}
560+
514561
async function clickProgressBar(page, position) {
515562
const bar = page.locator(".ap-bar");
516563
await bar.waitFor();

0 commit comments

Comments
 (0)