Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 43 additions & 2 deletions cypress/e2e/spec-wc-pyodide.cy.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import {
ensureFilePanelOpen,
getEditorShadow,
getErrorLine,
getErrorMessage,
getFriendlyErrorMessage,
getFileButtonByName,
getFriendlyErrorMessage,
getInputPanel,
getOutputPanel,
getProgramInput,
getPyodideOutput,
getPythonConsoleOutput,
getRunButton,
getTextOutputTab,
makeNewFile,
ensureFilePanelOpen,
runCode,
runProject,
setCodeEditorContent,
Expand Down Expand Up @@ -41,6 +44,14 @@ describe("Running the code with pyodide", () => {
});
});

it("shows errors in the input panel and not the output panel", () => {
runCode("print(a)");
getInputPanel()
.find(".error-message__python")
.should("contain", "NameError");
getOutputPanel().find(".error-message").should("not.exist");
});

it("runs a simple program", () => {
runCode('print("Hello world")');
getPyodideOutput().should("not.contain.text", "Visual output");
Expand Down Expand Up @@ -352,3 +363,33 @@ describe("When friendly errors enabled with pyodide", () => {
);
});
});

describe("Running the code with pyodide in an output-only embed", () => {
beforeEach(() => {
const params = new URLSearchParams();
params.set("code", "print(a)");
params.set("embedded", "true");
params.set("output_only", "true");
cy.visit({
url: `${origin}?${params.toString()}`,
headers: {
"Cross-Origin-Opener-Policy": "same-origin",
"Cross-Origin-Embedder-Policy": "require-corp",
},
});
cy.window().then((win) => {
Object.defineProperty(win, "crossOriginIsolated", {
value: true,
configurable: true,
});
});
});

it("shows the error in the output panel", () => {
getRunButton().should("not.be.disabled");
runProject();
getPyodideOutput()
.find(".error-message__python")
.should("contain", "NameError");
});
});
71 changes: 71 additions & 0 deletions cypress/e2e/spec-wc-skulpt.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import {
getErrorLine,
getErrorMessage,
getFriendlyErrorMessage,
getInputPanel,
getMobileTab,
getOutputPanel,
getP5Canvas,
getPythonConsoleOutput,
getRunButton,
getSkulptRunner,
getSkulptTabByName,
getTurtleOutput,
runCode,
runProject,
stopProject,
} from "../helpers/editor.js";

Expand All @@ -31,6 +36,14 @@ describe("Running the code with skulpt", () => {
});
});

it("shows errors in the input panel and not the output panel", () => {
runCode("print(a)");
getInputPanel()
.find(".error-message__python")
.should("contain", "NameError");
getOutputPanel().find(".error-message").should("not.exist");
});

it("runs a simple program", () => {
runCode("print('Hello world')");

Expand Down Expand Up @@ -232,3 +245,61 @@ describe("When friendly errors enabled with skulpt", () => {
);
});
});

describe("Running the code with skulpt on mobile", () => {
beforeEach(() => {
cy.viewport(400, 800);
cy.visit(origin);
cy.window().then((win) => {
Object.defineProperty(win, "crossOriginIsolated", {
value: false,
configurable: true,
});
});
});

it("switches to the code tab when an error occurs", () => {
runCode("print(a)");
getMobileTab("Code").should("have.attr", "aria-selected", "true");
getInputPanel()
.find(".error-message__python")
.should("be.visible")
.and("contain", "NameError");
});
});

