Skip to content

Commit

Permalink
TEMP: Silence errors and warnings
Browse files Browse the repository at this point in the history
This commit identifies all the tests that emit warnings and/or errors. I
intend to work through them to fix the warnings/errors properly and then
I can remove this commit.
  • Loading branch information
chrisroos committed Jan 31, 2025
1 parent cb1db43 commit 75cab7d
Show file tree
Hide file tree
Showing 28 changed files with 83 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/DownloadButton/DownloadButton.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import FileSaver from "file-saver";
import JSZip from "jszip";
import JSZipUtils from "jszip-utils";

import "../../consoleMock";

jest.mock("file-saver");
jest.mock("jszip");
jest.mock("jszip-utils", () => ({
Expand Down
2 changes: 2 additions & 0 deletions src/components/Editor/EditorInput/EditorInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
import { matchMedia, setMedia } from "mock-match-media";
import { MOBILE_BREAKPOINT } from "../../../utils/mediaQueryBreakpoints";

import "../../../consoleMock";

window.HTMLElement.prototype.scrollIntoView = jest.fn();

let mockMediaQuery = (query) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { fireEvent, render, screen } from "@testing-library/react";
import { Provider } from "react-redux";
import configureStore from "redux-mock-store";
import "../../../consoleMock";

import NewComponentButton from "./NewComponentButton";
import { showNewFileModal } from "../../../redux/EditorSlice";
Expand Down
2 changes: 2 additions & 0 deletions src/components/Editor/Project/Project.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import Project from "./Project";
import { showSavedMessage } from "../../../utils/Notifications";
import { MemoryRouter } from "react-router-dom";

import "../../../consoleMock";

window.HTMLElement.prototype.scrollIntoView = jest.fn();

jest.mock("react-router-dom", () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { codeRunHandled, triggerCodeRun } from "../../../../redux/EditorSlice";
import { MemoryRouter } from "react-router-dom";
import { matchMedia, setMedia } from "mock-match-media";
import { MOBILE_BREAKPOINT } from "../../../../utils/mediaQueryBreakpoints";
import "../../../../consoleMock";

let mockMediaQuery = (query) => {
return matchMedia(query).matches;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import PyodideRunner from "./PyodideRunner";
import { Provider } from "react-redux";
import PyodideWorker, { postMessage } from "./PyodideWorker.mock.js";
import "../../../../../consoleMock"

import {
resetState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Provider } from "react-redux";
import VisualOutputPane from "./VisualOutputPane.jsx";
import Highcharts from "highcharts";

import "../../../../../consoleMock";

jest.mock("highcharts");

const renderPaneWithVisuals = (visuals) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
setSenseHatAlwaysEnabled,
} from "../../../../redux/EditorSlice";
import store from "../../../../app/store";
import "../../../../consoleMock";

const initialState = {
editor: {
Expand Down
2 changes: 2 additions & 0 deletions src/components/Menus/ContextMenu/ContextMenu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { fireEvent, render, screen } from "@testing-library/react";
import { axe, toHaveNoViolations } from "jest-axe";
import ContextMenu from "./ContextMenu";

import "../../../consoleMock";

expect.extend(toHaveNoViolations);
const action1 = jest.fn();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { MemoryRouter } from "react-router";
import configureStore from "redux-mock-store";
import FileSaver from "file-saver";

import "../../../../consoleMock";

jest.mock("file-saver");
jest.mock("jszip");
jest.mock("jszip-utils", () => ({
Expand Down
2 changes: 2 additions & 0 deletions src/components/Menus/Sidebar/FilePanel/FilePanel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import configureStore from "redux-mock-store";
import FilePanel from "./FilePanel";
import { openFile, setFocussedFileIndex } from "../../../../redux/EditorSlice";

import "../../../../consoleMock";

const createMockStore = function ({ components, openFiles = [[]], readOnly }) {
const mockStore = configureStore([]);
return mockStore({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { MemoryRouter } from "react-router-dom";

import ProjectsPanel from "./ProjectsPanel";

import "../../../../consoleMock";

document.dispatchEvent = jest.fn();

const initialState = {
Expand Down
2 changes: 2 additions & 0 deletions src/components/Menus/Sidebar/Sidebar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Sidebar from "./Sidebar";
import configureStore from "redux-mock-store";
import { Provider } from "react-redux";

import "../../../consoleMock";

let images = [
{
url: "path/to/image1",
Expand Down
2 changes: 2 additions & 0 deletions src/components/Menus/Sidebar/SidebarBar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import configureStore from "redux-mock-store";
import { Provider } from "react-redux";
import SidebarBar from "./SidebarBar";

import "../../../consoleMock"

const toggleOption = jest.fn();

const mockStore = configureStore([]);
Expand Down
2 changes: 2 additions & 0 deletions src/components/Mobile/MobileProject/MobileProject.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import configureStore from "redux-mock-store";
import MobileProject from "./MobileProject";
import { showSidebar } from "../../../redux/EditorSlice";

import "../../../consoleMock";

window.HTMLElement.prototype.scrollIntoView = jest.fn();

const middlewares = [];
Expand Down
2 changes: 2 additions & 0 deletions src/components/Modals/AccessDeniedWithAuthModal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import AccessDeniedWithAuthModal from "./AccessDeniedWithAuthModal";
import { syncProject } from "../../redux/EditorSlice";
import { defaultPythonProject } from "../../utils/defaultProjects";

import "../../consoleMock"

jest.mock("../../redux/EditorSlice", () => ({
...jest.requireActual("../../redux/EditorSlice"),
syncProject: jest.fn((_) => jest.fn()),
Expand Down
2 changes: 2 additions & 0 deletions src/components/Modals/ErrorModal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import configureStore from "redux-mock-store";
import ErrorModal from "./ErrorModal";
import { closeErrorModal, setError } from "../../redux/EditorSlice";

import "../../consoleMock"

const middlewares = [];
const mockStore = configureStore(middlewares);

Expand Down
2 changes: 2 additions & 0 deletions src/components/Modals/GeneralModal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { fireEvent, render, screen } from "@testing-library/react";
import React from "react";
import GeneralModal from "./GeneralModal";

import "../../consoleMock";

const defaultCallback = jest.fn();
const closeModal = jest.fn();

Expand Down
2 changes: 2 additions & 0 deletions src/components/Modals/NewFileModal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { fireEvent, render, screen } from "@testing-library/react";
import { Provider } from "react-redux";
import configureStore from "redux-mock-store";

import "../../consoleMock"

import NewFileModal from "./NewFileModal";
import {
addProjectComponent,
Expand Down
2 changes: 2 additions & 0 deletions src/components/Modals/NotFoundModal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import NotFoundModal from "./NotFoundModal";
import { closeNotFoundModal, syncProject } from "../../redux/EditorSlice";
import { defaultPythonProject } from "../../utils/defaultProjects";

import "../../consoleMock"

jest.mock("../../redux/EditorSlice", () => ({
...jest.requireActual("../../redux/EditorSlice"),
syncProject: jest.fn((_) => jest.fn()),
Expand Down
2 changes: 2 additions & 0 deletions src/components/Modals/RenameFileModal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { fireEvent, render, screen } from "@testing-library/react";
import { Provider } from "react-redux";
import configureStore from "redux-mock-store";

import "../../consoleMock";

import RenameFileModal from "./RenameFileModal";
import {
setNameError,
Expand Down
1 change: 1 addition & 0 deletions src/components/Modals/RenameProjectModal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { Provider } from "react-redux";
import configureStore from "redux-mock-store";
import { MockedProvider } from "@apollo/client/testing";
import "../../consoleMock"

import {
RenameProjectModal,
Expand Down
2 changes: 2 additions & 0 deletions src/components/ProjectBar/ProjectBar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import configureStore from "redux-mock-store";
import { MemoryRouter } from "react-router-dom";
import ProjectBar from "./ProjectBar";

import "../../consoleMock";

jest.mock("axios");

jest.mock("react-router-dom", () => ({
Expand Down
2 changes: 2 additions & 0 deletions src/components/ProjectName/ProjectName.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import userEvent from "@testing-library/user-event";
import ProjectName from "./ProjectName";
import { updateProjectName } from "../../redux/EditorSlice";

import "../../consoleMock";

const project = {
identifier: "hello-world-project",
name: "Hello world",
Expand Down
1 change: 1 addition & 0 deletions src/components/SaveButton/SaveButton.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Provider } from "react-redux";
import configureStore from "redux-mock-store";
import { triggerSave } from "../../redux/EditorSlice";
import SaveButton from "./SaveButton";
import "../../consoleMock"

const logInHandler = jest.fn();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { act, render, screen } from "@testing-library/react";
import { Provider } from "react-redux";
import configureStore from "redux-mock-store";
import WebComponentProject from "./WebComponentProject";
import "../../consoleMock";

const codeChangedHandler = jest.fn();
const runStartedHandler = jest.fn();
Expand Down
36 changes: 36 additions & 0 deletions src/consoleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const originalError = console.error;
const originalWarn = console.warn;

window.console.warn = (msg) => {
if (msg.includes("DEPRECATED: icons as React elements will not be supported in future releases") ||
msg.includes("PyodideWorker is not initialized") ||
msg.includes("changing the droppableId")) {
return;
}

originalWarn(msg);
}

window.console.error = (error) => {
let msg;
if (typeof(error) === "object") {
msg = error.message;
} else {
msg = error;
}

if (msg.includes("inside a test was not wrapped in act(...)") ||
msg.includes("Warning: Invalid value for prop") ||
msg.includes("getClientRects is not a function") ||
msg.includes("An error occurred! For more details, see the full error text at") ||
msg.includes("Warning: react-modal: App element is not defined") ||
msg.includes("Support for defaultProps will be removed from function components") ||
msg.includes("A component is changing a controlled input to be uncontrolled") ||
msg.includes("Unsupported origin: unsupported") ||
msg.includes("Consider adding an error boundary to your tree") ||
msg.includes("Each child in a list should have a unique")) {
return;
}

originalError(error);
}
2 changes: 2 additions & 0 deletions src/containers/WebComponentLoader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { useProjectPersistence } from "../hooks/useProjectPersistence";
import localStorageUserMiddleware from "../redux/middlewares/localStorageUserMiddleware";
import { Cookies, CookiesProvider } from "react-cookie";

import "../consoleMock";

jest.mock("../hooks/useProject", () => ({
useProject: jest.fn(),
}));
Expand Down

0 comments on commit 75cab7d

Please sign in to comment.