From 27b6e679c08e8a98d5eb5a0f79b31ccaa3cf8430 Mon Sep 17 00:00:00 2001 From: dengfuping Date: Sun, 18 Feb 2024 18:01:40 +0800 Subject: [PATCH 1/3] improve(test): Migrate from jest to vitest --- jest.config.ts | 28 - package.json | 41 +- .../__tests__/__snapshots__/ref.test.tsx.snap | 26 - .../__tests__/__snapshots__/ref.test.tsx.snap | 26 - .../__tests__/__snapshots__/ref.test.tsx.snap | 26 - .../__snapshots__/donut.test.tsx.snap | 91 - packages/charts/vitest.config.ts | 4 + packages/codemod/vitest.config.ts | 4 + .../__snapshots__/index.test.tsx.snap | 8 +- .../design/src/badge/__tests__/index.test.tsx | 1 + .../__snapshots__/spin.test.tsx.snap | 6 +- .../styleProviderProps.test.tsx.snap | 4 +- .../__tests__/navigate.test.tsx | 2 +- .../__snapshots__/index.test.tsx.snap | 14 +- .../__snapshots__/index.test.tsx.snap | 20 +- .../src/drawer/__tests__/index.test.tsx | 7 +- .../__snapshots__/index.test.tsx.snap | 10 +- .../__snapshots__/index.test.tsx.snap | 8 +- .../__snapshots__/progress.test.tsx.snap | 834 ++-- .../__snapshots__/index.test.tsx.snap | 6 +- .../__snapshots__/index.test.tsx.snap | 8 +- .../__snapshots__/index.test.tsx.snap | 8 +- .../__snapshots__/index.test.tsx.snap | 8 +- .../design/src/tag/__tests__/index.test.tsx | 7 +- .../src/tooltip/__tests__/index.test.tsx | 11 +- packages/design/vitest.config.ts | 4 + packages/icons/vitest.config.ts | 4 + .../{__test__ => __tests__}/index.test.tsx | 2 +- .../{__test__ => __tests__}/index.test.tsx | 2 +- .../{__test__ => __tests__}/index.test.tsx | 2 +- .../__snapshots__/index.test.tsx.snap | 6 +- .../{__test__ => __tests__}/index.test.tsx | 20 +- .../__snapshots__/index.test.tsx.snap | 10 +- .../{__test__ => __tests__}/index.test.tsx | 11 +- .../{__test__ => __tests__}/index.test.tsx | 14 +- packages/ui/tsconfig.json | 3 + packages/ui/vitest.config.ts | 4 + packages/util/vitest.config.ts | 4 + pnpm-lock.yaml | 4439 +++++++---------- tests/setupTests.ts | 62 +- tests/shared/demoTest.tsx | 8 +- tests/shared/excludeWarning.tsx | 2 +- tests/shared/rootPropsTest.tsx | 4 +- tests/util.ts | 5 +- tests/vitest.setup.ts | 3 + tsconfig.json | 2 +- vitest.config.ts | 52 + vitest.workspace.ts | 1 + 48 files changed, 2565 insertions(+), 3307 deletions(-) delete mode 100644 jest.config.ts delete mode 100644 packages/charts/src/Area/__tests__/__snapshots__/ref.test.tsx.snap delete mode 100644 packages/charts/src/DualAxes/__tests__/__snapshots__/ref.test.tsx.snap delete mode 100644 packages/charts/src/Line/__tests__/__snapshots__/ref.test.tsx.snap delete mode 100644 packages/charts/src/Pie/__tests__/__snapshots__/donut.test.tsx.snap create mode 100644 packages/charts/vitest.config.ts create mode 100644 packages/codemod/vitest.config.ts create mode 100644 packages/design/vitest.config.ts create mode 100644 packages/icons/vitest.config.ts rename packages/ui/src/BasicLayout/{__test__ => __tests__}/index.test.tsx (98%) rename packages/ui/src/ContentWithIcon/{__test__ => __tests__}/index.test.tsx (87%) rename packages/ui/src/ContentWithQuestion/{__test__ => __tests__}/index.test.tsx (87%) rename packages/ui/src/Login/{__test__ => __tests__}/index.test.tsx (78%) rename packages/ui/src/Ranger/{__test__ => __tests__}/index.test.tsx (95%) rename packages/ui/src/Welcome/{__test__ => __tests__}/index.test.tsx (84%) create mode 100644 packages/ui/tsconfig.json create mode 100644 packages/ui/vitest.config.ts create mode 100644 packages/util/vitest.config.ts create mode 100644 tests/vitest.setup.ts create mode 100644 vitest.config.ts create mode 100644 vitest.workspace.ts diff --git a/jest.config.ts b/jest.config.ts deleted file mode 100644 index 846e9fd64..000000000 --- a/jest.config.ts +++ /dev/null @@ -1,28 +0,0 @@ -const { readdirSync } = require('fs'); -const { join } = require('path'); - -const pkgList = readdirSync(join(__dirname, './packages')).filter( - (pkg: string) => pkg.charAt(0) !== '.' -); - -const moduleNameMapper = { - '^react$': require.resolve('react'), - '^.+\\.svg$': require.resolve('jest-svg-transformer'), - '\\.(css|less|sass|scss)$': require.resolve('identity-obj-proxy'), -}; - -pkgList.forEach((shortName: string) => { - const name = `@oceanbase/${shortName}`; - moduleNameMapper[name] = join(__dirname, `./packages/${shortName}/src`); -}); - -module.exports = { - testEnvironment: 'jsdom', - transform: { - '^.+\\.(ts|tsx)?$': 'ts-jest', - '^.+\\.(js|jsx)?$': 'babel-jest', - }, - transformIgnorePatterns: [`/node_modules/(?!${[].join('|')})`], - moduleNameMapper, - setupFilesAfterEnv: ['./tests/setupTests.ts'], -}; diff --git a/package.json b/package.json index 484ee01a6..b5472fc91 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,9 @@ "site:deploy": "gh-pages -d site", "postpublish": "npm run sync:other-npm", "sync:other-npm": "node -e 'require(\"./scripts/sync-cnpm-and-tnpm\")()'", - "test": "NODE_OPTIONS=--max_old_space_size=4096 cross-env TZ=UTC jest", - "test:coverage": "NODE_OPTIONS=--max_old_space_size=4096 cross-env TZ=UTC TEST_LOG=none jest --coverage", - "test:update": "NODE_OPTIONS=--max_old_space_size=4096 cross-env TZ=UTC jest --updateSnapshot", + "test": "cross-env TZ=UTC vitest", + "test:coverage": "cross-env TZ=UTC TEST_LOG=none vitest --coverage", + "test:update": "cross-env TZ=UTC vitest -u", "lint": "eslint --cache --ext .js,.jsx,.ts,.tsx", "lint:fix": "eslint --cache --ext .js,.jsx,.ts,.tsx --fix --format=pretty", "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,less,md,json}\"", @@ -60,23 +60,20 @@ "@testing-library/react": "^14.2.1", "@testing-library/react-hooks": "^8.0.1", "@testing-library/user-event": "^14.5.2", - "@types/jest": "^29.5.12", "@types/lodash": "^4.14.202", - "@types/node": "^20.11.16", - "@types/react": "^18.2.54", + "@types/node": "^20.11.19", + "@types/react": "^18.2.56", "@umijs/fabric": "^4.0.1", "@umijs/test": "^4.1.1", - "@vercel/analytics": "^1.1.3", - "antd": "^5.14.0", + "@vercel/analytics": "^1.2.1", + "antd": "^5.14.1", "antd-style": "^3.6.1", - "antd-token-previewer": "^2.0.5", - "babel-jest": "^29.7.0", + "antd-token-previewer": "^2.0.8", "classnames": "^2.5.1", "copy-to-clipboard": "^3.3.3", "cross-env": "^7.0.3", "dayjs": "^1.11.10", "dumi": "^2.2.17", - "eslint-plugin-jest": "^27.6.3", "execa": "^5.1.1", "father": "^4.4.0", "fs-extra": "^11.2.0", @@ -86,22 +83,17 @@ "husky": "^8.0.3", "identity-obj-proxy": "^3.0.0", "isomorphic-fetch": "^3.0.0", - "jest": "^29.7.0", - "jest-canvas-mock": "^2.5.2", "jest-environment-jsdom": "^29.7.0", - "jest-fetch-mock": "^3.0.3", - "jest-svg-transformer": "^1.0.0", "jsonml-to-react-element": "^1.1.11", "jsonml.js": "^0.1.0", "lerna": "^8.1.2", "lint-staged": "^15.2.2", "lodash": "^4.17.21", - "lz-string": "^1.5.0", "mockdate": "^3.0.5", "prettier": "^3.2.5", "prismjs": "^1.29.0", "rc-checkbox": "^3.1.0", - "rc-drawer": "^7.0.0", + "rc-drawer": "^7.1.0", "rc-footer": "^0.6.8", "rc-resize-observer": "^1.4.0", "rc-segmented": "^2.3.0", @@ -111,17 +103,16 @@ "react-color": "^2.19.3", "react-copy-to-clipboard": "^5.1.0", "react-dom": "^18.2.0", - "react-fast-marquee": "^1.6.3", + "react-fast-marquee": "^1.6.4", "react-intl": "^6.6.2", - "react-router-dom": "^6.22.0", + "react-router-dom": "^6.22.1", "runscript": "^1.6.0", - "svg-jest": "^1.0.1", - "sylvanas": "^0.6.1", - "ts-jest": "^29.1.2", "ts-node": "^10.9.2", "typescript": "^5.3.3", - "vanilla-jsoneditor": "^0.21.5", - "web-vitals": "^3.5.2", - "yorkie": "^2.0.0" + "vanilla-jsoneditor": "^0.21.6", + "vitest": "^1.3.0", + "vitest-canvas-mock": "^0.3.3", + "vitest-fetch-mock": "^0.2.2", + "web-vitals": "^3.5.2" } } diff --git a/packages/charts/src/Area/__tests__/__snapshots__/ref.test.tsx.snap b/packages/charts/src/Area/__tests__/__snapshots__/ref.test.tsx.snap deleted file mode 100644 index 5594283d9..000000000 --- a/packages/charts/src/Area/__tests__/__snapshots__/ref.test.tsx.snap +++ /dev/null @@ -1,26 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Area ref ref 1`] = ` -
-
- -
- - -`; diff --git a/packages/charts/src/DualAxes/__tests__/__snapshots__/ref.test.tsx.snap b/packages/charts/src/DualAxes/__tests__/__snapshots__/ref.test.tsx.snap deleted file mode 100644 index 62365b71f..000000000 --- a/packages/charts/src/DualAxes/__tests__/__snapshots__/ref.test.tsx.snap +++ /dev/null @@ -1,26 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`DualAxes ref ref 1`] = ` -
-
- -
- - -`; diff --git a/packages/charts/src/Line/__tests__/__snapshots__/ref.test.tsx.snap b/packages/charts/src/Line/__tests__/__snapshots__/ref.test.tsx.snap deleted file mode 100644 index 472492495..000000000 --- a/packages/charts/src/Line/__tests__/__snapshots__/ref.test.tsx.snap +++ /dev/null @@ -1,26 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Line ref ref 1`] = ` -
-
- -
- - -`; diff --git a/packages/charts/src/Pie/__tests__/__snapshots__/donut.test.tsx.snap b/packages/charts/src/Pie/__tests__/__snapshots__/donut.test.tsx.snap deleted file mode 100644 index 43467c8ae..000000000 --- a/packages/charts/src/Pie/__tests__/__snapshots__/donut.test.tsx.snap +++ /dev/null @@ -1,91 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`donut floor number 1`] = ` -
-
- -
-
- 总数 -
-
-
-
- 21.16 -
-
-
- - -`; - -exports[`donut statistic title and content formatter 1`] = ` -
-
- -
-
- custom title -
-
-
-
- custom content -
-
-
- - -`; diff --git a/packages/charts/vitest.config.ts b/packages/charts/vitest.config.ts new file mode 100644 index 000000000..132a51652 --- /dev/null +++ b/packages/charts/vitest.config.ts @@ -0,0 +1,4 @@ +import { defineProject, mergeConfig } from 'vitest/config'; +import configShared from '../../vitest.config'; + +export default mergeConfig(configShared, defineProject({})); diff --git a/packages/codemod/vitest.config.ts b/packages/codemod/vitest.config.ts new file mode 100644 index 000000000..132a51652 --- /dev/null +++ b/packages/codemod/vitest.config.ts @@ -0,0 +1,4 @@ +import { defineProject, mergeConfig } from 'vitest/config'; +import configShared from '../../vitest.config'; + +export default mergeConfig(configShared, defineProject({})); diff --git a/packages/design/src/badge/__tests__/__snapshots__/index.test.tsx.snap b/packages/design/src/badge/__tests__/__snapshots__/index.test.tsx.snap index 27be679dd..12702de4f 100644 --- a/packages/design/src/badge/__tests__/__snapshots__/index.test.tsx.snap +++ b/packages/design/src/badge/__tests__/__snapshots__/index.test.tsx.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`Badge status custom icon 1`] = ` +exports[`Badge > status custom icon 1`] = ` `; -exports[`Badge status dot 1`] = ` +exports[`Badge > status dot 1`] = ` @@ -51,7 +51,7 @@ exports[`Badge status dot 1`] = ` `; -exports[`Badge status icon 1`] = ` +exports[`Badge > status icon 1`] = ` spin.indicator should work 1`] = `
`; -exports[`ConfigProvider spin spin.indicator should work in nested ConfigProvider 1`] = ` +exports[`ConfigProvider spin > spin.indicator should work in nested ConfigProvider 1`] = `
`; +exports[`ConfigProvider styleProviderProps > ConfigProvider styleProviderProps.hashPriority 1`] = `
`; diff --git a/packages/design/src/config-provider/__tests__/navigate.test.tsx b/packages/design/src/config-provider/__tests__/navigate.test.tsx index dc0d43e40..56fce9415 100644 --- a/packages/design/src/config-provider/__tests__/navigate.test.tsx +++ b/packages/design/src/config-provider/__tests__/navigate.test.tsx @@ -1,7 +1,7 @@ import React, { useContext } from 'react'; import { BrowserRouter, useNavigate } from 'react-router-dom'; import { render } from '@testing-library/react'; -import ConfigProvider from '..'; +import { ConfigProvider } from '@oceanbase/design'; describe('ConfigProvider navigate', () => { it('navigate should work', () => { diff --git a/packages/design/src/descriptions/__tests__/__snapshots__/index.test.tsx.snap b/packages/design/src/descriptions/__tests__/__snapshots__/index.test.tsx.snap index 0519fb244..7e6f830a2 100644 --- a/packages/design/src/descriptions/__tests__/__snapshots__/index.test.tsx.snap +++ b/packages/design/src/descriptions/__tests__/__snapshots__/index.test.tsx.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`Descriptions contentProps should work for Descriptions.Item 1`] = ` +exports[`Descriptions > contentProps should work for Descriptions.Item 1`] = `
@@ -51,7 +51,7 @@ exports[`Descriptions contentProps should work for Descriptions.Item 1`] = `
`; -exports[`Descriptions contentProps should work for items 1`] = ` +exports[`Descriptions > contentProps should work for items 1`] = `
@@ -102,7 +102,7 @@ exports[`Descriptions contentProps should work for items 1`] = `
`; -exports[`Descriptions remove colon for vertical layout by default for Descriptions.Item 1`] = ` +exports[`Descriptions > remove colon for vertical layout by default for Descriptions.Item 1`] = `
@@ -302,7 +302,7 @@ exports[`Descriptions remove colon for vertical layout by default for Descriptio
`; -exports[`Descriptions remove colon for vertical layout by default for items 1`] = ` +exports[`Descriptions > remove colon for vertical layout by default for items 1`] = `
@@ -502,7 +502,7 @@ exports[`Descriptions remove colon for vertical layout by default for items 1`]
`; -exports[`Descriptions render for Descriptions.Item 1`] = ` +exports[`Descriptions > render for Descriptions.Item 1`] = `
@@ -649,7 +649,7 @@ exports[`Descriptions render for Descriptions.Item 1`] = `
`; -exports[`Descriptions render for items 1`] = ` +exports[`Descriptions > render for items 1`] = `
diff --git a/packages/design/src/drawer/__tests__/__snapshots__/index.test.tsx.snap b/packages/design/src/drawer/__tests__/__snapshots__/index.test.tsx.snap index 1deda45c6..61f879b0b 100644 --- a/packages/design/src/drawer/__tests__/__snapshots__/index.test.tsx.snap +++ b/packages/design/src/drawer/__tests__/__snapshots__/index.test.tsx.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`Drawer render correctly 1`] = ` +exports[`Drawer > render correctly 1`] = `
`; -exports[`Drawer render with confirmLoading and okButtonProps 1`] = ` +exports[`Drawer > render with confirmLoading and okButtonProps 1`] = `