describe("Running the code with skulpt in an output-only embed", () => {
const urlFor = (splitView) => {
const params = new URLSearchParams();
params.set("code", "import turtle\nprint(a)");
params.set("embedded", "true");
params.set("output_only", "true");
params.set("output_split_view", splitView);
return `${origin}?${params.toString()}`;
};

const visitAndRun = (splitView) => {
cy.visit(urlFor(splitView));
cy.window().then((win) => {
Object.defineProperty(win, "crossOriginIsolated", {
value: false,
configurable: true,
});
});
getRunButton().should("not.be.disabled");
runProject();
cy.get("#results").should("contain", "NameError");
};

it("shows the error in the output panel in split view", () => {
visitAndRun("true");
getSkulptRunner()
.find(".error-message__python")
.should("contain", "NameError");
});

it("does not show the error in tabbed view", () => {
visitAndRun("false");
getSkulptRunner().find(".error-message").should("not.exist");
});
});
9 changes: 9 additions & 0 deletions cypress/helpers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ export const getTurtleOutput = () => getEditorShadow().find("#turtleOutput");
export const getErrorMessage = () =>
getEditorShadow().find(".error-message__python");

export const getInputPanel = () =>
getEditorShadow().findByRole("region", { name: "Input panel" });

export const getOutputPanel = () =>
getEditorShadow().findByRole("region", { name: "Output panel" });

export const getMobileTab = (name) =>
getEditorShadow().find(".mobile-nav").contains('[role="tab"]', name);

export const getErrorLine = () => getEditorShadow().find(".cm-error-line");

export const getFriendlyErrorMessage = () =>
Expand Down
6 changes: 6 additions & 0 deletions src/assets/stylesheets/EditorInput.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
inline-size: 100%;
}

.editor-input .error-message {
box-sizing: border-box;
flex-shrink: 0;
max-block-size: 50%;
}

.editor-input__view-only-banner {
font-weight: var(--font-weight-bold);
padding: var(--space-0-5) var(--space-1);
Expand Down
4 changes: 4 additions & 0 deletions src/assets/stylesheets/RunBar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
flex-direction: row;
justify-content: flex-end;
padding: var(--space-1);

.runner-controls {
padding: 0;
}
}

.--light {
Expand Down
5 changes: 5 additions & 0 deletions src/components/Editor/EditorInput/EditorInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import EditorPanel from "../EditorPanel/EditorPanel";
import DraggableTab from "../DraggableTabs/DraggableTab";
import DroppableTabList from "../DraggableTabs/DroppableTabList";
import RunBar from "../../RunButton/RunBar";
import ErrorMessage from "../ErrorMessage/ErrorMessage";

import "../../../assets/stylesheets/EditorInput.scss?inline";
import RunnerControls from "../../RunButton/RunnerControls";
Expand All @@ -31,6 +32,7 @@ const EditorInput = () => {
const dispatch = useDispatch();
const isMobile = useMediaQuery({ query: MOBILE_MEDIA_QUERY });
const readOnly = useSelector((state) => state.editor.readOnly);
const isPythonProject = project?.project_type !== "html";

const [numberOfComponents, setNumberOfComponents] = useState(
project?.components?.length,
Expand Down Expand Up @@ -186,6 +188,9 @@ const EditorInput = () => {
/>
</TabPanel>
))}
{isPythonProject && panelIndex === openFiles.length - 1 && (
<ErrorMessage />
)}
{isMobile ? null : <RunBar />}
</Tabs>
))}
Expand Down
30 changes: 30 additions & 0 deletions src/components/Editor/EditorInput/EditorInput.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,36 @@ describe("When not read only", () => {
});
});

describe("Error message", () => {
test("Shows error inside the input panel, above the run bar", () => {
setMedia({ width: "1000px" });
renderEditorInput({
editor: { ...initialState.editor, error: "NameError: boom" },
});
const error = screen.getByText("NameError: boom").closest(".error-message");
expect(error.closest(".editor-input")).toBeInTheDocument();
expect(error.nextElementSibling).toHaveClass("run-bar");
});

test("Does not show anything when there is no error", () => {
renderEditorInput({});
expect(
document.querySelector(".editor-input .error-message"),
).not.toBeInTheDocument();
});

test("Does not show error for HTML projects", () => {
renderEditorInput({
editor: {
...initialState.editor,
project: { ...initialState.editor.project, project_type: "html" },
error: "Something went wrong",
},
});
expect(screen.queryByText("Something went wrong")).not.toBeInTheDocument();
});
});

