ソースを参照

Update Jest to v29, uuid v9 & update stubs

- `uuid` update is required to avoid import errors - https://github.com/uuidjs/uuid/blob/main/CHANGELOG.md#900-2022-09-05
- Add stubs for window.scrollTo to avoid console errors when running tests
- Filter out warnings for Draftail React warnings, these are unlikely to be resolved anytime soon and add noise to the Jests tests that are unhelpful
- Closes #10043
LB Johnston 1 年間 前
コミット
f90e03ab35
3 ファイル変更819 行追加128 行削除
  1. 31 0
      client/tests/stubs.js
  2. 782 124
      package-lock.json
  3. 6 4
      package.json

+ 31 - 0
client/tests/stubs.js

@@ -60,3 +60,34 @@ global.DOCUMENT_CHOOSER_MODAL_ONLOAD_HANDLERS = { type: 'document' };
 
 class PageChooserModal {}
 global.PageChooserModal = PageChooserModal;
+
+/** Mock window.scrollTo as not provided via JSDom */
+window.scrollTo = jest.fn();
+
+/** Mock console.warn to filter out warnings from React due to Draftail legacy Component API usage.
+ * Draftail/Draft-js is unlikely to support these and the warnings are not useful for unit test output.
+ */
+/* eslint-disable no-console */
+const consoleWarnOriginal = console.warn;
+console.warn = function filterWarnings(...args) {
+  /* eslint-enable no-console */
+
+  const [warning, component] = args;
+
+  const legacyReactWarnings = [
+    'Warning: componentWillMount has been renamed, and is not recommended for use.',
+    'Warning: componentWillReceiveProps has been renamed, and is not recommended for use.',
+    'Warning: componentWillUpdate has been renamed, and is not recommended for use.',
+  ];
+
+  const ignoredComponents = ['DraftEditor', 'PluginEditor'];
+
+  if (
+    legacyReactWarnings.some((_) => warning.includes(_)) &&
+    ignoredComponents.includes(component)
+  ) {
+    return;
+  }
+
+  consoleWarnOriginal.apply(console, args);
+};

ファイルの差分が大きいため隠しています
+ 782 - 124
package-lock.json


+ 6 - 4
package.json

@@ -31,6 +31,7 @@
     "transform": {
       "^.+\\.(js|ts|tsx)$": "ts-jest"
     },
+    "testEnvironment": "jsdom",
     "testPathIgnorePatterns": [
       "/node_modules/",
       "/build/",
@@ -77,12 +78,13 @@
     "css-loader": "^6.5.1",
     "cssnano": "^5.0.14",
     "enzyme": "^3.11.0",
-    "enzyme-adapter-react-16": "^1.15.6",
+    "enzyme-adapter-react-16": "^1.15.7",
     "enzyme-to-json": "^3.6.2",
     "eslint": "^8.5.0",
     "expose-loader": "^3.1.0",
     "gettext-extractor": "^3.5.3",
-    "jest": "^26.6.3",
+    "jest": "^29.5.0",
+    "jest-environment-jsdom": "29.5.0",
     "mini-css-extract-plugin": "^2.4.5",
     "postcss": "^8.4.7",
     "postcss-loader": "^6.2.1",
@@ -95,7 +97,7 @@
     "stylelint": "^14.2.0",
     "tailwindcss": "^3.1.5",
     "tailwindcss-vanilla-rtl": "^0.2.0",
-    "ts-jest": "^26.5.6",
+    "ts-jest": "^29.1.0",
     "ts-loader": "^9.2.6",
     "typescript": "^4.5.4",
     "webpack": "^5.76.0",
@@ -124,7 +126,7 @@
     "reselect": "^4.0.0",
     "telepath-unpack": "^0.0.3",
     "tippy.js": "^6.3.7",
-    "uuid": "^8.3.2"
+    "uuid": "^9.0.0"
   },
   "scripts": {
     "start": "webpack --config ./client/webpack.config.js --mode development --progress --watch",

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません