Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Pyodide input test #1125

Merged
merged 38 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
047b904
set cypress to enable shared array buffers
sra405 Oct 25, 2024
b907e48
initialise codeRunLoading as true to stop the run button flashing bef…
sra405 Oct 25, 2024
20ea984
update pyodide tests to include headers and check for button states
sra405 Oct 25, 2024
11ee4f3
alter initial codeRunLoading state and toggle true when a pyodideWork…
sra405 Oct 25, 2024
263cc73
CHANGELOG
sra405 Oct 25, 2024
dd997c8
ci(cypress): not sure why the browers options aren't working in actions
sra405 Oct 25, 2024
44b2056
fix enigma warning
sra405 Oct 25, 2024
de68739
split out runner loading and loader states
sra405 Oct 25, 2024
6966c56
disable run button based on runner loading states
sra405 Oct 25, 2024
50f1ef2
html loads instantly so dispatch on first render
sra405 Oct 25, 2024
31b412f
start with no python runner and determine logically
sra405 Oct 25, 2024
ce00c2d
only load pyodideWorker when needed and set loaded state when complete
sra405 Oct 25, 2024
93c993a
set skulpt loading state when active
sra405 Oct 25, 2024
8b781d1
set ci cypress browser to chrome
sra405 Oct 25, 2024
fdafd90
Merge branch 'main' into enable-pyodide-input-test
sra405 Oct 25, 2024
d7c6093
remove showRunner logic now active logic has altered slightly
sra405 Oct 28, 2024
cd5b6dc
update wc cypress tests
sra405 Oct 28, 2024
ceee145
fix skulpt/pyodide active states
sra405 Oct 28, 2024
7556fa3
rename loadedRunner action to avoid state name clash
sra405 Oct 29, 2024
0e6cdc9
cypress mission zero ensuring tests don't implicitly test other funct…
sra405 Oct 29, 2024
59d518d
py-enigma cypress test
sra405 Oct 29, 2024
2c495f4
cypress pyodide remove the only
sra405 Oct 29, 2024
01e3261
cypress skulpt ensure run button is not disabled i.e. runner is loaded
sra405 Oct 29, 2024
cb62537
default visual output to true in skulpt
sra405 Oct 29, 2024
0f14693
default skulpt to visual due to common use cases but toggle off if no…
sra405 Oct 29, 2024
cab4888
sure up cypress testing
sra405 Oct 29, 2024
dcbb907
remove only's again :facepalm:
sra405 Oct 29, 2024
3e51d8b
testing and code tidy up
sra405 Oct 29, 2024
9d2f148
Merge branch 'main' into enable-pyodide-input-test
sra405 Oct 29, 2024
177e048
almost fixed all the python runner and pyodideWorker related unit tests
sra405 Oct 31, 2024
eeb3af8
Merge branch 'main' into enable-pyodide-input-test
sra405 Nov 4, 2024
fc56f2f
initial review changes
sra405 Nov 4, 2024
cc38ef7
PyodideRunner.test - fix postMessage based failures... waitFor AGAIN!
sra405 Nov 5, 2024
0fa70bf
PyodideRunner.test - fix remaining fetch/arraybuffer tests
sra405 Nov 5, 2024
1ee0203
Merge branch 'main' into enable-pyodide-input-test
sra405 Nov 6, 2024
f8eab09
Merge branch 'main' into enable-pyodide-input-test
sra405 Nov 7, 2024
534bbd9
Merge branch 'main' into enable-pyodide-input-test
sra405 Nov 11, 2024
576f140
fix(pythonrunner-active-styles-+-skulpt-visual-state): pr review comm…
sra405 Nov 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ jobs:
yarn start
wait-on: "http://localhost:3011"
quiet: true
config-file: cypress.config.mjs
browser: chrome
env:
REACT_APP_API_ENDPOINT: "https://test-editor-api.raspberrypi.org"
PUBLIC_URL: "http://localhost:3011"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Fixed

