From 18d648a746900ed83c8541b2a8fe3c6d7b7315c3 Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Tue, 28 May 2024 14:14:40 +0200 Subject: [PATCH] Use vi-canvas-mock --- package.json | 2 +- src/setupTests.node.ts | 2 +- src/vitest-canvas-mock.ts | 27 --------------------------- yarn.lock | 22 +++++++++++----------- 4 files changed, 13 insertions(+), 40 deletions(-) delete mode 100644 src/vitest-canvas-mock.ts diff --git a/package.json b/package.json index c7ee77dd..be66ca02 100644 --- a/package.json +++ b/package.json @@ -135,7 +135,6 @@ "husky": ">=6", "hyperfine": "^1.0.0", "istanbul": "^0.4.5", - "jest-canvas-mock": "^2.5.2", "jest-junit": "^16.0.0", "lint-staged": ">=10", "msw": "^2.2.2", @@ -145,6 +144,7 @@ "react-is": "^18.3.1", "react-test-renderer": "^18.3.1", "storybook": "^8.1.2", + "vi-canvas-mock": "^1.0.0", "vite": "^4.0.0", "vite-plugin-inspect": "^0.8.4", "vite-plugin-svgr": "^4.2.0", diff --git a/src/setupTests.node.ts b/src/setupTests.node.ts index a9010fe5..b9719cb5 100644 --- a/src/setupTests.node.ts +++ b/src/setupTests.node.ts @@ -1,5 +1,5 @@ import '@testing-library/jest-dom/vitest' -import './vitest-canvas-mock' +import 'vi-canvas-mock' import { setProjectAnnotations } from '@storybook/react' import * as axeMatchers from 'vitest-axe/matchers' import { cleanup } from '@testing-library/react' diff --git a/src/vitest-canvas-mock.ts b/src/vitest-canvas-mock.ts deleted file mode 100644 index 3e9f2ee7..00000000 --- a/src/vitest-canvas-mock.ts +++ /dev/null @@ -1,27 +0,0 @@ -var apis = [ - 'Path2D', - 'CanvasGradient', - 'CanvasPattern', - 'CanvasRenderingContext2D', - 'DOMMatrix', - 'ImageData', - 'TextMetrics', - 'ImageBitmap', - 'createImageBitmap', -] -async function importMockWindow() { - // @ts-ignore - const getCanvasWindow = await import('jest-canvas-mock/lib/window.js').then( - (res) => res.default?.default || res.default || res - ) - const canvasWindow = getCanvasWindow({ document: window.document }) - apis.forEach((api) => { - // @ts-ignore - globalThis[api] = canvasWindow[api] - // @ts-ignore - globalThis.window[api] = canvasWindow[api] - }) -} -// @ts-ignore -globalThis.jest = vi -importMockWindow() diff --git a/yarn.lock b/yarn.lock index 6399d738..3bbf2ec0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8239,7 +8239,6 @@ __metadata: husky: "npm:>=6" hyperfine: "npm:^1.0.0" istanbul: "npm:^0.4.5" - jest-canvas-mock: "npm:^2.5.2" jest-junit: "npm:^16.0.0" lint-staged: "npm:>=10" msw: "npm:^2.2.2" @@ -8261,6 +8260,7 @@ __metadata: styled-components: "npm:^5.3.3" typescript: "npm:^5.4.5" use-dark-mode: "npm:^2.3.1" + vi-canvas-mock: "npm:^1.0.0" vite: "npm:^4.0.0" vite-plugin-inspect: "npm:^0.8.4" vite-plugin-svgr: "npm:^4.2.0" @@ -12457,16 +12457,6 @@ __metadata: languageName: node linkType: hard -"jest-canvas-mock@npm:^2.5.2": - version: 2.5.2 - resolution: "jest-canvas-mock@npm:2.5.2" - dependencies: - cssfontparser: "npm:^1.2.1" - moo-color: "npm:^1.0.2" - checksum: 10/094e2e1c773c658fab7e91e9279027fc38a55060865b5b6a3c9acc47fc912fb9d3451ab4fdf544d016578f77b975626707c3a62e396575aa878f46d939c7ca5e - languageName: node - linkType: hard - "jest-changed-files@npm:^29.7.0": version: 29.7.0 resolution: "jest-changed-files@npm:29.7.0" @@ -19121,6 +19111,16 @@ __metadata: languageName: node linkType: hard +"vi-canvas-mock@npm:^1.0.0": + version: 1.0.0 + resolution: "vi-canvas-mock@npm:1.0.0" + dependencies: + cssfontparser: "npm:^1.2.1" + moo-color: "npm:^1.0.2" + checksum: 10/bfe9d79ce8a835407fe6abe2238ed4e6ba8faf847790d7c16e5c5ee5ffdf4dfcf66e17c6320635bb6033bfa35a47a3eaa870c57f466b51d10485bb8962922739 + languageName: node + linkType: hard + "vite-node@npm:1.6.0": version: 1.6.0 resolution: "vite-node@npm:1.6.0"