describe("When read only", () => {
beforeEach(() => {
renderEditorInput({ editor: { ...initialState.editor, readOnly: true } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const PyodideRunner = ({
const user = useSelector((s) => s.auth.user);
const userId = user?.profile?.user;
const isSplitView = useSelector((s) => s.editor.isSplitView);
const isOutputOnly = useSelector((s) => s.editor.isOutputOnly);
const isEmbedded = useSelector((s) => s.editor.isEmbedded);
const reactAppApiEndpoint = useSelector((s) => s.editor.reactAppApiEndpoint);
const codeRunTriggered = useSelector((s) => s.editor.codeRunTriggered);
Expand Down Expand Up @@ -612,7 +613,7 @@ const PyodideRunner = ({
ref={output}
></pre>
</TabPanel>
<ErrorMessage />
{isOutputOnly && <ErrorMessage />}
</Tabs>
</div>
)}
Expand Down Expand Up @@ -649,7 +650,7 @@ const PyodideRunner = ({
ref={output}
></pre>
</TabPanel>
<ErrorMessage />
{isOutputOnly && <ErrorMessage />}
</Tabs>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
openFile,
setFocussedFileIndex,
setFriendlyError,
setIsOutputOnly,
} from "../../../../../redux/EditorSlice.js";
import store from "../../../../../app/store";

Expand Down Expand Up @@ -686,6 +687,35 @@ describe("When an error is received", () => {
});
});

describe("Error message in the output panel", () => {
beforeEach(() => {
act(() => {
store.dispatch(setError("NameError: boom"));
});
});

test("is not shown by default", () => {
render(
<Provider store={store}>
<PyodideRunner active={true} />
</Provider>,
);
expect(screen.queryByText("NameError: boom")).not.toBeInTheDocument();
});

test("is shown when output only", () => {
act(() => {
store.dispatch(setIsOutputOnly(true));
});
render(
<Provider store={store}>
<PyodideRunner active={true} />
</Provider>,
);
expect(screen.getByText("NameError: boom")).toBeInTheDocument();
});
});

describe("When the code run is interrupted", () => {
let input;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ const SkulptRunner = ({
ref={output}
></pre>
</TabPanel>
<ErrorMessage />
{isOutputOnly && <ErrorMessage />}
</Tabs>
</div>
)}
Expand Down Expand Up @@ -718,7 +718,6 @@ const SkulptRunner = ({
ref={output}
></pre>
</TabPanel>
{!isOutputOnly && <ErrorMessage />}
</Tabs>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ describe("When an error has occurred", () => {
};
});

test("Displays error message", () => {
test("Does not display error message in the output panel", () => {
store = mockStore(initialState);
render(
<Provider store={store}>
Expand All @@ -534,8 +534,8 @@ describe("When an error has occurred", () => {
);

expect(
screen.getByText("SyntaxError: bad token T_OP on line 1 of main.py"),
).toBeVisible();
screen.queryByText("SyntaxError: bad token T_OP on line 1 of main.py"),
).not.toBeInTheDocument();
});

test("Does not display error message when isOutputOnly state is true", () => {
Expand Down
7 changes: 7 additions & 0 deletions src/components/Mobile/MobileProject/MobileProject.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const MobileProject = ({
const codeRunTriggered = useSelector(
(state) => state.editor.codeRunTriggered,
);
const error = useSelector((state) => state.editor.error);
const aiHintToggleFocusRequested = useSelector(
(state) => state.editor.aiHintToggleFocusRequested,
);
Expand Down Expand Up @@ -56,6 +57,12 @@ const MobileProject = ({
}
}, [codeRunTriggered, sidebarShowing, withSidebar]);

useEffect(() => {
if (error) {
setSelectedTab(withSidebar ? 1 : 0);
}
}, [error, withSidebar]);

return (
<div
className="proj-container proj-editor-container proj-container--mobile"
Expand Down
Loading
Loading