From 047b904a0b876e4ad099883aeebaaf652e2c2657 Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 25 Oct 2024 09:33:50 +0100 Subject: [PATCH 01/32] set cypress to enable shared array buffers --- cypress.config.mjs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cypress.config.mjs b/cypress.config.mjs index 29e8c298e..aaad6c706 100644 --- a/cypress.config.mjs +++ b/cypress.config.mjs @@ -17,6 +17,13 @@ export default defineConfig({ return null; }, }); + on("before:browser:launch", (browser = {}, launchOptions) => { + if (browser.name === "chrome") { + launchOptions.args.push("--enable-features=SharedArrayBuffer"); + launchOptions.args.push("--disable-site-isolation-trials"); + } + return launchOptions; + }); }, retries: { runMode: 3, From b907e48d10cbdcde4156b987f38286dc79aad64a Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 25 Oct 2024 09:34:21 +0100 Subject: [PATCH 02/32] initialise codeRunLoading as true to stop the run button flashing before load --- src/redux/EditorSlice.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/redux/EditorSlice.js b/src/redux/EditorSlice.js index 8a73f4cc5..757fb8c8f 100644 --- a/src/redux/EditorSlice.js +++ b/src/redux/EditorSlice.js @@ -106,7 +106,7 @@ const initialState = { isSplitView: true, isThemeable: true, webComponent: false, - codeRunLoading: false, + codeRunLoading: true, codeRunStopped: false, projectList: [], projectListLoaded: "idle", From 20ea984caf2f79e435da73d917a391a3a0afac3b Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 25 Oct 2024 09:35:00 +0100 Subject: [PATCH 03/32] update pyodide tests to include headers and check for button states --- cypress/e2e/spec-wc-pyodide.cy.js | 35 ++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/cypress/e2e/spec-wc-pyodide.cy.js b/cypress/e2e/spec-wc-pyodide.cy.js index c9d3e51f9..5df5ae508 100644 --- a/cypress/e2e/spec-wc-pyodide.cy.js +++ b/cypress/e2e/spec-wc-pyodide.cy.js @@ -3,7 +3,6 @@ const origin = "http://localhost:3011/web-component.html"; beforeEach(() => { cy.intercept("*", (req) => { req.headers["Origin"] = origin; - req.continue(); }); }); @@ -13,12 +12,22 @@ const runCode = (code) => { .shadow() .find("div[class=cm-content]") .invoke("text", `${code}\n`); - cy.get("editor-wc").shadow().find(".btn--run").click(); + cy.get("editor-wc") + .shadow() + .find(".btn--run") + .should("not.be.disabled") + .click(); }; describe("Running the code with pyodide", () => { beforeEach(() => { - cy.visit(origin); + cy.visit({ + url: origin, + headers: { + "Cross-Origin-Opener-Policy": "same-origin", + "Cross-Origin-Embedder-Policy": "require-corp", + }, + }); cy.window().then((win) => { Object.defineProperty(win, "crossOriginIsolated", { value: true, @@ -39,21 +48,33 @@ describe("Running the code with pyodide", () => { runCode( "from time import sleep\nfor i in range(100):\n\tprint(i)\n\tsleep(1)", ); - cy.get("editor-wc").shadow().find(".btn--stop").click(); + cy.get("editor-wc") + .shadow() + .find(".pythonrunner-console-output-line") + .should("contain", "3"); + cy.get("editor-wc") + .shadow() + .find(".btn--stop") + .should("be.visible") + .click(); cy.get("editor-wc") .shadow() .find(".error-message__content") .should("contain", "Execution interrupted"); }); - // skip this test for now until we get the headers set up - it.skip("runs a simple program with an input", () => { + it("runs a simple program with an input", () => { runCode('name = input("What is your name?")\nprint("Hello", name)'); + cy.get("editor-wc").shadow().find(".btn--stop").should("be.visible"); cy.get("editor-wc") .shadow() .find(".pythonrunner-console-output-line") .should("contain", "What is your name?"); - cy.get("editor-wc").shadow().find("#input").invoke("text", "Lois{enter}"); + cy.get("editor-wc") + .shadow() + .find("#input") + .should("be.visible") + .type("Lois{enter}"); cy.get("editor-wc") .shadow() .find(".pythonrunner-console-output-line") From 11ee4f36dcc73a6e0972cdb71e38d462a7acfab2 Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 25 Oct 2024 09:47:15 +0100 Subject: [PATCH 04/32] alter initial codeRunLoading state and toggle true when a pyodideWorker is initialised --- .../Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx | 2 ++ src/redux/EditorSlice.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx b/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx index 8bb232feb..dd754e851 100644 --- a/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx +++ b/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx @@ -63,6 +63,8 @@ const PyodideRunner = (props) => { useEffect(() => { if (pyodideWorker) { + // initialise as loading + handleLoading(); pyodideWorker.onmessage = ({ data }) => { switch (data.method) { case "handleLoading": diff --git a/src/redux/EditorSlice.js b/src/redux/EditorSlice.js index 757fb8c8f..8a73f4cc5 100644 --- a/src/redux/EditorSlice.js +++ b/src/redux/EditorSlice.js @@ -106,7 +106,7 @@ const initialState = { isSplitView: true, isThemeable: true, webComponent: false, - codeRunLoading: true, + codeRunLoading: false, codeRunStopped: false, projectList: [], projectListLoaded: "idle", From 263cc73734ea3197c5de950e659827a97f11c3d0 Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 25 Oct 2024 09:49:47 +0100 Subject: [PATCH 05/32] CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73b8ca178..75ed4ce3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased +### Fixed + +- Fixed pyodide input test and cypress config to enable further pyodide tests (#1125) + ## [0.28.4] - 2024-10-23 ### Added From dd997c80b8f5af550561c352912f4bddd3b5b0db Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 25 Oct 2024 13:00:38 +0100 Subject: [PATCH 06/32] ci(cypress): not sure why the browers options aren't working in actions --- .github/workflows/ci-cd.yml | 1 + cypress.config.mjs | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 8f0a5f4b1..853c4f644 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -95,6 +95,7 @@ jobs: yarn start wait-on: "http://localhost:3011" quiet: true + config-file: cypress.config.mjs env: REACT_APP_API_ENDPOINT: "https://test-editor-api.raspberrypi.org" PUBLIC_URL: "http://localhost:3011" diff --git a/cypress.config.mjs b/cypress.config.mjs index aaad6c706..f288ea033 100644 --- a/cypress.config.mjs +++ b/cypress.config.mjs @@ -19,6 +19,7 @@ export default defineConfig({ }); on("before:browser:launch", (browser = {}, launchOptions) => { if (browser.name === "chrome") { + console.log("Applying Chrome launch options"); launchOptions.args.push("--enable-features=SharedArrayBuffer"); launchOptions.args.push("--disable-site-isolation-trials"); } From 44b205639ae8c7c45167096819a7cddd079cbc9b Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 25 Oct 2024 15:56:12 +0100 Subject: [PATCH 07/32] fix enigma warning --- src/PyodideWorker.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PyodideWorker.js b/src/PyodideWorker.js index 216fb8d25..b50981742 100644 --- a/src/PyodideWorker.js +++ b/src/PyodideWorker.js @@ -165,6 +165,7 @@ const PyodideWorker = () => { `${process.env.ASSETS_URL}/pyodide/packages/py_enigma-0.1-py3-none-any.whl`, ); }, + after: () => {}, }, turtle: { before: async () => { From de687398ecf9fd6bcdcdc45d63ae93cd52c1d11f Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 25 Oct 2024 15:56:32 +0100 Subject: [PATCH 08/32] split out runner loading and loader states --- src/redux/EditorSlice.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/redux/EditorSlice.js b/src/redux/EditorSlice.js index 8a73f4cc5..37158403a 100644 --- a/src/redux/EditorSlice.js +++ b/src/redux/EditorSlice.js @@ -106,6 +106,8 @@ const initialState = { isSplitView: true, isThemeable: true, webComponent: false, + activeRunner: null, + loadedRunner: null, codeRunLoading: false, codeRunStopped: false, projectList: [], @@ -296,7 +298,17 @@ export const EditorSlice = createSlice({ stopDraw: (state) => { state.drawTriggered = false; }, - loadingRunner: (state) => { + loadingRunner: (state, action) => { + state.activeRunner = action.payload; + state.codeRunLoading = true; + }, + loadedRunner: (state, action) => { + state.loadedRunner = action.payload; + state.codeRunLoading = false; + }, + resetRunner: (state) => { + state.activeRunner = null; + state.loadedRunner = null; state.codeRunLoading = true; }, codeRunHandled: (state) => { @@ -466,6 +478,8 @@ export const EditorSlice = createSlice({ export const { addProjectComponent, loadingRunner, + loadedRunner, + resetRunner, codeRunHandled, expireJustLoaded, closeFile, From 6966c567c34621d629258ebfc1a96feeb4e8e6d9 Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 25 Oct 2024 15:58:22 +0100 Subject: [PATCH 09/32] disable run button based on runner loading states --- src/components/RunButton/RunButton.jsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/RunButton/RunButton.jsx b/src/components/RunButton/RunButton.jsx index 2b6717697..4034284f0 100644 --- a/src/components/RunButton/RunButton.jsx +++ b/src/components/RunButton/RunButton.jsx @@ -6,6 +6,8 @@ import { triggerCodeRun } from "../../redux/EditorSlice"; const RunButton = ({ embedded = false, className, ...props }) => { const codeRunLoading = useSelector((state) => state.editor.codeRunLoading); + const activeRunner = useSelector((state) => state.editor.activeRunner); + const loadedRunner = useSelector((state) => state.editor.loadedRunner); const dispatch = useDispatch(); const onClickRun = () => { @@ -17,7 +19,9 @@ const RunButton = ({ embedded = false, className, ...props }) => { return (