- Fixed pyodide input test and cypress config to enable further pyodide tests (#1125)
- Image sizing and wrapping in the sidebar (#1126)

## [0.28.4] - 2024-10-23
Expand Down
8 changes: 8 additions & 0 deletions cypress.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ export default defineConfig({
return null;
},
});
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");
danhalson marked this conversation as resolved.
Show resolved Hide resolved
}
return launchOptions;
});
},
retries: {
runMode: 3,
Expand Down
22 changes: 15 additions & 7 deletions cypress/e2e/missionZero-wc.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,23 @@ it("picks up calls to input()", () => {
cy.get("editor-wc")
.shadow()
.find("div[class=cm-content]")
.invoke("text", "input()");
.invoke("text", "name = input('What is your name?')\nprint('Hello', name)");
cy.get("editor-wc").shadow().find(".btn--run").click();
cy.get("editor-wc").shadow().find(".btn--stop").should("be.visible");
cy.get("editor-wc")
.shadow()
.find(
"div[class='pythonrunner-container skulptrunner skulptrunner--active']",
)
.contains("Text output")
.find("div.pythonrunner-container.skulptrunner.skulptrunner--active")
.contains(".react-tabs__tab-text", "Text output")
.click();
cy.get("editor-wc")
.shadow()
.find("span[contenteditable=true]")
.type("{enter}");
.type("Scott{enter}");
cy.get("#results").should("contain", '"noInputEvents":false');
cy.get("editor-wc")
.shadow()
.find(".pythonrunner-console-output-line")
.should("contain", "Hello Scott");
});

it("picks up calls to wait for motion", () => {
Expand Down Expand Up @@ -208,7 +211,12 @@ it("returns duration of null if focus is lost", () => {
"text",
'from sense_hat import SenseHat\nsense = SenseHat()\nsense.show_message("a")',
);
cy.get("editor-wc").shadow().find(".btn--run").click();
cy.get("editor-wc")
.shadow()
.find(".btn--run")
.should("not.be.disabled")
.click();
cy.get("editor-wc").shadow().find(".btn--stop").should("be.visible");
cy.window().blur();
cy.window().focus();
cy.get("#results").should("contain", '"duration":null');
Expand Down
73 changes: 66 additions & 7 deletions cypress/e2e/spec-wc-pyodide.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const origin = "http://localhost:3011/web-component.html";
beforeEach(() => {
cy.intercept("*", (req) => {
req.headers["Origin"] = origin;
req.continue();
});
});

Expand All @@ -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,
Expand All @@ -29,6 +38,16 @@ describe("Running the code with pyodide", () => {

it("runs a simple program", () => {
runCode('print("Hello world")');
cy.get("editor-wc")
.shadow()
.find(".pyodiderunner")
.contains(".react-tabs__tab", "Visual output")
.should("not.exist");
cy.get("editor-wc")
.shadow()
.find(".pyodiderunner")
.find(".react-tabs__tab--selected")
.should("contain", "Text output");
cy.get("editor-wc")
.shadow()
.find(".pythonrunner-console-output-line")
Expand All @@ -39,21 +58,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")
Expand Down Expand Up @@ -133,6 +164,34 @@ describe("Running the code with pyodide", () => {
.should("contain", "4");
});

it("runs a simple program with the py-enigma library", () => {
runCode(
`
from enigma.machine import EnigmaMachine
# Sheet settings
ROTORS = "IV I V"
RINGS = "20 5 10"
PLUGBOARD = "KT AJ IV US NY HL GD XF PB CQ"
def use_enigma_machine(msg, rotor_start):
# Set up the Enigma machine
machine = EnigmaMachine.from_key_sheet(rotors=ROTORS, reflector="B", ring_settings=RINGS, plugboard_settings=PLUGBOARD)
# Set the initial position of the rotors
machine.set_display(rotor_start)
# Encrypt or decrypt the message
transformed_msg = machine.process_text(msg)
return(transformed_msg)
text_in = "This is a test message"
rotor_start = "FNZ"
text_out = use_enigma_machine(text_in, rotor_start)
print(text_out)
`,
);
cy.get("editor-wc")
.shadow()
.find(".pythonrunner-console-output-line")
.should("contain", "ULRYQJMVHLFQKBEFUGEOFL");
});

it("errors when importing a non-existent module", () => {
runCode("import i_do_not_exist");
cy.get("editor-wc")
Expand Down
34 changes: 33 additions & 1 deletion cypress/e2e/spec-wc-skulpt.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ const runCode = (code) => {
.find("div[class=cm-content]")
.invoke("text", `${code}\n`);
cy.wait(200);
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 skulpt", () => {
Expand All @@ -28,10 +32,38 @@ describe("Running the code with skulpt", () => {
});
});

it("runs a simple program", () => {
runCode("print('Hello world')");
cy.get("editor-wc")
.shadow()
.find(".skulptrunner")
.contains(".react-tabs__tab", "Visual output")
.should("not.exist");
cy.get("editor-wc")
.shadow()
.find(".skulptrunner")
.find(".react-tabs__tab--selected")
.should("contain", "Text output");
cy.get("editor-wc")
.shadow()
.find(".pythonrunner-console-output-line")
.should("contain", "Hello world");
});

it("runs a simple p5 program", () => {
runCode(
"from p5 import *\n\ndef setup():\n\tsize(400, 400)\ndef draw():\n\tfill('cyan')\n\trect(0, 0, 400, 250)\nrun(frame_rate=2)",
);
cy.get("editor-wc")
.shadow()
.find(".skulptrunner")
.contains(".react-tabs__tab", "Text output")
.should("exist");
cy.get("editor-wc")
.shadow()
.find(".skulptrunner")
.find(".react-tabs__tab--selected")
.should("contain", "Visual output");
cy.get("editor-wc").shadow().find(".p5Canvas").should("exist");
});

Expand Down
10 changes: 9 additions & 1 deletion cypress/e2e/spec-wc.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,18 @@ describe("when embedded, output_only & output_split_view are true", () => {

// Check text output panel is visible and has a run button
// Important to wait for this before making the negative assertions that follow
cy.get("editor-wc").shadow().contains("Text output").should("be.visible");
const runnerContainer = cy
.get("editor-wc")
.shadow()
.find(".proj-runner-container");
runnerContainer
.find(".react-tabs__tab--selected")
.should("contain", "Text output");
cy.get("editor-wc")
.shadow()
.find("button")
.contains("Run")
.should("not.be.disabled")
.should("be.visible");

// Check that the side bar is not displayed
Expand Down Expand Up @@ -160,6 +167,7 @@ describe("when embedded, output_only & output_split_view are true", () => {
.shadow()
.find("button")
.contains("Run")
.should("not.be.disabled")
.should("be.visible");

// Check that the code has automatically run i.e. the HTML has been rendered
Expand Down
16 changes: 16 additions & 0 deletions src/assets/stylesheets/PythonRunner.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@
position: relative;
}

.pyodiderunner {
display: none;

&--active {
display: flex;
}
}

.skulptrunner {
display: none;

&--active {
display: flex;
}
}

.visual-output {
flex: 1;
display: flex;
Expand Down
4 changes: 4 additions & 0 deletions src/components/Editor/Runners/HtmlRunner/HtmlRunner.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
showErrorModal,
codeRunHandled,
triggerCodeRun,
loadingRunner,
setLoadedRunner,
} from "../../../../redux/EditorSlice";

import {
Expand Down Expand Up @@ -166,6 +168,8 @@ function HtmlRunner() {

useEffect(() => {
eventListener();
dispatch(loadingRunner("html"));
dispatch(setLoadedRunner("html"));
}, []);

let timeout;
Expand Down
Loading
Loading