From f39d653a73936fa121b6e3dc052ea3fd00c22cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AF=B8=E5=B2=B3?= Date: Mon, 11 Mar 2024 19:51:23 +0800 Subject: [PATCH] [Feature Branch] improve(test): Migrate from jest to vitest (#483) * improve(test): Migrate from jest to vitest * fix(test): Update snapshots * fix(test): Set TZ=UTC env and exclude part of charts tests for now --- jest.config.ts | 28 - package.json | 23 +- .../__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 | 850 ++-- .../__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 | 3529 +++++------------ tests/globalSetup.ts | 3 + tests/setupTests.ts | 66 +- tests/shared/demoTest.tsx | 8 +- tests/shared/excludeWarning.tsx | 2 +- tests/shared/rootPropsTest.tsx | 10 +- tests/util.ts | 5 +- tests/vitest.setup.ts | 3 + tsconfig.json | 2 +- vitest.config.ts | 62 + vitest.workspace.ts | 1 + 49 files changed, 1746 insertions(+), 3237 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/globalSetup.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 b224a5b14..4ab688425 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 vitest", + "test:coverage": "cross-env TEST_LOG=none vitest --coverage", + "test:update": "cross-env 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,14 +60,13 @@ "@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.25", "@types/react": "^18.2.64", "@umijs/fabric": "^4.0.1", "@umijs/test": "^4.1.2", "@vercel/analytics": "^1.2.2", - "antd": "^5.15.1", + "antd": "^5.15.0", "antd-style": "^3.6.1", "antd-token-previewer": "^2.0.8", "babel-jest": "^29.7.0", @@ -86,17 +85,12 @@ "husky": "^9.0.11", "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", @@ -115,13 +109,12 @@ "react-intl": "^6.6.2", "react-router-dom": "^6.22.3", "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.4.2", "vanilla-jsoneditor": "^0.21.6", - "web-vitals": "^3.5.2", - "yorkie": "^2.0.0" + "vitest": "^1.3.1", + "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`] = `