Skip to content

Commit dfc4cdc

Browse files
authored
fix(playground): Update Vite config to handle Babel's CJS default export (#1245)
* fix(playground): Update Vite config to handle Babel's CJS default export * Add Playground E2E test and typeWithOptions binding - Add e2e/Playground.cy.res with a test for compiling and running code - Add typeWithOptions binding to Cy.res for typing with options - Rename Navigation_.cy.res to Navigation.cy.res for consistency
1 parent 08487ac commit dfc4cdc

4 files changed

Lines changed: 71 additions & 0 deletions

File tree

e2e/Playground.cy.res

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
open Cy
2+
3+
let waitForHydration = () => {
4+
getByTestId("navbar-primary")->shouldBeVisible->ignore
5+
cyWindow()->its("document.readyState")->shouldWithValue("eq", "complete")->ignore
6+
wait(2000)
7+
}
8+
9+
let waitForPlayground = () => {
10+
get(".cm-editor")->should("be.visible")->ignore
11+
getByTestId("control-panel")->should("be.visible")->ignore
12+
wait(2000)
13+
}
14+
15+
let clickNavLink = (~testId, ~text) => {
16+
get(`[data-testid="${testId}"] a:visible`)
17+
->containsChainable(text)
18+
->click
19+
->ignore
20+
}
21+
22+
describe("Playground", () => {
23+
beforeEach(() => {
24+
viewport(1280, 720)
25+
visit("/")
26+
waitForHydration()
27+
})
28+
29+
it("should compile and run Console.log in the playground", () => {
30+
// Navigate to the playground from the homepage
31+
clickNavLink(~testId="navbar-primary-left-content", ~text="Playground")
32+
url()->shouldInclude("/try")->ignore
33+
34+
// Wait for the playground editor and compiler to fully load
35+
waitForPlayground()
36+
37+
// Clear all existing code and type new ReScript source
38+
get(".cm-content")
39+
->typeWithOptions(
40+
"{selectall}{backspace}Console.log(\"Hello ReScript!\")",
41+
{"force": true, "delay": 20},
42+
)
43+
->ignore
44+
45+
// Allow time for the compiler to process
46+
wait(3000)
47+
48+
// Switch to the JavaScript tab and verify compiled output
49+
contains("JavaScript")->click->ignore
50+
get("pre.whitespace-pre-wrap")
51+
->shouldContainText("console.log")
52+
->ignore
53+
54+
// Click the Run button in the control panel
55+
getByTestId("control-panel")
56+
->find("button")
57+
->containsChainable("Run")
58+
->click
59+
->ignore
60+
61+
// The Run button auto-switches to the Output tab.
62+
// Verify the console output panel contains the logged text.
63+
get("div.whitespace-pre-wrap pre")
64+
->shouldContainText("Hello ReScript!")
65+
->ignore
66+
})
67+
})

e2e/bindings/Cy.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ external log: string => unit = "log"
7272
@send external clickWithOptions: (t, {..}) => t = "click"
7373
@send external dblclick: t => t = "dblclick"
7474
@send external type_: (t, string) => t = "type"
75+
@send external typeWithOptions: (t, string, {..}) => t = "type"
7576
@send external clear: t => t = "clear"
7677
@send external check: t => t = "check"
7778
@send external uncheck: t => t = "uncheck"

vite.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ export default defineConfig({
4040
exclude: ["node_modules/.vite/deps/*.js"],
4141
},
4242
assetsInclude: ["**/resources.json"],
43+
legacy: {
44+
inconsistentCjsInterop: true,
45+
},
4346
});

0 commit comments

Comments
 (0)