From 7322aa6f5f99425635442ddb2439c05339247c80 Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Wed, 7 Jun 2023 21:59:21 +0800 Subject: [PATCH] Revert "chore: migrate to vitest (#42506)" (#42900) This reverts commit 6759887c440e5603c4e7766938cb5c3358ce4794. --- .eslintignore | 1 + .eslintrc.js | 27 +- .github/workflows/test.yml | 4 +- .gitignore | 1 + .jest.image.js | 23 + .jest.js | 68 ++ .jest.node.js | 19 + .jest.site.js | 21 + __mocks__/rc-virtual-list.ts | 3 - .../__snapshots__/index.test.ts.snap | 12 +- .../__snapshots__/setup.test.tsx.snap | 4 +- components/__tests__/index.test.ts | 3 +- components/__tests__/node.test.tsx | 37 +- components/_util/PurePanel.tsx | 3 +- components/_util/__tests__/getScroll.test.ts | 8 +- .../__tests__/responsiveObserve.test.tsx | 2 +- components/_util/__tests__/scrollTo.test.ts | 12 +- components/_util/__tests__/util.test.tsx | 14 +- components/_util/__tests__/warning.test.ts | 8 +- components/_util/__tests__/wave.test.tsx | 71 +- components/affix/__tests__/Affix.test.tsx | 20 +- .../__snapshots__/Affix.test.tsx.snap | 4 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 6 +- components/alert/__tests__/index.test.tsx | 24 +- components/anchor/__tests__/Anchor.test.tsx | 108 ++- .../__snapshots__/Anchor.test.tsx.snap | 8 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 6 +- components/app/__tests__/index.test.tsx | 12 +- .../__snapshots__/demo-extend.test.ts.snap | 8 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 4 +- .../auto-complete/__tests__/focus.test.tsx | 16 +- .../auto-complete/__tests__/index.test.tsx | 6 +- components/auto-complete/index.tsx | 2 +- components/avatar/__tests__/Avatar.test.tsx | 8 +- .../__snapshots__/Avatar.test.tsx.snap | 32 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 4 +- components/back-top/__tests__/index.test.tsx | 12 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 28 +- .../__snapshots__/ribbon.test.tsx.snap | 4 +- components/badge/__tests__/index.test.tsx | 10 +- .../breadcrumb/__tests__/Breadcrumb.test.tsx | 8 +- .../__snapshots__/Breadcrumb.test.tsx.snap | 24 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/itemRender.test.tsx.snap | 4 +- .../__snapshots__/router.test.tsx.snap | 4 +- .../breadcrumb/__tests__/router.test.tsx | 4 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 52 +- .../button/__tests__/delay-timer.test.tsx | 10 +- components/button/__tests__/index.test.tsx | 22 +- components/button/__tests__/wave.test.tsx | 18 +- .../__snapshots__/demo-extend.test.ts.snap | 30 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 10 +- components/calendar/__tests__/index.test.tsx | 70 +- components/calendar/__tests__/select.test.tsx | 20 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 10 +- components/card/__tests__/index.test.tsx | 6 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 12 +- components/carousel/__tests__/index.test.tsx | 9 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 34 +- components/cascader/__tests__/index.test.tsx | 27 +- components/cascader/index.tsx | 2 +- .../__snapshots__/checkbox.test.tsx.snap | 4 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/group.test.tsx.snap | 6 +- .../checkbox/__tests__/checkbox.test.tsx | 6 +- components/checkbox/__tests__/group.test.tsx | 22 +- components/col/style/index.ts | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 4 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 10 +- components/collapse/__tests__/index.test.tsx | 66 +- components/color-picker/ColorPicker.tsx | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 24 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 8 +- .../__tests__/components.test.tsx | 14 +- .../color-picker/__tests__/index.test.tsx | 6 +- .../__snapshots__/components.test.tsx.snap | 768 +++++++++--------- .../__snapshots__/form.test.tsx.snap | 4 +- .../__snapshots__/popup.test.tsx.snap | 8 +- .../config-provider/__tests__/button.test.tsx | 2 +- .../__tests__/components.test.tsx | 1 + .../__tests__/container.test.tsx | 8 +- .../config-provider/__tests__/form.test.tsx | 24 +- .../config-provider/__tests__/locale.test.tsx | 6 +- .../config-provider/__tests__/memo.test.tsx | 4 +- .../config-provider/__tests__/nonce.test.tsx | 1 + .../config-provider/__tests__/popup.test.tsx | 21 +- .../config-provider/__tests__/target.test.tsx | 16 +- .../config-provider/__tests__/theme.test.tsx | 8 +- .../__tests__/useConfig.test.tsx | 2 +- .../config-provider/defaultRenderEmpty.tsx | 2 +- components/config-provider/index.tsx | 10 +- .../date-picker/__tests__/DatePicker.test.tsx | 30 +- .../__tests__/QuarterPicker.test.tsx | 2 +- .../__tests__/RangePicker.test.tsx | 2 +- .../__snapshots__/DatePicker.test.tsx.snap | 8 +- .../__snapshots__/QuarterPicker.test.tsx.snap | 4 +- .../__snapshots__/RangePicker.test.tsx.snap | 6 +- .../__snapshots__/WeekPicker.test.tsx.snap | 4 +- .../__snapshots__/demo-extend.test.ts.snap | 4 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/mount.test.ts.snap | 10 +- .../__snapshots__/other.test.tsx.snap | 14 +- components/date-picker/__tests__/utils.ts | 2 +- components/date-picker/index.ts | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 18 +- .../descriptions/__tests__/index.test.tsx | 4 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- components/divider/__tests__/index.test.tsx | 2 +- components/drawer/__tests__/Drawer.test.tsx | 16 +- .../drawer/__tests__/DrawerEvent.test.tsx | 30 +- .../__snapshots__/Drawer.test.tsx.snap | 26 +- .../__snapshots__/DrawerEvent.test.tsx.snap | 4 +- .../__snapshots__/demo-extend.test.tsx.snap | 8 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../drawer/__tests__/demo-extend.test.tsx | 24 +- components/drawer/__tests__/type.test.tsx | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../dropdown-button.test.tsx.snap | 6 +- .../__snapshots__/index.test.tsx.snap | 10 +- .../__tests__/dropdown-button.test.tsx | 40 +- components/dropdown/__tests__/index.test.tsx | 45 +- components/dropdown/dropdown.tsx | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 6 +- .../__snapshots__/back-top.test.tsx.snap | 4 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/group.test.tsx.snap | 4 +- .../__snapshots__/index.test.tsx.snap | 6 +- .../float-button/__tests__/back-top.test.tsx | 10 +- .../float-button/__tests__/group.test.tsx | 8 +- .../float-button/__tests__/index.test.tsx | 10 +- .../__snapshots__/demo-extend.test.ts.snap | 40 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 14 +- .../__snapshots__/list.test.tsx.snap | 4 +- components/form/__tests__/index.test.tsx | 58 +- .../form/__tests__/list-noStyle.test.tsx | 6 +- components/form/__tests__/list.test.tsx | 10 +- components/form/__tests__/ref.test.tsx | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 14 +- components/grid/__tests__/gap.test.tsx | 4 +- components/grid/__tests__/index.test.tsx | 28 +- components/grid/__tests__/server.test.tsx | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- components/icon/__tests__/index.test.tsx | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 6 +- components/image/__tests__/index.test.tsx | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 6 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 10 +- .../input-number/__tests__/index.test.tsx | 4 +- .../input-number/__tests__/prefix.test.tsx | 2 +- components/input/__tests__/Password.test.tsx | 28 +- components/input/__tests__/Search.test.tsx | 26 +- .../__snapshots__/Password.test.tsx.snap | 12 +- .../__snapshots__/Search.test.tsx.snap | 26 +- .../__snapshots__/demo-extend.test.ts.snap | 26 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 146 ++-- .../__snapshots__/textarea.test.tsx.snap | 58 +- components/input/__tests__/focus.test.tsx | 8 +- components/input/__tests__/index.test.tsx | 8 +- components/input/__tests__/textarea.test.tsx | 51 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 14 +- .../__tests__/dynamic-breakpoint.test.tsx | 8 +- components/layout/__tests__/index.test.tsx | 16 +- components/layout/__tests__/warning.test.tsx | 2 +- .../__snapshots__/Item.test.tsx.snap | 10 +- .../__snapshots__/demo-extend.test.ts.snap | 33 +- .../__tests__/__snapshots__/demo.test.ts.snap | 33 +- .../__snapshots__/empty.test.tsx.snap | 4 +- .../__snapshots__/index.test.tsx.snap | 6 +- .../__snapshots__/pagination.test.tsx.snap | 14 +- components/list/__tests__/pagination.test.tsx | 4 +- .../__snapshots__/index.test.tsx.snap | 146 ++-- components/locale/__tests__/config.test.tsx | 4 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 4 +- components/mentions/__tests__/index.test.tsx | 15 +- components/mentions/index.tsx | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 12 +- components/menu/__tests__/index.test.tsx | 153 ++-- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- components/message/__tests__/config.test.tsx | 8 +- components/message/__tests__/hooks.test.tsx | 10 +- .../message/__tests__/immediately.test.tsx | 6 +- components/message/__tests__/index.test.tsx | 26 +- .../message/__tests__/static-warning.test.tsx | 8 +- components/message/__tests__/type.test.tsx | 10 +- components/message/__tests__/util.ts | 11 +- components/modal/__tests__/Modal.test.tsx | 8 +- .../__snapshots__/Modal.test.tsx.snap | 10 +- .../__snapshots__/confirm.test.tsx.snap | 4 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__snapshots__/demo.test.tsx.snap | 2 +- components/modal/__tests__/confirm.test.tsx | 140 ++-- components/modal/__tests__/hook.test.tsx | 22 +- .../modal/__tests__/static-warning.test.tsx | 8 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../notification/__tests__/config.test.tsx | 13 +- .../notification/__tests__/hooks.test.tsx | 6 +- .../notification/__tests__/index.test.tsx | 8 +- .../notification/__tests__/placement.test.tsx | 6 +- .../__tests__/static-warning.test.tsx | 8 +- components/notification/__tests__/util.ts | 3 +- .../__snapshots__/demo-extend.test.ts.snap | 32 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 8 +- .../pagination/__tests__/index.test.tsx | 4 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 8 +- .../popconfirm/__tests__/index.test.tsx | 32 +- components/popconfirm/index.tsx | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 6 +- components/popover/__tests__/index.test.tsx | 4 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 42 +- components/progress/__tests__/index.test.tsx | 20 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 8 +- components/qrcode/__tests__/index.test.tsx | 6 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/group.test.tsx.snap | 4 +- .../__snapshots__/radio-button.test.tsx.snap | 8 +- .../__snapshots__/radio.test.tsx.snap | 10 +- components/radio/__tests__/group.test.tsx | 22 +- .../radio/__tests__/radio-button.test.tsx | 22 +- components/radio/__tests__/radio.test.tsx | 4 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.ts.snap | 4 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 4 +- components/result/__tests__/index.test.tsx | 2 +- components/row/style/index.tsx | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 4 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 32 +- components/segmented/__tests__/index.test.tsx | 22 +- .../__snapshots__/demo-extend.test.ts.snap | 66 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 8 +- components/select/__tests__/index.test.tsx | 16 +- components/select/index.tsx | 4 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 206 ++--- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 10 +- components/slider/__tests__/index.test.tsx | 33 +- .../__snapshots__/demo-extend.test.ts.snap | 28 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 12 +- .../__snapshots__/space-compact.test.tsx.snap | 6 +- components/space/__tests__/gap.test.tsx | 2 +- components/space/__tests__/index.test.tsx | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 10 +- components/spin/__tests__/delay.test.tsx | 26 +- components/spin/__tests__/index.test.tsx | 8 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 6 +- components/statistic/__tests__/index.test.tsx | 34 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 10 +- components/steps/__tests__/index.test.tsx | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 4 +- components/switch/__tests__/index.test.tsx | 16 +- components/switch/__tests__/wave.test.tsx | 6 +- components/switch/style/index.ts | 2 +- components/table/Column.ts | 3 +- components/table/ColumnGroup.ts | 3 +- .../table/__tests__/Table.filter.test.tsx | 136 ++-- .../table/__tests__/Table.order.test.tsx | 2 +- .../table/__tests__/Table.pagination.test.tsx | 42 +- .../__tests__/Table.rowSelection.test.tsx | 130 +-- .../table/__tests__/Table.sorter.test.tsx | 32 +- components/table/__tests__/Table.test.tsx | 23 +- .../__snapshots__/Table.expand.test.tsx.snap | 4 +- .../__snapshots__/Table.filter.test.tsx.snap | 22 +- .../Table.pagination.test.tsx.snap | 10 +- .../Table.rowSelection.test.tsx.snap | 16 +- .../__snapshots__/Table.sorter.test.tsx.snap | 12 +- .../__snapshots__/Table.test.tsx.snap | 12 +- .../__snapshots__/demo-extend.test.ts.snap | 14 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/empty.test.tsx.snap | 10 +- .../__snapshots__/demo-extend.test.ts.snap | 10 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 12 +- components/tabs/__tests__/demo-extend.test.ts | 7 +- components/tabs/__tests__/demo.test.ts | 7 +- components/tabs/__tests__/index.test.tsx | 9 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 6 +- components/tag/__tests__/index.test.tsx | 42 +- components/theme/util/getAlphaColor.ts | 4 +- components/theme/util/statistic.ts | 4 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 10 +- .../time-picker/__tests__/index.test.tsx | 2 +- components/time-picker/index.tsx | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 6 +- components/timeline/__tests__/index.test.tsx | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/tooltip.test.tsx.snap | 12 +- components/tooltip/__tests__/tooltip.test.tsx | 34 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 22 +- components/tour/__tests__/index.test.tsx | 4 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 12 +- .../__snapshots__/list.test.tsx.snap | 4 +- .../__snapshots__/search.test.tsx.snap | 6 +- .../transfer/__tests__/customize.test.tsx | 4 +- .../transfer/__tests__/dropdown.test.tsx | 32 +- components/transfer/__tests__/index.test.tsx | 32 +- components/transfer/__tests__/search.test.tsx | 12 +- .../__snapshots__/demo-extend.test.ts.snap | 20 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 10 +- .../tree-select/__tests__/index.test.tsx | 4 +- components/tree-select/index.tsx | 2 +- .../__snapshots__/demo-extend.test.ts.snap | 4 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/directory.test.tsx.snap | 24 +- .../__snapshots__/index.test.tsx.snap | 10 +- components/tree/__tests__/directory.test.tsx | 47 +- components/tree/__tests__/index.test.tsx | 4 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__snapshots__/demo.test.tsx.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 10 +- components/typography/__tests__/copy.test.tsx | 40 +- .../typography/__tests__/editable.test.tsx | 6 +- .../typography/__tests__/ellipsis.test.tsx | 63 +- .../__tests__/enter-key-callback.test.tsx | 10 +- .../typography/__tests__/index.test.tsx | 48 +- .../__snapshots__/demo-extend.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/upload.test.tsx.snap | 4 +- .../__snapshots__/uploadlist.test.tsx.snap | 16 +- components/upload/__tests__/dragger.test.tsx | 18 +- components/upload/__tests__/upload.test.tsx | 138 ++-- .../upload/__tests__/uploadlist.test.tsx | 187 ++--- .../__snapshots__/demo-extend.test.ts.snap | 4 +- .../__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 18 +- components/watermark/__tests__/index.test.tsx | 16 +- docs/react/contributing.en-US.md | 2 +- docs/react/contributing.zh-CN.md | 2 +- jest-puppeteer.config.js | 13 + package.json | 23 +- .../__mocks__}/@rc-component/trigger.tsx | 11 +- .../__mocks__}/copy-to-clipboard.ts | 0 .../__mocks__/rc-util/lib}/Portal.tsx | 6 +- tests/__mocks__/rc-virtual-list.ts | 3 + tests/__snapshots__/index.test.ts.snap | 2 +- tests/index.test.ts | 14 +- tests/setup.js | 54 ++ tests/setup.ts | 188 ----- tests/setupAfterEnv.ts | 110 +++ tests/setupPuppeteer.ts | 45 - tests/shared/accessibilityTest.tsx | 3 +- tests/shared/demoTest.tsx | 17 +- tests/shared/excludeWarning.tsx | 2 +- tests/shared/focusTest.tsx | 21 +- tests/shared/imageTest.tsx | 8 +- tests/shared/mountTest.tsx | 1 + tests/shared/rootPropsTest.tsx | 9 +- tests/shared/rtlTest.tsx | 1 + tests/utils.tsx | 10 +- tsconfig.json | 5 +- typings/jest.d.ts | 5 + typings/vitest.d.ts | 8 - vitest.config.ts | 68 -- vitest.image.config.ts | 14 - vitest.node.config.ts | 12 - vitest.site.config.ts | 12 - 444 files changed, 3577 insertions(+), 3489 deletions(-) create mode 100644 .jest.image.js create mode 100644 .jest.js create mode 100644 .jest.node.js create mode 100644 .jest.site.js delete mode 100644 __mocks__/rc-virtual-list.ts create mode 100644 jest-puppeteer.config.js rename {__mocks__ => tests/__mocks__}/@rc-component/trigger.tsx (65%) rename {__mocks__ => tests/__mocks__}/copy-to-clipboard.ts (100%) rename {__mocks__/rc-util/es => tests/__mocks__/rc-util/lib}/Portal.tsx (78%) create mode 100644 tests/__mocks__/rc-virtual-list.ts create mode 100644 tests/setup.js delete mode 100644 tests/setup.ts create mode 100644 tests/setupAfterEnv.ts delete mode 100644 tests/setupPuppeteer.ts create mode 100644 typings/jest.d.ts delete mode 100644 typings/vitest.d.ts delete mode 100644 vitest.config.ts delete mode 100644 vitest.image.config.ts delete mode 100644 vitest.node.config.ts delete mode 100644 vitest.site.config.ts diff --git a/.eslintignore b/.eslintignore index fabaa79cbf..6fbfa158dc 100644 --- a/.eslintignore +++ b/.eslintignore @@ -21,3 +21,4 @@ coverage **/*.d.ts # Scripts scripts/previewEditor/**/* +jest-stare diff --git a/.eslintrc.js b/.eslintrc.js index a23e6df7c6..5e01410968 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,7 +3,7 @@ module.exports = { 'airbnb', 'prettier', 'plugin:compat/recommended', - 'plugin:vitest/recommended', + 'plugin:jest/recommended', 'plugin:react/recommended', 'plugin:import/typescript', 'plugin:markdown/recommended', @@ -12,6 +12,7 @@ module.exports = { browser: true, node: true, jasmine: true, + jest: true, es6: true, }, settings: { @@ -24,15 +25,7 @@ module.exports = { }, }, parser: '@typescript-eslint/parser', - plugins: [ - 'react', - '@babel', - 'vitest', - '@typescript-eslint', - 'react-hooks', - 'unicorn', - 'markdown', - ], + plugins: ['react', '@babel', 'jest', '@typescript-eslint', 'react-hooks', 'unicorn', 'markdown'], // https://github.com/typescript-eslint/typescript-eslint/issues/46#issuecomment-470486034 overrides: [ { @@ -159,10 +152,8 @@ module.exports = { 'scripts/**', '**/*.test.js', '**/__tests__/*', - '__mocks__/**', '*.config.js', '**/*.md', - 'vitest*config.ts', ], }, ], @@ -188,12 +179,12 @@ module.exports = { 'no-restricted-globals': 0, 'max-classes-per-file': 0, - 'vitest/prefer-to-be': 0, - 'vitest/expect-expect': 0, - 'vitest/no-done-callback': 0, - 'vitest/valid-title': 0, - 'vitest/no-conditional-expect': 0, - 'vitest/no-standalone-expect': 0, + 'jest/no-test-callback': 0, + 'jest/expect-expect': 0, + 'jest/no-done-callback': 0, + 'jest/valid-title': 0, + 'jest/no-conditional-expect': 0, + 'jest/no-standalone-expect': 0, 'unicorn/better-regex': 2, 'unicorn/prefer-string-trim-start-end': 2, diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 767a1e34a7..3eb5482b89 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -191,7 +191,7 @@ jobs: # dom test - name: dom test if: ${{ matrix.module == 'dom' }} - run: npm test -- --shard=${{matrix.shard}} --coverage + run: npm test -- --maxWorkers=2 --shard=${{matrix.shard}} --coverage - name: persist coverages if: ${{ matrix.module == 'dom' && matrix.react == '17' }} @@ -347,7 +347,7 @@ jobs: - name: test # lib only run in master branch not in pull request if: ${{ github.event_name != 'pull_request' || matrix.module != 'lib' }} - run: npm test -- --shard=${{matrix.shard}} + run: npm test -- --maxWorkers=2 --shard=${{matrix.shard}} env: LIB_DIR: ${{ matrix.module }} needs: compile diff --git a/.gitignore b/.gitignore index 16cbdf1822..7693ccc269 100644 --- a/.gitignore +++ b/.gitignore @@ -58,6 +58,7 @@ components/version/token-meta.json # Image snapshot diff __diff_output__/ __image_snapshots__/ +/jest-stare /imageSnapshots /imageDiffSnapshots diff --git a/.jest.image.js b/.jest.image.js new file mode 100644 index 0000000000..fb42545326 --- /dev/null +++ b/.jest.image.js @@ -0,0 +1,23 @@ +const { moduleNameMapper, transformIgnorePatterns } = require('./.jest'); + +// jest config for image snapshots +module.exports = { + setupFiles: ['./tests/setup.js'], + moduleFileExtensions: ['ts', 'tsx', 'js', 'md'], + moduleNameMapper, + transform: { + '\\.tsx?$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor', + '\\.js$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor', + '\\.md$': './node_modules/@ant-design/tools/lib/jest/demoPreprocessor', + '\\.(jpg|png|gif|svg)$': './node_modules/@ant-design/tools/lib/jest/imagePreprocessor', + }, + testRegex: 'image\\.test\\.(j|t)s$', + transformIgnorePatterns, + globals: { + 'ts-jest': { + tsConfigFile: './tsconfig.test.json', + }, + }, + preset: 'jest-puppeteer', + testTimeout: 10000, +}; diff --git a/.jest.js b/.jest.js new file mode 100644 index 0000000000..08ff43ec46 --- /dev/null +++ b/.jest.js @@ -0,0 +1,68 @@ +const compileModules = ['react-sticky-box', 'rc-tween-one', '@babel', '@ant-design', 'countup.js']; + +const ignoreList = []; + +// cnpm use `_` as prefix +['', '_'].forEach((prefix) => { + compileModules.forEach((module) => { + ignoreList.push(`${prefix}${module}`); + }); +}); + +const transformIgnorePatterns = [ + // Ignore modules without es dir. + // Update: @babel/runtime should also be transformed + `/node_modules/(?!${ignoreList.join('|')})[^/]+?/(?!(es)/)`, +]; + +function getTestRegex(libDir) { + if (['dist', 'lib', 'es'].includes(libDir)) { + return 'demo\\.test\\.(j|t)sx?$'; + } + return '.*\\.test\\.(j|t)sx?$'; +} + +module.exports = { + verbose: true, + testEnvironment: 'jsdom', + setupFiles: ['./tests/setup.js', 'jest-canvas-mock'], + setupFilesAfterEnv: ['./tests/setupAfterEnv.ts'], + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'md'], + modulePathIgnorePatterns: ['/_site/'], + moduleNameMapper: { + '/\\.(css|less)$/': 'identity-obj-proxy', + '^antd$': '/components/index', + '^antd/es/(.*)$': '/components/$1', + }, + testPathIgnorePatterns: ['/node_modules/', 'dekko', 'node', 'image.test.js', 'image.test.ts'], + transform: { + '\\.tsx?$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor', + '\\.(m?)js$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor', + '\\.md$': './node_modules/@ant-design/tools/lib/jest/demoPreprocessor', + '\\.(jpg|png|gif|svg)$': './node_modules/@ant-design/tools/lib/jest/imagePreprocessor', + }, + testRegex: getTestRegex(process.env.LIB_DIR), + collectCoverageFrom: [ + 'components/**/*.{ts,tsx}', + '!components/*/style/index.tsx', + '!components/style/index.tsx', + '!components/*/locale/index.tsx', + '!components/*/__tests__/type.test.tsx', + '!components/**/*/interface.{ts,tsx}', + '!components/*/__tests__/image.test.{ts,tsx}', + '!components/__tests__/node.test.tsx', + '!components/*/demo/*.tsx', + '!components/*/design/**', + ], + transformIgnorePatterns, + globals: { + 'ts-jest': { + tsConfig: './tsconfig.test.json', + }, + }, + testEnvironmentOptions: { + url: 'http://localhost', + }, + // bail: true, + maxWorkers: '50%', +}; diff --git a/.jest.node.js b/.jest.node.js new file mode 100644 index 0000000000..54d6fb852d --- /dev/null +++ b/.jest.node.js @@ -0,0 +1,19 @@ +const { moduleNameMapper, transformIgnorePatterns } = require('./.jest'); + +// jest config for server render environment +module.exports = { + setupFiles: ['./tests/setup.js'], + setupFilesAfterEnv: ['./tests/setupAfterEnv.ts'], + moduleFileExtensions: ['ts', 'tsx', 'js', 'md'], + moduleNameMapper, + transform: { + '\\.tsx?$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor', + '\\.js$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor', + '\\.md$': './node_modules/@ant-design/tools/lib/jest/demoPreprocessor', + '\\.(jpg|png|gif|svg)$': './node_modules/@ant-design/tools/lib/jest/imagePreprocessor', + }, + testRegex: 'node\\.test\\.(j|t)sx$', + testEnvironment: 'node', + transformIgnorePatterns, + // bail: true, +}; diff --git a/.jest.site.js b/.jest.site.js new file mode 100644 index 0000000000..a1f19aee58 --- /dev/null +++ b/.jest.site.js @@ -0,0 +1,21 @@ +const { moduleNameMapper, transformIgnorePatterns } = require('./.jest'); + +// jest config for server render environment +module.exports = { + moduleFileExtensions: ['ts', 'tsx', 'js', 'md'], + moduleNameMapper, + transform: { + '\\.tsx?$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor', + '\\.js$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor', + '\\.md$': './node_modules/@ant-design/tools/lib/jest/demoPreprocessor', + '\\.(jpg|png|gif|svg)$': './node_modules/@ant-design/tools/lib/jest/imagePreprocessor', + }, + testRegex: 'check-site\\.(j|t)s$', + testEnvironment: 'node', + transformIgnorePatterns, + globals: { + 'ts-jest': { + tsConfigFile: './tsconfig.test.json', + }, + }, +}; diff --git a/__mocks__/rc-virtual-list.ts b/__mocks__/rc-virtual-list.ts deleted file mode 100644 index e99eeb9b9f..0000000000 --- a/__mocks__/rc-virtual-list.ts +++ /dev/null @@ -1,3 +0,0 @@ -import Mock from 'rc-virtual-list/es/mock'; - -export default Mock; diff --git a/components/__tests__/__snapshots__/index.test.ts.snap b/components/__tests__/__snapshots__/index.test.ts.snap index a6f6d0399c..8572ab796f 100644 --- a/components/__tests__/__snapshots__/index.test.ts.snap +++ b/components/__tests__/__snapshots__/index.test.ts.snap @@ -1,6 +1,6 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +// Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`antd > exports modules correctly 1`] = ` +exports[`antd exports modules correctly 1`] = ` [ "Affix", "Alert", @@ -37,9 +37,7 @@ exports[`antd > exports modules correctly 1`] = ` "List", "Mentions", "Menu", - "message", "Modal", - "notification", "Pagination", "Popconfirm", "Popover", @@ -61,7 +59,6 @@ exports[`antd > exports modules correctly 1`] = ` "Table", "Tabs", "Tag", - "theme", "TimePicker", "Timeline", "Tooltip", @@ -71,7 +68,10 @@ exports[`antd > exports modules correctly 1`] = ` "TreeSelect", "Typography", "Upload", - "version", "Watermark", + "message", + "notification", + "theme", + "version", ] `; diff --git a/components/__tests__/__snapshots__/setup.test.tsx.snap b/components/__tests__/__snapshots__/setup.test.tsx.snap index c3c40d4094..f2e4db6141 100644 --- a/components/__tests__/__snapshots__/setup.test.tsx.snap +++ b/components/__tests__/__snapshots__/setup.test.tsx.snap @@ -1,6 +1,6 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +// Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`SetUp.Test > diff of React 18 & React 17 1`] = ` +exports[`SetUp.Test diff of React 18 & React 17 1`] = ` NodeList [
bamboo diff --git a/components/__tests__/index.test.ts b/components/__tests__/index.test.ts index 8364ed2743..9ab8d246ba 100644 --- a/components/__tests__/index.test.ts +++ b/components/__tests__/index.test.ts @@ -1,7 +1,6 @@ -import * as antd from '..'; - const OLD_NODE_ENV = process.env.NODE_ENV; process.env.NODE_ENV = 'development'; +const antd = require('..'); describe('antd', () => { afterAll(() => { diff --git a/components/__tests__/node.test.tsx b/components/__tests__/node.test.tsx index 452abf2f25..cc63dd37e4 100644 --- a/components/__tests__/node.test.tsx +++ b/components/__tests__/node.test.tsx @@ -3,24 +3,21 @@ import * as React from 'react'; import { renderToString } from 'react-dom/server'; import type { Options } from '../../tests/shared/demoTest'; -globalThis.testConfig = {}; +(global as any).testConfig = {}; -vi.mock('../../tests/shared/demoTest', () => { +jest.mock('../../tests/shared/demoTest', () => { function fakeDemoTest(name: string, option: Options = {}) { - globalThis.testConfig[name] = option; + (global as any).testConfig[name] = option; } fakeDemoTest.rootPropsTest = () => {}; - return { - default: fakeDemoTest, - rootPropsTest: () => {}, - }; + return fakeDemoTest; }); describe('node', () => { beforeAll(() => { - vi.useFakeTimers().setSystemTime(new Date('2016-11-22')); + jest.useFakeTimers().setSystemTime(new Date('2016-11-22')); }); // Find the component exist demo test file @@ -30,27 +27,23 @@ describe('node', () => { const componentName = componentTestFile.match(/components\/([^/]*)\//)![1]; // Test for ssr - // eslint-disable-next-line vitest/valid-describe-callback - describe(componentName, async () => { + describe(componentName, () => { const demoList = globSync(`./components/${componentName}/demo/*.tsx`); // Use mock to get config - await import(`../../${componentTestFile}`); + require(`../../${componentTestFile}`); // eslint-disable-line global-require, import/no-dynamic-require + const option = (global as any).testConfig?.[componentName]; + demoList.forEach((demoFile) => { - const option = globalThis.testConfig?.[componentName]; const skip: string[] = option?.skip || []; const test = skip.some((skipMarkdown) => demoFile.includes(skipMarkdown)) ? it.skip : it; - test( - demoFile, - async () => { - const Demo = (await import(`../../${demoFile}`)).default; - expect(() => { - renderToString(); - }).not.toThrow(); - }, - 120000, - ); + test(demoFile, () => { + const Demo = require(`../../${demoFile}`).default; // eslint-disable-line global-require, import/no-dynamic-require + expect(() => { + renderToString(); + }).not.toThrow(); + }); }); }); }); diff --git a/components/_util/PurePanel.tsx b/components/_util/PurePanel.tsx index 39e5e2e991..49e8b2c16e 100644 --- a/components/_util/PurePanel.tsx +++ b/components/_util/PurePanel.tsx @@ -7,7 +7,7 @@ export interface BaseProps { style?: React.CSSProperties; } -/* c8 ignore start */ +/* istanbul ignore next */ export default function genPurePanel( Component: any, defaultPrefixCls?: string, @@ -96,4 +96,3 @@ export default function genPurePanel( ); } as typeof Component; } -/* c8 ignore stop */ diff --git a/components/_util/__tests__/getScroll.test.ts b/components/_util/__tests__/getScroll.test.ts index 0eb77443ad..8cb737ff1a 100644 --- a/components/_util/__tests__/getScroll.test.ts +++ b/components/_util/__tests__/getScroll.test.ts @@ -7,7 +7,7 @@ describe('getScroll', () => { }); it('getScroll window', async () => { - const scrollToSpy = vi.spyOn(window, 'scrollTo').mockImplementation((x, y) => { + const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => { window.pageXOffset = x; window.pageYOffset = y; }); @@ -18,7 +18,7 @@ describe('getScroll', () => { }); it('getScroll document', async () => { - const scrollToSpy = vi.spyOn(window, 'scrollTo').mockImplementation((x, y) => { + const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => { document.documentElement.scrollLeft = x; document.documentElement.scrollTop = y; }); @@ -30,7 +30,7 @@ describe('getScroll', () => { it('getScroll div', async () => { const div = document.createElement('div'); - const scrollToSpy = vi.spyOn(window, 'scrollTo').mockImplementation((x, y) => { + const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => { div.scrollLeft = x; div.scrollTop = y; }); @@ -42,7 +42,7 @@ describe('getScroll', () => { it('getScroll documentElement', async () => { const div: any = {}; - const scrollToSpy = vi.spyOn(window, 'scrollTo').mockImplementation((x, y) => { + const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => { div.scrollLeft = null; div.scrollTop = null; div.documentElement = {}; diff --git a/components/_util/__tests__/responsiveObserve.test.tsx b/components/_util/__tests__/responsiveObserve.test.tsx index b47595d4cd..d88c5ea606 100644 --- a/components/_util/__tests__/responsiveObserve.test.tsx +++ b/components/_util/__tests__/responsiveObserve.test.tsx @@ -11,7 +11,7 @@ describe('Test ResponsiveObserve', () => { return null; }; render(); - const subscribeFunc = vi.fn(); + const subscribeFunc = jest.fn(); const token = responsiveObserveRef.subscribe(subscribeFunc); expect( responsiveObserveRef.matchHandlers[responsiveObserveRef.responsiveMap.xs].mql.matches, diff --git a/components/_util/__tests__/scrollTo.test.ts b/components/_util/__tests__/scrollTo.test.ts index a6e7533c1c..5fe2e09502 100644 --- a/components/_util/__tests__/scrollTo.test.ts +++ b/components/_util/__tests__/scrollTo.test.ts @@ -2,10 +2,10 @@ import { waitFakeTimer } from '../../../tests/utils'; import scrollTo from '../scrollTo'; describe('Test ScrollTo function', () => { - const dateNowMock = vi.spyOn(Date, 'now'); + const dateNowMock = jest.spyOn(Date, 'now'); beforeAll(() => { - vi.useFakeTimers(); + jest.useFakeTimers(); }); beforeEach(() => { @@ -13,16 +13,16 @@ describe('Test ScrollTo function', () => { }); afterAll(() => { - vi.useRealTimers(); + jest.useRealTimers(); }); afterEach(() => { - vi.clearAllTimers(); + jest.clearAllTimers(); dateNowMock.mockClear(); }); it('test scrollTo', async () => { - const scrollToSpy = vi.spyOn(window, 'scrollTo').mockImplementation((_, y) => { + const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((_, y) => { window.scrollY = y; window.pageYOffset = y; }); @@ -36,7 +36,7 @@ describe('Test ScrollTo function', () => { }); it('test callback - option', async () => { - const cbMock = vi.fn(); + const cbMock = jest.fn(); scrollTo(1000, { callback: cbMock, }); diff --git a/components/_util/__tests__/util.test.tsx b/components/_util/__tests__/util.test.tsx index 7e806a606f..6b80428474 100644 --- a/components/_util/__tests__/util.test.tsx +++ b/components/_util/__tests__/util.test.tsx @@ -9,19 +9,19 @@ import TransButton from '../transButton'; describe('Test utils function', () => { describe('throttle', () => { beforeAll(() => { - vi.useFakeTimers(); + jest.useFakeTimers(); }); afterAll(() => { - vi.useRealTimers(); + jest.useRealTimers(); }); afterEach(() => { - vi.clearAllTimers(); + jest.clearAllTimers(); }); it('throttle function should work', async () => { - const callback = vi.fn(); + const callback = jest.fn(); const throttled = throttleByAnimationFrame(callback); expect(callback).not.toHaveBeenCalled(); @@ -34,7 +34,7 @@ describe('Test utils function', () => { }); it('throttle function should be canceled', async () => { - const callback = vi.fn(); + const callback = jest.fn(); const throttled = throttleByAnimationFrame(callback); throttled(); @@ -54,7 +54,7 @@ describe('Test utils function', () => { }); it('should trigger onClick when press enter', () => { - const onClick = vi.fn(); + const onClick = jest.fn(); const { container } = render(TransButton); @@ -75,7 +75,7 @@ describe('Test utils function', () => { }); it('isStyleSupport return false in service side', () => { - const spy = vi + const spy = jest .spyOn(window.document, 'documentElement', 'get') .mockImplementation(() => undefined as unknown as HTMLElement); expect(isStyleSupport('color')).toBe(false); diff --git a/components/_util/__tests__/warning.test.ts b/components/_util/__tests__/warning.test.ts index 377d3eaf69..00a952bd49 100644 --- a/components/_util/__tests__/warning.test.ts +++ b/components/_util/__tests__/warning.test.ts @@ -1,10 +1,8 @@ -import type { SpyInstance } from 'vitest'; - describe('Test warning', () => { - let spy: SpyInstance; + let spy: jest.SpyInstance; beforeAll(() => { - spy = vi.spyOn(console, 'error').mockImplementation(() => {}); + spy = jest.spyOn(console, 'error').mockImplementation(() => {}); }); afterAll(() => { @@ -12,7 +10,7 @@ describe('Test warning', () => { }); beforeEach(() => { - vi.resetModules(); + jest.resetModules(); }); afterEach(() => { diff --git a/components/_util/__tests__/wave.test.tsx b/components/_util/__tests__/wave.test.tsx index 4ad0abe81e..1311db9829 100644 --- a/components/_util/__tests__/wave.test.tsx +++ b/components/_util/__tests__/wave.test.tsx @@ -3,13 +3,11 @@ import mountTest from '../../../tests/shared/mountTest'; import { act, fireEvent, getByText, render, waitFakeTimer } from '../../../tests/utils'; import Wave from '../wave'; -let isVisible = vi.hoisted(() => true); +(global as any).isVisible = true; -vi.mock('rc-util/es/Dom/isVisible', () => { - const mockFn = () => isVisible; - return { - default: mockFn, - }; +jest.mock('rc-util/lib/Dom/isVisible', () => { + const mockFn = () => (global as any).isVisible; + return mockFn; }); describe('Wave component', () => { @@ -31,37 +29,44 @@ describe('Wave component', () => { } (window as any).ResizeObserver = FakeResizeObserver; - vi.useFakeTimers(); + jest.useFakeTimers(); }); afterAll(() => { - vi.useRealTimers(); + jest.useRealTimers(); expect(obCnt).not.toBe(0); expect(disCnt).not.toBe(0); }); beforeEach(() => { - isVisible = true; + (global as any).isVisible = true; document.body.innerHTML = ''; }); - afterEach(async () => { - await vi.runAllTimersAsync(); - vi.clearAllTimers(); + afterEach(() => { + jest.clearAllTimers(); const styles = document.getElementsByTagName('style'); for (let i = 0; i < styles.length; i += 1) { styles[i].remove(); } }); - function getWaveColor() { + function getWaveStyle() { + const styleObj: Record = {}; const { style } = document.querySelector('.ant-wave')!; - return style.getPropertyValue('--wave-color'); + style.cssText.split(';').forEach((kv) => { + if (kv.trim()) { + const cells = kv.split(':'); + styleObj[cells[0].trim()] = cells[1].trim(); + } + }); + + return styleObj; } function waitRaf() { act(() => { - vi.advanceTimersByTime(100); + jest.advanceTimersByTime(100); }); } @@ -85,7 +90,7 @@ describe('Wave component', () => { }); it('invisible in screen', () => { - isVisible = false; + (global as any).isVisible = false; const { container, unmount } = render( @@ -114,7 +119,9 @@ describe('Wave component', () => { fireEvent.click(container.querySelector('button')!); waitRaf(); - expect(getWaveColor()).toBeFalsy(); + const style = getWaveStyle(); + + expect(style['--wave-color']).toBeFalsy(); unmount(); }); @@ -122,7 +129,7 @@ describe('Wave component', () => { it('wave color is not grey', () => { const { container, unmount } = render( - , @@ -131,7 +138,8 @@ describe('Wave component', () => { fireEvent.click(container.querySelector('button')!); waitRaf(); - expect(getWaveColor()).toEqual('rgb(255, 0, 0)'); + const style = getWaveStyle(); + expect(style['--wave-color']).toEqual('red'); unmount(); }); @@ -139,14 +147,15 @@ describe('Wave component', () => { it('read wave color from border-top-color', () => { const { container, unmount } = render( -
button
+
button
, ); fireEvent.click(getByText(container, 'button')!); waitRaf(); - expect(getWaveColor()).toEqual('rgb(0, 0, 255)'); + const style = getWaveStyle(); + expect(style['--wave-color']).toEqual('blue'); unmount(); }); @@ -154,14 +163,15 @@ describe('Wave component', () => { it('read wave color from background color', () => { const { container, unmount } = render( -
button
+
button
, ); fireEvent.click(getByText(container, 'button')!); waitRaf(); - expect(getWaveColor()).toEqual('rgb(0, 128, 0)'); + const style = getWaveStyle(); + expect(style['--wave-color']).toEqual('green'); unmount(); }); @@ -169,14 +179,15 @@ describe('Wave component', () => { it('read wave color from border firstly', () => { const { container, unmount } = render( -
button
+
button
, ); fireEvent.click(getByText(container, 'button')!); waitRaf(); - expect(getWaveColor()).toEqual('rgb(255, 0, 0)'); + const style = getWaveStyle(); + expect(style['--wave-color']).toEqual('yellow'); unmount(); }); @@ -211,7 +222,7 @@ describe('Wave component', () => { }); it('not show when hidden', () => { - isVisible = false; + (global as any).isVisible = false; const { container } = render( @@ -260,7 +271,7 @@ describe('Wave component', () => { it('wave color should inferred if border is transparent and background is not', () => { const { container, unmount } = render( - , @@ -268,7 +279,8 @@ describe('Wave component', () => { fireEvent.click(container.querySelector('button')!); waitRaf(); - expect(getWaveColor()).toEqual('rgb(255, 0, 0)'); + const style = getWaveStyle(); + expect(style['--wave-color']).toEqual('red'); unmount(); }); @@ -285,7 +297,8 @@ describe('Wave component', () => { fireEvent.click(container.querySelector('button')!); waitRaf(); - expect(getWaveColor()).toEqual('red'); + const style = getWaveStyle(); + expect(style['--wave-color']).toEqual('red'); unmount(); }); diff --git a/components/affix/__tests__/Affix.test.tsx b/components/affix/__tests__/Affix.test.tsx index 7d2552e6fb..cbe9b44815 100644 --- a/components/affix/__tests__/Affix.test.tsx +++ b/components/affix/__tests__/Affix.test.tsx @@ -22,7 +22,7 @@ const AffixMounter: React.FC = ({ getInstance, ...restProps }) => { const container = useRef(null); useEffect(() => { if (container.current) { - container.current.addEventListener = vi + container.current.addEventListener = jest .fn() .mockImplementation((event: keyof HTMLElementEventMap, cb: (ev: Event) => void) => { events[event] = cb; @@ -42,12 +42,12 @@ describe('Affix Render', () => { rtlTest(Affix); accessibilityTest(Affix); - const domMock = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect'); + const domMock = jest.spyOn(HTMLElement.prototype, 'getBoundingClientRect'); const classRect: Record = { container: { top: 0, bottom: 100 } as DOMRect }; beforeEach(() => { - vi.useFakeTimers(); + jest.useFakeTimers(); }); beforeAll(() => { @@ -57,8 +57,8 @@ describe('Affix Render', () => { }); afterEach(() => { - vi.useRealTimers(); - vi.clearAllTimers(); + jest.useRealTimers(); + jest.clearAllTimers(); }); afterAll(() => { @@ -89,11 +89,7 @@ describe('Affix Render', () => { }); it('Anchor correct render when target is null', async () => { - render( - null}> - test - , - ); + render( null}>test); await waitFakeTimer(); }); @@ -113,7 +109,7 @@ describe('Affix Render', () => { }); it('updatePosition when offsetTop changed', async () => { - const onChange = vi.fn(); + const onChange = jest.fn(); const { container, rerender } = render(); await waitFakeTimer(); @@ -232,7 +228,7 @@ describe('Affix Render', () => { '.fixed', // outer ].forEach((selector) => { it(`trigger listener when size change: ${selector}`, async () => { - const updateCalled = vi.fn(); + const updateCalled = jest.fn(); const { container } = render( , { diff --git a/components/affix/__tests__/__snapshots__/Affix.test.tsx.snap b/components/affix/__tests__/__snapshots__/Affix.test.tsx.snap index 1d68a8068f..bd230c7ac4 100644 --- a/components/affix/__tests__/__snapshots__/Affix.test.tsx.snap +++ b/components/affix/__tests__/__snapshots__/Affix.test.tsx.snap @@ -1,6 +1,6 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +// Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Affix Render > rtl render > component should be rendered correctly in RTL direction 1`] = ` +exports[`Affix Render rtl render component should be rendered correctly in RTL direction 1`] = `
custom action 1`] = ` +exports[`Alert custom action 1`] = `
custom action 1`] = `
`; -exports[`Alert > rtl render > component should be rendered correctly in RTL direction 1`] = ` +exports[`Alert rtl render component should be rendered correctly in RTL direction 1`] = `
{ accessibilityTest(Alert); beforeAll(() => { - vi.useFakeTimers(); + jest.useFakeTimers(); }); afterAll(() => { - vi.useRealTimers(); + jest.useRealTimers(); }); it('should show close button and could be closed', async () => { - const onClose = vi.fn(); + const onClose = jest.fn(); render( { await userEvent.click(screen.getByRole('button', { name: /close/i })); + act(() => { + jest.runAllTimers(); + }); + expect(onClose).toHaveBeenCalledTimes(1); }); @@ -72,7 +76,7 @@ describe('Alert', () => { }); it('should show error as ErrorBoundary when children have error', () => { - const warnSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); + const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); expect(warnSpy).toHaveBeenCalledTimes(0); // @ts-expect-error // eslint-disable-next-line react/jsx-no-undef @@ -101,9 +105,11 @@ describe('Alert', () => { await userEvent.hover(screen.getByRole('alert')); - await waitFor(() => { - expect(screen.getByRole('tooltip')).toBeInTheDocument(); + act(() => { + jest.runAllTimers(); }); + + expect(screen.getByRole('tooltip')).toBeInTheDocument(); }); it('could be used with Popconfirm', async () => { @@ -117,6 +123,10 @@ describe('Alert', () => { ); await userEvent.click(screen.getByRole('alert')); + act(() => { + jest.runAllTimers(); + }); + expect(screen.getByRole('tooltip')).toBeInTheDocument(); }); diff --git a/components/anchor/__tests__/Anchor.test.tsx b/components/anchor/__tests__/Anchor.test.tsx index bd253574f6..51cf897264 100644 --- a/components/anchor/__tests__/Anchor.test.tsx +++ b/components/anchor/__tests__/Anchor.test.tsx @@ -2,7 +2,6 @@ import { resetWarned } from 'rc-util/lib/warning'; import React, { useState } from 'react'; import scrollIntoView from 'scroll-into-view-if-needed'; -import type { SpyInstance } from 'vitest'; import Anchor from '..'; import { act, fireEvent, render, waitFakeTimer } from '../../../tests/utils'; import Button from '../../button'; @@ -10,9 +9,8 @@ import type { AnchorDirection } from '../Anchor'; const { Link } = Anchor; -function createRootDiv() { +function createDiv() { const root = document.createElement('div'); - root.className = 'root'; document.body.appendChild(root); return root; } @@ -20,16 +18,18 @@ function createRootDiv() { let idCounter = 0; const getHashUrl = () => `Anchor-API-${idCounter++}`; -vi.mock('scroll-into-view-if-needed', () => ({ - default: vi.fn(), -})); +jest.mock('scroll-into-view-if-needed', () => jest.fn()); describe('Anchor Render', () => { - const getBoundingClientRectMock = vi.spyOn(HTMLHeadingElement.prototype, 'getBoundingClientRect'); - const getClientRectsMock = vi.spyOn(HTMLHeadingElement.prototype, 'getClientRects'); + const getBoundingClientRectMock = jest.spyOn( + HTMLHeadingElement.prototype, + 'getBoundingClientRect', + ); + const getClientRectsMock = jest.spyOn(HTMLHeadingElement.prototype, 'getClientRects'); + const scrollIntoViewMock = jest.createMockFromModule('scroll-into-view-if-needed'); beforeAll(() => { - vi.useFakeTimers(); + jest.useFakeTimers(); getBoundingClientRectMock.mockReturnValue({ width: 100, height: 100, @@ -39,18 +39,18 @@ describe('Anchor Render', () => { }); beforeEach(() => { - vi.useFakeTimers(); - vi.mocked(scrollIntoView).mockReset(); + jest.useFakeTimers(); + scrollIntoViewMock.mockReset(); }); afterEach(() => { - vi.clearAllTimers(); - vi.useRealTimers(); + jest.clearAllTimers(); + jest.useRealTimers(); }); afterAll(() => { - vi.clearAllTimers(); - vi.useRealTimers(); + jest.clearAllTimers(); + jest.useRealTimers(); getBoundingClientRectMock.mockRestore(); getClientRectsMock.mockRestore(); }); @@ -186,12 +186,12 @@ describe('Anchor Render', () => { const link = container.querySelector(`a[href="http://www.example.com/#${hash}"]`)!; fireEvent.click(link); await waitFakeTimer(); - expect(link.classList.contains('ant-anchor-link-title-active')).toBeTruthy(); + expect(link.classList).toContain('ant-anchor-link-title-active'); }); it('scrolls the page when clicking a link', async () => { - const root = createRootDiv(); - const scrollToSpy = vi.spyOn(window, 'scrollTo'); + const root = createDiv(); + const scrollToSpy = jest.spyOn(window, 'scrollTo'); render(
Q1
, { container: root }); const { container } = render( , @@ -200,14 +200,13 @@ describe('Anchor Render', () => { fireEvent.click(link); await waitFakeTimer(); expect(scrollToSpy).toHaveBeenCalled(); - scrollToSpy.mockRestore(); }); it('handleScroll should not be triggered when scrolling caused by clicking a link', async () => { const hash1 = getHashUrl(); const hash2 = getHashUrl(); - const root = createRootDiv(); - const onChange = vi.fn(); + const root = createDiv(); + const onChange = jest.fn(); render(
Hello
@@ -266,8 +265,8 @@ describe('Anchor Render', () => { it('targetOffset prop', async () => { const hash = getHashUrl(); - const scrollToSpy = vi.spyOn(window, 'scrollTo'); - const root = createRootDiv(); + const scrollToSpy = jest.spyOn(window, 'scrollTo'); + const root = createDiv(); render(

Hello

, { container: root }); const { container, rerender } = render( , @@ -291,16 +290,14 @@ describe('Anchor Render', () => { fireEvent.click(container.querySelector(`a[href="#${hash}"]`)!); await waitFakeTimer(); expect(scrollToSpy).toHaveBeenLastCalledWith(0, 800); - - scrollToSpy.mockRestore(); }); // https://github.com/ant-design/ant-design/issues/31941 it('targetOffset prop when contain spaces', async () => { const hash = `${getHashUrl()} s p a c e s`; - const scrollToSpy = vi.spyOn(window, 'scrollTo'); - const root = createRootDiv(); + const scrollToSpy = jest.spyOn(window, 'scrollTo'); + const root = createDiv(); render(

Hello

, { container: root }); const { container, rerender } = render( , @@ -322,8 +319,6 @@ describe('Anchor Render', () => { fireEvent.click(container.querySelector(`a[href="#${hash}"]`)!); await waitFakeTimer(); expect(scrollToSpy).toHaveBeenLastCalledWith(0, 800); - - scrollToSpy.mockRestore(); }); it('onClick event', () => { @@ -352,7 +347,7 @@ describe('Anchor Render', () => { it('onChange event', () => { const hash1 = getHashUrl(); const hash2 = getHashUrl(); - const onChange = vi.fn(); + const onChange = jest.fn(); const { container } = render( { const hash1 = getHashUrl(); const hash2 = getHashUrl(); - const beforeFn = vi.fn(); - const afterFn = vi.fn(); + const beforeFn = jest.fn(); + const afterFn = jest.fn(); const Demo: React.FC = () => { const [trigger, setTrigger] = useState(false); @@ -440,8 +435,8 @@ describe('Anchor Render', () => { getBoundingClientRectMock.mockReturnValue({ width: 0, height: 0, top: 1000 } as DOMRect); const hash = getHashUrl(); - const scrollToSpy = vi.spyOn(window, 'scrollTo'); - const root = createRootDiv(); + const scrollToSpy = jest.spyOn(window, 'scrollTo'); + const root = createDiv(); render(

Hello

, { container: root }); const { container, rerender } = render( @@ -475,14 +470,13 @@ describe('Anchor Render', () => { height: 100, top: 1000, } as DOMRect); - - scrollToSpy.mockRestore(); }); it('test edge case when container is not windows', async () => { const hash = getHashUrl(); - const root = createRootDiv(); + const scrollToSpy = jest.spyOn(window, 'scrollTo'); + const root = createDiv(); render(

Hello

, { container: root }); const { container, rerender } = render( @@ -498,23 +492,19 @@ describe('Anchor Render', () => {
, ); - // Since it's mock rect pos here. We need always reset the `scrollTop` for test - document.body.scrollTop = 0; fireEvent.click(container.querySelector(`a[href="#${hash}"]`)!); await waitFakeTimer(); - expect(document.body.scrollTop).toEqual(1000); + expect(scrollToSpy).toHaveBeenLastCalledWith(0, 800); - document.body.scrollTop = 0; setProps({ offsetTop: 100 }); fireEvent.click(container.querySelector(`a[href="#${hash}"]`)!); await waitFakeTimer(); - expect(document.body.scrollTop).toEqual(900); + expect(scrollToSpy).toHaveBeenLastCalledWith(0, 800); - document.body.scrollTop = 0; setProps({ targetOffset: 200 }); fireEvent.click(container.querySelector(`a[href="#${hash}"]`)!); await waitFakeTimer(); - expect(document.body.scrollTop).toEqual(800); + expect(scrollToSpy).toHaveBeenLastCalledWith(0, 800); }); describe('getCurrentAnchor', () => { @@ -539,7 +529,7 @@ describe('Anchor Render', () => { it('should trigger onChange when have getCurrentAnchor', () => { const hash1 = getHashUrl(); const hash2 = getHashUrl(); - const onChange = vi.fn(); + const onChange = jest.fn(); const { container } = render( { it('getCurrentAnchor have default link as argument', () => { const hash1 = getHashUrl(); const hash2 = getHashUrl(); - const getCurrentAnchor = vi.fn(); + const getCurrentAnchor = jest.fn(); const { container } = render( { describe('scroll x', () => { it('targetOffset horizontal', async () => { const hash = getHashUrl(); - const scrollToSpy = vi.spyOn(window, 'scrollTo'); - const root = createRootDiv(); + const scrollToSpy = jest.spyOn(window, 'scrollTo'); + const root = createDiv(); render(

Hello

, { container: root }); const { container, rerender } = render( { fireEvent.click(container.querySelector(`a[href="#${hash}"]`)!); await waitFakeTimer(); expect(scrollToSpy).toHaveBeenLastCalledWith(0, 800); - - scrollToSpy.mockRestore(); }); }); @@ -768,12 +756,12 @@ describe('Anchor Render', () => { const link = container.querySelector(`a[href="http://www.example.com/#${hash}"]`)!; fireEvent.click(link); await waitFakeTimer(); - expect(link.classList.contains('ant-anchor-link-title-active')).toBeTruthy(); + expect(link.classList).toContain('ant-anchor-link-title-active'); }); it('scrolls the page when clicking a link', async () => { - const root = createRootDiv(); - const scrollToSpy = vi.spyOn(window, 'scrollTo'); + const root = createDiv(); + const scrollToSpy = jest.spyOn(window, 'scrollTo'); render(
Q1
, { container: root }); const { container } = render( @@ -784,15 +772,13 @@ describe('Anchor Render', () => { fireEvent.click(link); await waitFakeTimer(); expect(scrollToSpy).toHaveBeenCalled(); - - scrollToSpy.mockRestore(); }); it('handleScroll should not be triggered when scrolling caused by clicking a link', async () => { const hash1 = getHashUrl(); const hash2 = getHashUrl(); - const root = createRootDiv(); - const onChange = vi.fn(); + const root = createDiv(); + const onChange = jest.fn(); render(
Hello
@@ -865,10 +851,10 @@ describe('Anchor Render', () => { }); describe('warning', () => { - let errSpy: SpyInstance; + let errSpy: jest.SpyInstance; beforeEach(() => { resetWarned(); - errSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); + errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); }); afterEach(() => { @@ -985,14 +971,14 @@ describe('Anchor Render', () => { const toggleButton = wrapper.container.querySelector('button')!; fireEvent.click(toggleButton); - act(() => vi.runAllTimers()); + act(() => jest.runAllTimers()); expect(!!ink.style.left).toBe(true); expect(!!ink.style.width).toBe(true); expect(ink.style.top).toBe(''); expect(ink.style.height).toBe(''); fireEvent.click(toggleButton); - act(() => vi.runAllTimers()); + act(() => jest.runAllTimers()); expect(!!ink.style.top).toBe(true); expect(!!ink.style.height).toBe(true); expect(ink.style.left).toBe(''); diff --git a/components/anchor/__tests__/__snapshots__/Anchor.test.tsx.snap b/components/anchor/__tests__/__snapshots__/Anchor.test.tsx.snap index 0a030f440b..aa6da33ae7 100644 --- a/components/anchor/__tests__/__snapshots__/Anchor.test.tsx.snap +++ b/components/anchor/__tests__/__snapshots__/Anchor.test.tsx.snap @@ -1,6 +1,6 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +// Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Anchor Render > render items and ignore jsx children 1`] = ` +exports[`Anchor Render render items and ignore jsx children 1`] = `
render items and ignore jsx children 1`] = `
`; -exports[`Anchor Render > renders items correctly 1`] = ` +exports[`Anchor Render renders items correctly 1`] = `
renders items correctly 1`] = `
`; -exports[`Anchor Render > renders items correctly#horizontal 1`] = ` +exports[`Anchor Render renders items correctly#horizontal 1`] = `
rtl render > component should be rendered correctly in RTL direction 1`] = ` +exports[`App rtl render component should be rendered correctly in RTL direction 1`] = `
`; -exports[`App > single 1`] = ` +exports[`App single 1`] = `
diff --git a/components/app/__tests__/index.test.tsx b/components/app/__tests__/index.test.tsx index cf58ca84b3..c738a60a20 100644 --- a/components/app/__tests__/index.test.tsx +++ b/components/app/__tests__/index.test.tsx @@ -11,12 +11,12 @@ describe('App', () => { rtlTest(App); beforeEach(() => { - vi.useFakeTimers(); + jest.useFakeTimers(); }); afterEach(() => { - vi.clearAllTimers(); - vi.useRealTimers(); + jest.clearAllTimers(); + jest.useRealTimers(); }); it('single', () => { @@ -134,12 +134,10 @@ describe('App', () => { it('support style', () => { const { container } = render( - +
test
, ); - expect(container.querySelector('.ant-app')).toHaveStyle( - 'color: rgb(255, 0, 0);', - ); + expect(container.querySelector('.ant-app')).toHaveStyle('color: blue;'); }); }); diff --git a/components/auto-complete/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/auto-complete/__tests__/__snapshots__/demo-extend.test.ts.snap index f4a2dc307a..18443f6349 100644 --- a/components/auto-complete/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/auto-complete/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -1,4 +1,4 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`renders components/auto-complete/demo/basic.tsx extend context correctly 1`] = ` Array [ @@ -235,7 +235,7 @@ exports[`renders components/auto-complete/demo/certain-category.tsx extend conte >
rtl render > component should be rendered correctly in RTL direction 1`] = ` +exports[`AutoComplete rtl render component should be rendered correctly in RTL direction 1`] = `