@samitouri / QOS-React / commits / 9cdd6b243e

Fix playground e2e test

ghstack-source-id: 3904ff9beea21ffbb79a6a15fcfbb72f04a2d170 Pull Request resolved: https://github.com/facebook/react-forget/pull/2842

Lauren Tan committed Apr 10, 2024 at 18:17 UTC 9cdd6b243e8e633c4322424cd4b963e03819b1f9
3 files changed +34 -9
compiler/apps/playground/__tests__/e2e/__snapshots__/page.spec.ts/default-input.txt renamed
compiler/apps/playground/__tests__/e2e/__snapshots__/page.spec.ts/user-input.txt new
+13
@@ -0,0 +1,13 @@
1 +function TestComponent(t0) {
2 +  const $ = useMemoCache(2);
3 +  const { x } = t0;
4 +  let t1;
5 +  if ($[0] !== x) {
6 +    t1 = <Button>{x}</Button>;
7 +    $[0] = x;
8 +    $[1] = t1;
9 +  } else {
10 +    t1 = $[1];
11 +  }
12 +  return t1;
13 +}
\ No newline at end of file
compiler/apps/playground/__tests__/e2e/page.spec.ts
+21 -9
@@ -7,18 +7,30 @@
7
8 import { expect, test } from "@playwright/test";
9
10 +const delay = 50;
11 +
12 +function concat(data: Array<string>): string {
13 + return data.join("");
14 +}
15 +
16 test("editor should compile successfully", async ({ page }) => {
17 await page.goto("/", { waitUntil: "networkidle" });
18
13 - page.on("dialog", (dialog) => dialog.accept());
14 - await page.getByRole("button", { name: "Wipe" }).click();
19 + // User input compiles
20 + const monacoEditor = page.locator(".monaco-editor").nth(0);
21 + await monacoEditor.click();
22 + await page.keyboard.press("Meta+KeyA", { delay });
23 + await page.keyboard.type("export default function TestComponent({ x }) {\n");
24 + await page.keyboard.type("return <Button>{x}</Button>;\n");
25 await page.getByRole("button", { name: /JS/ }).click();
16 - const results =
26 + const userInput =
27 + (await page.locator(".monaco-editor").nth(2).allInnerTexts()) ?? [];
28 + expect(concat(userInput)).toMatchSnapshot("user-input.txt");
29 +
30 + // Reset button works
31 + page.on("dialog", (dialog) => dialog.accept());
32 + await page.getByRole("button", { name: "Reset" }).click();
33 + const defaultInput =
34 (await page.locator(".monaco-editor").nth(2).allInnerTexts()) ?? [];
18 - expect(
19 - results.reduce((buffer, str) => {
20 - buffer.concat(str);
21 - return buffer;
22 - }),
23 - ).toMatchSnapshot("results.txt");
35 + expect(concat(defaultInput)).toMatchSnapshot("default-input.txt");
36 });