From c2d7fe4f0dab11630fc0e44e67fa6989bb575c85 Mon Sep 17 00:00:00 2001
From: lijianan <574980606@qq.com>
Date: Thu, 6 Oct 2022 13:51:02 +0800
Subject: [PATCH] chore: delete Enzyme (#37854)
* chore: delete Enzyme
* fix: fix
---
.jest.image.js | 1 -
.jest.js | 1 -
.jest.site.js | 1 -
.../breadcrumb/__tests__/Breadcrumb.test.tsx | 1 -
.../breadcrumb/__tests__/router.test.tsx | 1 -
package.json | 6 +-
tests/setup.js | 68 +------------------
tests/shared/focusTest.tsx | 1 -
8 files changed, 3 insertions(+), 77 deletions(-)
diff --git a/.jest.image.js b/.jest.image.js
index 6e3c1f2b46..fb42545326 100644
--- a/.jest.image.js
+++ b/.jest.image.js
@@ -13,7 +13,6 @@ module.exports = {
},
testRegex: 'image\\.test\\.(j|t)s$',
transformIgnorePatterns,
- snapshotSerializers: ['enzyme-to-json/serializer'],
globals: {
'ts-jest': {
tsConfigFile: './tsconfig.test.json',
diff --git a/.jest.js b/.jest.js
index b9434c048d..17e5e08706 100644
--- a/.jest.js
+++ b/.jest.js
@@ -47,7 +47,6 @@ module.exports = {
'!components/__tests__/node.test.tsx',
],
transformIgnorePatterns,
- snapshotSerializers: ['enzyme-to-json/serializer'],
globals: {
'ts-jest': {
tsConfig: './tsconfig.test.json',
diff --git a/.jest.site.js b/.jest.site.js
index fa3b353ed1..a1f19aee58 100644
--- a/.jest.site.js
+++ b/.jest.site.js
@@ -13,7 +13,6 @@ module.exports = {
testRegex: 'check-site\\.(j|t)s$',
testEnvironment: 'node',
transformIgnorePatterns,
- snapshotSerializers: ['enzyme-to-json/serializer'],
globals: {
'ts-jest': {
tsConfigFile: './tsconfig.test.json',
diff --git a/components/breadcrumb/__tests__/Breadcrumb.test.tsx b/components/breadcrumb/__tests__/Breadcrumb.test.tsx
index ea4ac0c5ed..430d25321d 100644
--- a/components/breadcrumb/__tests__/Breadcrumb.test.tsx
+++ b/components/breadcrumb/__tests__/Breadcrumb.test.tsx
@@ -21,7 +21,6 @@ describe('Breadcrumb', () => {
errorSpy.mockRestore();
});
- // https://github.com/airbnb/enzyme/issues/875
it('warns on non-Breadcrumb.Item and non-Breadcrumb.Separator children', () => {
const MyCom: React.FC = () =>
foo
;
render(
diff --git a/components/breadcrumb/__tests__/router.test.tsx b/components/breadcrumb/__tests__/router.test.tsx
index 3005f4fdb7..ca0a0ad601 100644
--- a/components/breadcrumb/__tests__/router.test.tsx
+++ b/components/breadcrumb/__tests__/router.test.tsx
@@ -32,7 +32,6 @@ describe('react router', () => {
jest.useRealTimers();
});
- // https://github.com/airbnb/enzyme/issues/875
it('react router 6', () => {
const Home: React.FC = () => {
const location = useLocation();
diff --git a/package.json b/package.json
index e564f44e14..8e09fe05c3 100644
--- a/package.json
+++ b/package.json
@@ -101,7 +101,7 @@
"test-image": "npm run dist && docker-compose run tests",
"argos": "node ./scripts/argos-upload.js",
"version": "node ./scripts/generate-version",
- "install-react-16": "npm i --no-save --legacy-peer-deps react@16 react-dom@16 enzyme-adapter-react-16",
+ "install-react-16": "npm i --no-save --legacy-peer-deps react@16 react-dom@16",
"install-react-17": "npm i --no-save --legacy-peer-deps react@17 react-dom@17",
"install-react-18": "npm i --no-save --legacy-peer-deps react@18 react-dom@18 @testing-library/react@13"
},
@@ -170,7 +170,6 @@
"@testing-library/jest-dom": "^5.16.3",
"@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^14.4.2",
- "@types/enzyme": "^3.10.5",
"@types/gtag.js": "^0.0.11",
"@types/jest": "^29.0.0",
"@types/jest-axe": "^3.5.3",
@@ -190,7 +189,6 @@
"@types/warning": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
- "@wojtekmaj/enzyme-adapter-react-17": "^0.6.0",
"antd-img-crop": "^4.0.0",
"array-move": "^4.0.0",
"babel-plugin-add-react-displayname": "^0.0.5",
@@ -209,8 +207,6 @@
"docsearch.js": "^2.6.3",
"duplicate-package-checker-webpack-plugin": "^3.0.0",
"enquire-js": "^0.2.1",
- "enzyme": "^3.10.0",
- "enzyme-to-json": "^3.6.0",
"esbuild-loader": "^2.13.1",
"eslint": "^8.0.0",
"eslint-config-airbnb": "^19.0.0",
diff --git a/tests/setup.js b/tests/setup.js
index 0e356c1f11..f230185718 100644
--- a/tests/setup.js
+++ b/tests/setup.js
@@ -1,17 +1,9 @@
const React = require('react');
const util = require('util');
-const { _rs: onLibResize } = require('rc-resize-observer/lib/utils/observerUtil');
-const { _rs: onEsResize } = require('rc-resize-observer/es/utils/observerUtil');
-
// eslint-disable-next-line no-console
console.log('Current React Version:', React.version);
-// jest.mock('react', () => ({
-// ...jest.requireActual('react'),
-// useLayoutEffect: jest.requireActual('react').useEffect,
-// }));
-
/* eslint-disable global-require */
if (typeof window !== 'undefined') {
global.window.resizeTo = (width, height) => {
@@ -39,62 +31,6 @@ if (typeof window !== 'undefined') {
// ref: https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
// ref: https://github.com/jsdom/jsdom/issues/2524
- Object.defineProperty(window, 'TextEncoder', {
- writable: true,
- value: util.TextEncoder,
- });
- Object.defineProperty(window, 'TextDecoder', {
- writable: true,
- value: util.TextDecoder,
- });
+ Object.defineProperty(window, 'TextEncoder', { writable: true, value: util.TextEncoder });
+ Object.defineProperty(window, 'TextDecoder', { writable: true, value: util.TextDecoder });
}
-
-const Enzyme = require('enzyme');
-
-const Adapter =
- process.env.REACT === '16'
- ? require('enzyme-adapter-react-16') // eslint-disable-line import/no-extraneous-dependencies,import/no-unresolved
- : require('@wojtekmaj/enzyme-adapter-react-17');
-
-Enzyme.configure({ adapter: new Adapter() });
-
-Object.assign(Enzyme.ReactWrapper.prototype, {
- findObserver(index = 0) {
- return this.find('ResizeObserver').at(index);
- },
- triggerResize(index = 0) {
- const target = this.findObserver(index).getDOMNode();
- const originGetBoundingClientRect = target.getBoundingClientRect;
-
- target.getBoundingClientRect = () => ({ width: 510, height: 903 });
- onLibResize([{ target }]);
- onEsResize([{ target }]);
-
- target.getBoundingClientRect = originGetBoundingClientRect;
- },
-});
-
-// React.StrictMode wrapper
-jest.mock('enzyme', () => {
- const enzyme = jest.requireActual('enzyme');
- const { StrictMode, cloneElement } = jest.requireActual('react');
- const { mount, render } = enzyme;
-
- function EnzymeWrapper({ strictMode, children, ...props }) {
- // Not wrap StrictMode for some test case need count render times
- if (strictMode === false) {
- return cloneElement(children, props);
- }
-
- return {cloneElement(children, props)};
- }
-
- return {
- ...enzyme,
- mount: (ui, { strictMode, ...config } = {}, ...args) =>
- mount({ui}, config, ...args),
- render: (ui, { strictMode, ...config } = {}, ...args) =>
- render({ui}, config, ...args),
- originMount: mount,
- };
-});
diff --git a/tests/shared/focusTest.tsx b/tests/shared/focusTest.tsx
index fcd8f3551d..b92ec0d0b1 100644
--- a/tests/shared/focusTest.tsx
+++ b/tests/shared/focusTest.tsx
@@ -57,7 +57,6 @@ export default function focusTest(
return;
}
- // ======================== Enzyme ========================
let containerHtml: HTMLElement;
beforeEach(() => {
containerHtml = document.createElement('div');