Skip to content

Commit d21b6c4

Browse files
committed
fix(e2e): fillAndSubmitCommand now checks the stdout and stderr after the stdin if passed expectStdout or expectStderr
Avoids false positives
1 parent 92e3d49 commit d21b6c4

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

packages/web-host/src/components/ReplHistory.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export function ReplHistory({
2323
<pre
2424
className="bg-gray-50 whitespace-pre-wrap word-break-word"
2525
data-stdtype="stdin"
26+
data-std-index={index}
2627
>
2728
{entry.stdin}
2829
</pre>
@@ -31,6 +32,7 @@ export function ReplHistory({
3132
<pre
3233
className="bg-gray-50 whitespace-pre-wrap word-break-word"
3334
data-stdtype="stdin"
35+
data-std-index={index}
3436
// biome-ignore lint/security/noDangerouslySetInnerHtml: need to pass `allowHtml:true` to the addReplHistoryEntry function - only used for adding links to source of plugins when loaded
3537
dangerouslySetInnerHTML={{ __html: entry.stdin }}
3638
/>
@@ -40,6 +42,7 @@ export function ReplHistory({
4042
className="bg-green-100 whitespace-pre-wrap before:content-[attr(data-status)] relative before:absolute before:right-0 before:top-0 word-break-word"
4143
data-status={entry.status === "success" ? "✅" : "❌"}
4244
data-stdtype="stdout"
45+
data-std-index={index}
4346
>
4447
{entry.stdout}
4548
</pre>
@@ -49,6 +52,7 @@ export function ReplHistory({
4952
className="bg-red-100 whitespace-pre-wrap before:content-[attr(data-status)] relative before:absolute before:right-0 before:top-0 word-break-word"
5053
data-status={entry.status === "success" ? "✅" : "❌"}
5154
data-stdtype="stderr"
55+
data-std-index={index}
5256
>
5357
{entry.stderr}
5458
</pre>

packages/web-host/tests/utils.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { expect, type Page } from "@playwright/test";
1+
import { expect, type Locator, type Page } from "@playwright/test";
2+
3+
const NEXT_FRAME_DELAY = 64;
24

35
/**
46
* Get the last std output of the given type
@@ -10,6 +12,26 @@ export async function getLastStd(
1012
return await page.locator(`[data-stdtype='${type}']`).last();
1113
}
1214

15+
/**
16+
* Get the last std output of the given type after the given locator
17+
* This is useful to get the last std output after a command has been submitted
18+
* This ensures you don't have false positives when checking the last std output
19+
*/
20+
export async function getLastStdAfter(
21+
page: Page,
22+
type: "stdin" | "stdout" | "stderr",
23+
stdLocator: Locator,
24+
) {
25+
const stdinIndex = await stdLocator.getAttribute("data-std-index");
26+
return await page
27+
.locator(`[data-std-index='${stdinIndex}'] ~ [data-stdtype='${type}']`)
28+
.last();
29+
}
30+
31+
async function sleep(ms: number) {
32+
return new Promise((resolve) => setTimeout(resolve, ms));
33+
}
34+
1335
/**
1436
* Fill the input with the command and submit it
1537
* Pass the expected stdin, stdout and stderr to check the results
@@ -30,14 +52,15 @@ export async function fillAndSubmitCommand(
3052
const input = await page.getByPlaceholder("Type a command...");
3153
await input.fill(command);
3254
await input.press("Enter");
55+
await sleep(NEXT_FRAME_DELAY);
3356
const stdin = await getLastStd(page, "stdin");
3457
await expect(stdin).toHaveText(expectStdin);
3558
if (expectStdout) {
36-
const stdout = await getLastStd(page, "stdout");
59+
const stdout = await getLastStdAfter(page, "stdout", stdin);
3760
await expect(stdout).toHaveText(expectStdout);
3861
}
3962
if (expectStderr) {
40-
const stderr = await getLastStd(page, "stderr");
63+
const stderr = await getLastStdAfter(page, "stderr", stdin);
4164
await expect(stderr).toHaveText(expectStderr);
4265
}
4366
}

0 commit comments

Comments
 (0)