Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate to vitest #42506

Merged
merged 83 commits into from Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
5b1a48f
chore: migrate to vitest
Dunqing May 20, 2023
6847651
chore: update ci
Dunqing May 20, 2023
ccde072
fix: test correctly
Dunqing May 20, 2023
a80bb37
test: support puppeteer
Dunqing May 20, 2023
a3b1ad7
chore: update coverage
Dunqing May 21, 2023
b1b08f0
chore: update include/exclude
Dunqing May 21, 2023
1bf841d
chore: update config
Dunqing May 21, 2023
dd50294
test: update incorrect tests
Dunqing May 21, 2023
1e3a1c6
Merge remote-tracking branch 'upstream/master' into chore/migrate-to-…
Dunqing May 21, 2023
5df1070
chore: update script
Dunqing May 21, 2023
a0f309c
chore: update
Dunqing May 21, 2023
abb4433
fix: should close browser at the ended
Dunqing May 21, 2023
1852fd6
chore: improve
Dunqing May 21, 2023
8a1f803
fix: test cause tsc error
Dunqing May 21, 2023
d0ed782
fix: eslint error
Dunqing May 21, 2023
de904b8
chore: exclude correctly
Dunqing May 21, 2023
aa57941
test: update snap and fix some tests
Dunqing May 21, 2023
63ac037
chore: update test config
Dunqing May 21, 2023
6acbbf6
fix: countup.js
Dunqing May 21, 2023
dfca78d
fix: incorrect test
Dunqing May 21, 2023
219d8c7
chore: update reference
Dunqing May 21, 2023
76f7edf
test: update
Dunqing May 21, 2023
f6b1388
fix: countup.js
Dunqing May 21, 2023
d956c15
fix: timeout
Dunqing May 21, 2023
becdef2
chore: update site test
Dunqing May 21, 2023
80169dc
fix: fixed countup version
Dunqing May 21, 2023
bcf4abd
chore: remove unsed code
Dunqing May 21, 2023
d6b376a
test: update
Dunqing May 21, 2023
4afadfc
test: update demo timeout
Dunqing May 21, 2023
10e6d03
test: update timeout
Dunqing May 22, 2023
17c4a6a
chore: update image test
Dunqing May 22, 2023
8219b48
chore: update threads
Dunqing May 22, 2023
ff28025
fix: image/svg+xml test failed
Dunqing May 22, 2023
0c41de5
chore: limits threads
Dunqing May 22, 2023
66748f6
test: update test coverage include
Dunqing May 22, 2023
bc46490
chore: remove jest files
Dunqing May 22, 2023
943d825
chore: rename jest to vi
Dunqing May 22, 2023
c9c997a
chore: update document
Dunqing May 22, 2023
62438ba
chore: fix missing @types/jsdom
Dunqing May 22, 2023
8b4c898
chore: update coverage
Dunqing May 22, 2023
6804533
Merge remote-tracking branch 'upstream/master' into chore/migrate-to-…
Dunqing May 22, 2023
9d14b14
chore: update snap
Dunqing May 22, 2023
6afc3c9
fix:watermark test cases are incorrect
Dunqing May 22, 2023
795a1ad
feat: update ignore comment
Dunqing May 22, 2023
d9fb14b
Merge remote-tracking branch 'upstream/master' into chore/migrate-to-…
Dunqing May 22, 2023
fbf819d
chore: merge master
zombieJ May 26, 2023
eb0a53a
test: fix test case
zombieJ May 26, 2023
5de5b15
test: reset body scrollTop
zombieJ May 26, 2023
3482cc0
test: clean up
zombieJ May 26, 2023
a5b41d8
Merge remote-tracking branch 'origin/master' into chore/migrate-to-vi…
zombieJ May 26, 2023
0a6f50a
test: use vi
zombieJ May 26, 2023
86a831d
test: update snapshot
zombieJ May 26, 2023
96ae932
test: update snapshot
zombieJ May 26, 2023
938234e
Merge remote-tracking branch 'origin/master' into chore/migrate-to-vi…
zombieJ May 26, 2023
90dc315
Merge remote-tracking branch 'upstream/master' into chore/migrate-to-…
Dunqing May 30, 2023
7b2ce43
test: fix dropdown test failed
Dunqing May 30, 2023
9a08d4f
fix: toHaveStyle cause test fail
Dunqing May 30, 2023
7f92eff
test: improve test case
Dunqing May 30, 2023
f85995b
test: fix
Dunqing May 30, 2023
61c126b
fix: color failed, refer to https://github.com/jsdom/jsdom/pull/3560
Dunqing May 31, 2023
70d1db8
Merge remote-tracking branch 'upstream/master' into chore/migrate-to-…
Dunqing May 31, 2023
3b12214
test: fix
Dunqing Jun 1, 2023
eb3fde6
test: fix
Dunqing Jun 1, 2023
72faa41
Merge remote-tracking branch 'upstream/master' into chore/migrate-to-…
Dunqing Jun 1, 2023
578792a
test: fix circular import
Dunqing Jun 1, 2023
b502ba1
test: revert
Dunqing Jun 1, 2023
2dc21f3
ci: coverage failed
Dunqing Jun 1, 2023
062754a
test: fix c8 ignore comment
Dunqing Jun 1, 2023
c798ea8
Merge remote-tracking branch 'upstream/master' into chore/migrate-to-…
Dunqing Jun 1, 2023
a11c225
chore: incorrect config
Dunqing Jun 1, 2023
eb213e2
chore: fix ignore ci
Dunqing Jun 1, 2023
97ed8d2
test: revert svg+xml
Dunqing Jun 1, 2023
fc28e09
test: fix realTimers
Dunqing Jun 1, 2023
ac07faf
Merge branch 'master' into chore/migrate-to-vitest
afc163 Jun 5, 2023
a89de6c
Merge remote-tracking branch 'upstream/master' into chore/migrate-to-…
Dunqing Jun 6, 2023
4a3c294
feat: rc-trigger should be remove
Dunqing Jun 6, 2023
4ee07db
test: fix some failed test
Dunqing Jun 7, 2023
d3125f9
chore: remove unused deps and configure eslint-plugin-vitest
Dunqing Jun 7, 2023
25ed383
Merge remote-tracking branch 'upstream/master' into chore/migrate-to-…
Dunqing Jun 7, 2023
8e3e4be
Merge remote-tracking branch 'upstream/master' into chore/migrate-to-…
Dunqing Jun 7, 2023
90f7389
test: update snap
Dunqing Jun 7, 2023
a5f253e
chore: remove jest
Dunqing Jun 7, 2023
0c90f7e
test: fix lint error
Dunqing Jun 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion .eslintignore
Expand Up @@ -21,4 +21,3 @@ coverage
**/*.d.ts
# Scripts
scripts/previewEditor/**/*
jest-stare
27 changes: 18 additions & 9 deletions .eslintrc.js
Expand Up @@ -3,7 +3,7 @@ module.exports = {
'airbnb',
'prettier',
'plugin:compat/recommended',
'plugin:jest/recommended',
'plugin:vitest/recommended',
'plugin:react/recommended',
'plugin:import/typescript',
'plugin:markdown/recommended',
Expand All @@ -12,7 +12,6 @@ module.exports = {
browser: true,
node: true,
jasmine: true,
jest: true,
es6: true,
},
settings: {
Expand All @@ -25,7 +24,15 @@ module.exports = {
},
},
parser: '@typescript-eslint/parser',
plugins: ['react', '@babel', 'jest', '@typescript-eslint', 'react-hooks', 'unicorn', 'markdown'],
plugins: [
'react',
'@babel',
'vitest',
'@typescript-eslint',
'react-hooks',
'unicorn',
'markdown',
],
// https://github.com/typescript-eslint/typescript-eslint/issues/46#issuecomment-470486034
overrides: [
{
Expand Down Expand Up @@ -152,8 +159,10 @@ module.exports = {
'scripts/**',
'**/*.test.js',
'**/__tests__/*',
'__mocks__/**',
'*.config.js',
'**/*.md',
'vitest*config.ts',
],
},
],
Expand All @@ -179,12 +188,12 @@ module.exports = {
'no-restricted-globals': 0,
'max-classes-per-file': 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,
'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,

'unicorn/better-regex': 2,
'unicorn/prefer-string-trim-start-end': 2,
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Expand Up @@ -191,7 +191,7 @@ jobs:
# dom test
- name: dom test
if: ${{ matrix.module == 'dom' }}
run: npm test -- --maxWorkers=2 --shard=${{matrix.shard}} --coverage
run: npm test -- --shard=${{matrix.shard}} --coverage

- name: persist coverages
if: ${{ matrix.module == 'dom' && matrix.react == '17' }}
Expand Down Expand Up @@ -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 -- --maxWorkers=2 --shard=${{matrix.shard}}
run: npm test -- --shard=${{matrix.shard}}
env:
LIB_DIR: ${{ matrix.module }}
needs: compile
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -58,7 +58,6 @@ components/version/token-meta.json
# Image snapshot diff
__diff_output__/
__image_snapshots__/
/jest-stare
/imageSnapshots
/imageDiffSnapshots

Expand Down
23 changes: 0 additions & 23 deletions .jest.image.js

This file was deleted.

68 changes: 0 additions & 68 deletions .jest.js

This file was deleted.

19 changes: 0 additions & 19 deletions .jest.node.js

This file was deleted.

21 changes: 0 additions & 21 deletions .jest.site.js

This file was deleted.

@@ -1,16 +1,17 @@
import type { TriggerProps } from '@rc-component/trigger';
import MockTrigger from '@rc-component/trigger/lib/mock';
import MockTrigger from '@rc-component/trigger/es/mock';
import * as React from 'react';
import { TriggerMockContext } from '../../shared/demoTestContext';
import { TriggerMockContext } from '../../tests/shared/demoTestContext';

let OriginTrigger = jest.requireActual('@rc-component/trigger');
OriginTrigger = OriginTrigger.default ?? OriginTrigger;
const { default: OriginTrigger } = await vi.importActual<typeof import('@rc-component/trigger')>(
'@rc-component/trigger',
);

const ForwardTrigger = React.forwardRef<any, TriggerProps>((props, ref) => {
const context = React.useContext(TriggerMockContext);

const mergedPopupVisible = context?.popupVisible ?? props.popupVisible;
(global as any).triggerProps = props;
globalThis.triggerProps = props;

const mergedProps = {
...props,
Expand Down
File renamed without changes.
@@ -1,8 +1,8 @@
import React from 'react';
import { TriggerMockContext } from '../../../shared/demoTestContext';
import { TriggerMockContext } from '../../../tests/shared/demoTestContext';

const { default: OriginPortal } = await vi.importActual<typeof import('rc-util/es/Portal')>('rc-util/es/Portal');

let OriginPortal = jest.requireActual('rc-util/lib/Portal');
OriginPortal = OriginPortal.default ?? OriginPortal;
class MockPortal extends React.Component<{ children?: React.ReactNode }> {
container: boolean;

Expand Down
3 changes: 3 additions & 0 deletions __mocks__/rc-virtual-list.ts
@@ -0,0 +1,3 @@
import Mock from 'rc-virtual-list/es/mock';

export default Mock;
12 changes: 6 additions & 6 deletions components/__tests__/__snapshots__/index.test.ts.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`antd exports modules correctly 1`] = `
exports[`antd > exports modules correctly 1`] = `
[
"Affix",
"Alert",
Expand Down Expand Up @@ -37,7 +37,9 @@ exports[`antd exports modules correctly 1`] = `
"List",
"Mentions",
"Menu",
"message",
"Modal",
"notification",
"Pagination",
"Popconfirm",
"Popover",
Expand All @@ -59,6 +61,7 @@ exports[`antd exports modules correctly 1`] = `
"Table",
"Tabs",
"Tag",
"theme",
"TimePicker",
"Timeline",
"Tooltip",
Expand All @@ -68,10 +71,7 @@ exports[`antd exports modules correctly 1`] = `
"TreeSelect",
"Typography",
"Upload",
"Watermark",
"message",
"notification",
"theme",
"version",
"Watermark",
]
`;
4 changes: 2 additions & 2 deletions components/__tests__/__snapshots__/setup.test.tsx.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`SetUp.Test diff of React 18 & React 17 1`] = `
exports[`SetUp.Test > diff of React 18 & React 17 1`] = `
NodeList [
<div>
bamboo
Expand Down
3 changes: 2 additions & 1 deletion components/__tests__/index.test.ts
@@ -1,6 +1,7 @@
import * as antd from '..';

const OLD_NODE_ENV = process.env.NODE_ENV;
process.env.NODE_ENV = 'development';
const antd = require('..');

describe('antd', () => {
afterAll(() => {
Expand Down
37 changes: 22 additions & 15 deletions components/__tests__/node.test.tsx
Expand Up @@ -3,21 +3,24 @@ import * as React from 'react';
import { renderToString } from 'react-dom/server';
import type { Options } from '../../tests/shared/demoTest';

(global as any).testConfig = {};
globalThis.testConfig = {};

jest.mock('../../tests/shared/demoTest', () => {
vi.mock('../../tests/shared/demoTest', () => {
function fakeDemoTest(name: string, option: Options = {}) {
(global as any).testConfig[name] = option;
globalThis.testConfig[name] = option;
}

fakeDemoTest.rootPropsTest = () => {};

return fakeDemoTest;
return {
default: fakeDemoTest,
rootPropsTest: () => {},
};
});

describe('node', () => {
beforeAll(() => {
jest.useFakeTimers().setSystemTime(new Date('2016-11-22'));
vi.useFakeTimers().setSystemTime(new Date('2016-11-22'));
});

// Find the component exist demo test file
Expand All @@ -27,23 +30,27 @@ describe('node', () => {
const componentName = componentTestFile.match(/components\/([^/]*)\//)![1];

// Test for ssr
describe(componentName, () => {
// eslint-disable-next-line vitest/valid-describe-callback
describe(componentName, async () => {
const demoList = globSync(`./components/${componentName}/demo/*.tsx`);

// Use mock to get config
require(`../../${componentTestFile}`); // eslint-disable-line global-require, import/no-dynamic-require
const option = (global as any).testConfig?.[componentName];

await import(`../../${componentTestFile}`);
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, () => {
const Demo = require(`../../${demoFile}`).default; // eslint-disable-line global-require, import/no-dynamic-require
expect(() => {
renderToString(<Demo />);
}).not.toThrow();
});
test(
demoFile,
async () => {
const Demo = (await import(`../../${demoFile}`)).default;
expect(() => {
renderToString(<Demo />);
}).not.toThrow();
},
15000,
);
});
});
});
Expand Down