Browse Source

chore: delete Enzyme (#37854)

* chore: delete Enzyme

* fix: fix
pull/37870/head
lijianan 2 years ago
committed by GitHub
parent
commit
c2d7fe4f0d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .jest.image.js
  2. 1
      .jest.js
  3. 1
      .jest.site.js
  4. 1
      components/breadcrumb/__tests__/Breadcrumb.test.tsx
  5. 1
      components/breadcrumb/__tests__/router.test.tsx
  6. 6
      package.json
  7. 68
      tests/setup.js
  8. 1
      tests/shared/focusTest.tsx

1
.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',

1
.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',

1
.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',

1
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 = () => <div>foo</div>;
render(

1
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();

6
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",

68
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 <StrictMode>{cloneElement(children, props)}</StrictMode>;
}
return {
...enzyme,
mount: (ui, { strictMode, ...config } = {}, ...args) =>
mount(<EnzymeWrapper strictMode={strictMode}>{ui}</EnzymeWrapper>, config, ...args),
render: (ui, { strictMode, ...config } = {}, ...args) =>
render(<EnzymeWrapper strictMode={strictMode}>{ui}</EnzymeWrapper>, config, ...args),
originMount: mount,
};
});

1
tests/shared/focusTest.tsx

@ -57,7 +57,6 @@ export default function focusTest(
return;
}
// ======================== Enzyme ========================
let containerHtml: HTMLElement;
beforeEach(() => {
containerHtml = document.createElement('div');

Loading…
Cancel
Save