From d0ee44243a1068ce1899e5528580e5f8454b6335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Tue, 26 Apr 2022 08:36:16 +0100 Subject: [PATCH] fix(ui): fix tests under nodejs 18 --- ui/package-lock.json | 65 -------------------------------------------- ui/package.json | 1 - ui/src/App.test.tsx | 10 +++---- ui/src/App.tsx | 4 +-- ui/src/setupTests.ts | 3 -- 5 files changed, 6 insertions(+), 77 deletions(-) diff --git a/ui/package-lock.json b/ui/package-lock.json index 7060f8bca..ab81d7927 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -81,7 +81,6 @@ "eslint-plugin-jest": "26.1.5", "eslint-plugin-prettier": "4.0.0", "fetch-mock": "9.11.0", - "jest-canvas-mock": "2.3.1", "prettier": "2.6.2", "purgecss": "4.1.3", "react-scripts": "5.0.1", @@ -14985,12 +14984,6 @@ "node": ">=4" } }, - "node_modules/cssfontparser": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/cssfontparser/-/cssfontparser-1.2.1.tgz", - "integrity": "sha1-9AIvyPlwDGgCnVQghK+69CWj8+M=", - "dev": true - }, "node_modules/csshake": { "version": "1.5.3", "resolved": "https://registry.npmjs.org/csshake/-/csshake-1.5.3.tgz", @@ -20396,16 +20389,6 @@ } } }, - "node_modules/jest-canvas-mock": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/jest-canvas-mock/-/jest-canvas-mock-2.3.1.tgz", - "integrity": "sha512-5FnSZPrX3Q2ZfsbYNE3wqKR3+XorN8qFzDzB5o0golWgt6EOX1+emBnpOc9IAQ+NXFj8Nzm3h7ZdE/9H0ylBcg==", - "dev": true, - "dependencies": { - "cssfontparser": "^1.2.1", - "moo-color": "^1.0.2" - } - }, "node_modules/jest-changed-files": { "version": "27.5.1", "resolved": "https://registry.npmjs.org/jest-changed-files/-/jest-changed-files-27.5.1.tgz", @@ -23870,21 +23853,6 @@ "integrity": "sha512-I1mnb5xn4fO80BH9BLcF0yLypy2UKl+Cb01Fu0hJRkJjlCRtxZMWkTdAtDd5ZqCOxtCkhmRwyI57vWT+1iZ67w==", "dev": true }, - "node_modules/moo-color": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/moo-color/-/moo-color-1.0.3.tgz", - "integrity": "sha512-i/+ZKXMDf6aqYtBhuOcej71YSlbjT3wCO/4H1j8rPvxDJEifdwgg5MaFyu6iYAT8GBZJg2z0dkgK4YMzvURALQ==", - "dev": true, - "dependencies": { - "color-name": "^1.1.4" - } - }, - "node_modules/moo-color/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true - }, "node_modules/move-concurrently": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz", @@ -44418,12 +44386,6 @@ "integrity": "sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==", "dev": true }, - "cssfontparser": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/cssfontparser/-/cssfontparser-1.2.1.tgz", - "integrity": "sha1-9AIvyPlwDGgCnVQghK+69CWj8+M=", - "dev": true - }, "csshake": { "version": "1.5.3", "resolved": "https://registry.npmjs.org/csshake/-/csshake-1.5.3.tgz", @@ -48562,16 +48524,6 @@ "jest-cli": "^27.5.1" } }, - "jest-canvas-mock": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/jest-canvas-mock/-/jest-canvas-mock-2.3.1.tgz", - "integrity": "sha512-5FnSZPrX3Q2ZfsbYNE3wqKR3+XorN8qFzDzB5o0golWgt6EOX1+emBnpOc9IAQ+NXFj8Nzm3h7ZdE/9H0ylBcg==", - "dev": true, - "requires": { - "cssfontparser": "^1.2.1", - "moo-color": "^1.0.2" - } - }, "jest-changed-files": { "version": "27.5.1", "resolved": "https://registry.npmjs.org/jest-changed-files/-/jest-changed-files-27.5.1.tgz", @@ -51223,23 +51175,6 @@ "integrity": "sha512-I1mnb5xn4fO80BH9BLcF0yLypy2UKl+Cb01Fu0hJRkJjlCRtxZMWkTdAtDd5ZqCOxtCkhmRwyI57vWT+1iZ67w==", "dev": true }, - "moo-color": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/moo-color/-/moo-color-1.0.3.tgz", - "integrity": "sha512-i/+ZKXMDf6aqYtBhuOcej71YSlbjT3wCO/4H1j8rPvxDJEifdwgg5MaFyu6iYAT8GBZJg2z0dkgK4YMzvURALQ==", - "dev": true, - "requires": { - "color-name": "^1.1.4" - }, - "dependencies": { - "color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true - } - } - }, "move-concurrently": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz", diff --git a/ui/package.json b/ui/package.json index 588838d2f..5443dd724 100644 --- a/ui/package.json +++ b/ui/package.json @@ -80,7 +80,6 @@ "eslint-plugin-jest": "26.1.5", "eslint-plugin-prettier": "4.0.0", "fetch-mock": "9.11.0", - "jest-canvas-mock": "2.3.1", "prettier": "2.6.2", "purgecss": "4.1.3", "react-scripts": "5.0.1", diff --git a/ui/src/App.test.tsx b/ui/src/App.test.tsx index 52497d4f4..091d1f9bb 100644 --- a/ui/src/App.test.tsx +++ b/ui/src/App.test.tsx @@ -42,10 +42,8 @@ afterEach(() => { localStorage.setItem("themeConfig", ""); jest.restoreAllMocks(); window.history.pushState({}, "App", "/"); - global.window.location = { - href: "http://localhost/", - search: "", - }; + global.window.location.href = "http://localhost/"; + global.window.location.search = ""; }); describe("", () => { @@ -125,7 +123,7 @@ describe("", () => { }; const event = new PopStateEvent("popstate"); - window.onpopstate(event); + window.dispatchEvent(event); expect(window.location.search).toBe("?q=bar"); }); @@ -137,7 +135,7 @@ describe("", () => { tree.unmount(); const event = new PopStateEvent("popstate"); - window.onpopstate(event); + window.dispatchEvent(event); }); it("populates silence from from 'm' query arg", () => { diff --git a/ui/src/App.tsx b/ui/src/App.tsx index cc656c55a..50fd530a4 100644 --- a/ui/src/App.tsx +++ b/ui/src/App.tsx @@ -73,9 +73,9 @@ const App: FC = observer(({ defaultFilters, uiDefaults }) => { ); useEffect(() => { - window.onpopstate = onPopState; + window.addEventListener("popstate", onPopState); return () => { - window.onpopstate = () => {}; + window.removeEventListener("popstate", onPopState); }; }, [onPopState]); diff --git a/ui/src/setupTests.ts b/ui/src/setupTests.ts index b828bc3fb..a577f63da 100644 --- a/ui/src/setupTests.ts +++ b/ui/src/setupTests.ts @@ -29,9 +29,6 @@ jest.mock("react-intersection-observer"); // https://github.com/airbnb/enzyme Enzyme.configure({ adapter: new Adapter() }); -// favico.js needs canvas -require("jest-canvas-mock"); - // https://reactjs.org/blog/2019/08/08/react-v16.9.0.html#new-deprecations const reactDeprecationWarning = /.*has been renamed, and is not recommended for use.*/;