From bf1026b6ec357a0e4a9337a51db58642881e2374 Mon Sep 17 00:00:00 2001 From: cliffhall Date: Wed, 23 Apr 2025 17:52:17 -0400 Subject: [PATCH] Fix failing unit tests * This PR caused the Sidebar.test.ts file tests to fail because TransformStream is not found. * TransformStream exists in the Node version I'm testing with (20), but it still isn't found by Jest * Turns out it is a problem with Jest, and the workaround is the simple package jest-fixed-jsdom, which subclasses JSDOMEnvironment testing environment, placing this and several other dependencies in its global object. * In package.json - add jest-fixed-jsdom as a devDependency * In jest.config.cjs - change testEnvironment to jest-fixed-jsdom --- client/jest.config.cjs | 2 +- package-lock.json | 14 ++++++++++++++ package.json | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/client/jest.config.cjs b/client/jest.config.cjs index c360e72..b4d81cf 100644 --- a/client/jest.config.cjs +++ b/client/jest.config.cjs @@ -1,6 +1,6 @@ module.exports = { preset: "ts-jest", - testEnvironment: "jsdom", + testEnvironment: "jest-fixed-jsdom", moduleNameMapper: { "^@/(.*)$": "/src/$1", "\\.css$": "/src/__mocks__/styleMock.js", diff --git a/package-lock.json b/package-lock.json index f8461b3..973ca62 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,6 +31,7 @@ "@types/jest": "^29.5.14", "@types/node": "^22.7.5", "@types/shell-quote": "^1.7.5", + "jest-fixed-jsdom": "^0.0.9", "prettier": "3.3.3", "typescript": "^5.4.2" } @@ -5358,6 +5359,19 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-fixed-jsdom": { + "version": "0.0.9", + "resolved": "https://registry.npmjs.org/jest-fixed-jsdom/-/jest-fixed-jsdom-0.0.9.tgz", + "integrity": "sha512-KPfqh2+sn5q2B+7LZktwDcwhCpOpUSue8a1I+BcixWLOQoEVyAjAGfH+IYZGoxZsziNojoHGRTC8xRbB1wDD4g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18.0.0" + }, + "peerDependencies": { + "jest-environment-jsdom": ">=28.0.0" + } + }, "node_modules/jest-get-type": { "version": "29.6.3", "dev": true, diff --git a/package.json b/package.json index d127d13..bba280c 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "@types/jest": "^29.5.14", "@types/node": "^22.7.5", "@types/shell-quote": "^1.7.5", + "jest-fixed-jsdom": "^0.0.9", "prettier": "3.3.3", "typescript": "^5.4.2" }