Skip to content

Commit 252fcc7

Browse files
authored
chore: migrate jest to vitest (#989)
* feat: first * fix: should get scrollbar size * fix: Sticky scroll with getContainer * fix: sticky.spec.jsx tests * fix: FixedHeader.spec.jsx tests * fix: remove comment * fix: should use clientX * fix: remove comment * feat: update tests * test: update * test: revert
1 parent 38a9e02 commit 252fcc7

32 files changed

+6233
-5313
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,6 @@ jobs:
108108
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
109109

110110
- name: coverage
111-
run: npm test -- --coverage && bash <(curl -s https://codecov.io/bash)
111+
run: npm run coverage && bash <(curl -s https://codecov.io/bash)
112112

113113
needs: setup

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ package-lock.json
3232
es/
3333
.storybook
3434
.doc
35-
!tests/__mocks__/rc-util/lib
35+
!__mocks__/rc-util/lib
3636
examples/debug.tsx
3737
.history
3838
~*
@@ -42,4 +42,4 @@ examples/debug.tsx
4242
.umi-production
4343
.umi-test
4444
.env.local
45-
.dumi
45+
.dumi
File renamed without changes.

jest.config.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
"compile": "father build && lessc assets/index.less assets/index.css",
4141
"deploy": "npm run docs:build && npm run docs:deploy",
4242
"prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
43-
"test": "rc-test",
44-
"coverage": "rc-test --coverage",
43+
"test": "vitest",
44+
"coverage": "vitest run --coverage",
4545
"prepublishOnly": "npm run compile && np --no-cleanup --yolo --no-publish",
4646
"lint": "eslint src/ --ext .tsx,.ts",
4747
"lint:tsc": "tsc -p tsconfig.json --noEmit",
@@ -63,7 +63,6 @@
6363
"@testing-library/jest-dom": "^5.16.5",
6464
"@testing-library/react": "^12.1.5",
6565
"@types/enzyme": "^3.10.5",
66-
"@types/jest": "^28.1.2",
6766
"@types/react": "^17.0.35",
6867
"@types/react-dom": "^18.0.5",
6968
"@types/responselike": "^1.0.0",
@@ -86,7 +85,6 @@
8685
"rc-animate": "^3.0.0",
8786
"rc-dropdown": "~4.0.1",
8887
"rc-menu": "~9.6.0",
89-
"rc-test": "^7.0.14",
9088
"rc-tooltip": "^5.2.1",
9189
"react": "^16.0.0",
9290
"react-dnd": "^2.5.4",
@@ -97,7 +95,11 @@
9795
"react-window": "^1.8.5",
9896
"regenerator-runtime": "^0.13.7",
9997
"styled-components": "^5.0.1",
100-
"typescript": "^4.8.4"
98+
"typescript": "^4.8.4",
99+
"@vitest/coverage-c8": "^0.31.0",
100+
"@types/testing-library__jest-dom": "^5.14.5",
101+
"jsdom": "^22.0.0",
102+
"vitest": "^0.31.0"
101103
},
102104
"lint-staged": {
103105
"**/*.{js,jsx,tsx,ts,md,json}": [

src/stickyScrollBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { useContext } from '@rc-component/context';
12
import classNames from 'classnames';
23
import addEventListener from 'rc-util/lib/Dom/addEventListener';
34
import { getOffset } from 'rc-util/lib/Dom/css';
45
import getScrollBarSize from 'rc-util/lib/getScrollBarSize';
56
import * as React from 'react';
67
import TableContext from './context/TableContext';
7-
import { useContext } from '@rc-component/context';
88
import { useLayoutState } from './hooks/useFrame';
99

1010
interface StickyScrollBarProps {
File renamed without changes.

tests/Colgroup.spec.js renamed to tests/Colgroup.spec.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React from 'react';
21
import { mount } from 'enzyme';
2+
import React from 'react';
33
import Table, { INTERNAL_COL_DEFINE } from '../src';
44

55
describe('Table.ColGroup', () => {

tests/Deprecated.spec.js renamed to tests/Deprecated.spec.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import React from 'react';
21
import { mount } from 'enzyme';
32
import { resetWarned } from 'rc-util/lib/warning';
3+
import React from 'react';
44
import Table from '../src';
55

66
describe('Table.Deprecated', () => {
77
let errorSpy;
88

99
beforeAll(() => {
10-
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
10+
errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
1111
});
1212

1313
beforeEach(() => {
@@ -34,7 +34,7 @@ describe('Table.Deprecated', () => {
3434
removedProp => {
3535
it(`warning for '${removedProp}'`, () => {
3636
const props = {
37-
[removedProp]: jest.fn(),
37+
[removedProp]: vi.fn(),
3838
};
3939
mount(<Table {...props} />);
4040

tests/ExpandRow.spec.js renamed to tests/ExpandRow.spec.jsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import React from 'react';
21
import { mount } from 'enzyme';
3-
import { act } from 'react-dom/test-utils';
4-
import { resetWarned } from 'rc-util/lib/warning';
52
import { spyElementPrototype } from 'rc-util/lib/test/domHook';
3+
import { resetWarned } from 'rc-util/lib/warning';
4+
import React from 'react';
5+
import { act } from 'react-dom/test-utils';
66
import Table from '../src';
77

88
describe('Table.Expand', () => {
@@ -22,7 +22,7 @@ describe('Table.Expand', () => {
2222

2323
it('renders expand row correctly', () => {
2424
resetWarned();
25-
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
25+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
2626
const wrapper = mount(createTable({ expandedRowRender }));
2727
expect(wrapper.find('tbody tr')).toHaveLength(2);
2828
expect(errorSpy).toHaveBeenCalledWith(
@@ -32,7 +32,7 @@ describe('Table.Expand', () => {
3232
});
3333

3434
it('pass proper parameters to expandedRowRender', () => {
35-
const rowRender = jest.fn(() => <div>expanded row</div>);
35+
const rowRender = vi.fn(() => <div>expanded row</div>);
3636
const expandableProps = props => ({ expandable: { expandedRowRender: rowRender, ...props } });
3737
const wrapper = mount(createTable(expandableProps()));
3838
wrapper.setProps(expandableProps({ expandedRowKeys: [0] }));
@@ -232,7 +232,7 @@ describe('Table.Expand', () => {
232232
describe('config expand column index', () => {
233233
it('not show EXPAND_COLUMN if expandable is false', () => {
234234
resetWarned();
235-
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
235+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
236236

237237
const wrapper = mount(
238238
createTable({
@@ -250,7 +250,7 @@ describe('Table.Expand', () => {
250250

251251
it('renders expand icon to the specify column', () => {
252252
resetWarned();
253-
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
253+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
254254

255255
const wrapper = mount(
256256
createTable({
@@ -287,7 +287,7 @@ describe('Table.Expand', () => {
287287

288288
it('de-duplicate of EXPAND_COLUMN', () => {
289289
resetWarned();
290-
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
290+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
291291

292292
const wrapper = mount(
293293
createTable({
@@ -400,7 +400,7 @@ describe('Table.Expand', () => {
400400
});
401401

402402
it('renders expend row class correctly', () => {
403-
const expandedRowClassName = jest.fn().mockReturnValue('expand-row-test-class-name');
403+
const expandedRowClassName = vi.fn().mockReturnValue('expand-row-test-class-name');
404404
const wrapper = mount(
405405
createTable({
406406
expandable: {
@@ -431,7 +431,7 @@ describe('Table.Expand', () => {
431431
});
432432

433433
it('fires expand change event', () => {
434-
const onExpand = jest.fn();
434+
const onExpand = vi.fn();
435435
const wrapper = mount(
436436
createTable({
437437
expandable: {
@@ -448,7 +448,7 @@ describe('Table.Expand', () => {
448448
});
449449

450450
it('fires onExpandedRowsChange event', () => {
451-
const onExpandedRowsChange = jest.fn();
451+
const onExpandedRowsChange = vi.fn();
452452
const wrapper = mount(
453453
createTable({
454454
expandedRowRender,
@@ -473,7 +473,7 @@ describe('Table.Expand', () => {
473473
});
474474

475475
it('expandRowByClick', () => {
476-
const onExpand = jest.fn();
476+
const onExpand = vi.fn();
477477
const wrapper = mount(
478478
createTable({
479479
expandable: {
@@ -533,7 +533,7 @@ describe('Table.Expand', () => {
533533
// https://github.com/ant-design/ant-design/issues/23894
534534
it('should be collapsible when use `expandIcon` & `expandRowByClick`', () => {
535535
const data = [{ key: 0, name: 'Lucy', age: 27 }];
536-
const onExpand = jest.fn();
536+
const onExpand = vi.fn();
537537
const wrapper = mount(
538538
createTable({
539539
expandable: {
@@ -561,7 +561,7 @@ describe('Table.Expand', () => {
561561
// https://github.com/ant-design/ant-design/issues/23894
562562
it('should be collapsible when `expandRowByClick` without custom `expandIcon`', () => {
563563
const data = [{ key: 0, name: 'Lucy', age: 27 }];
564-
const onExpand = jest.fn();
564+
const onExpand = vi.fn();
565565
const wrapper = mount(
566566
createTable({
567567
expandable: {
@@ -582,7 +582,7 @@ describe('Table.Expand', () => {
582582

583583
it('should be collapsible when `expandRowByClick` with custom `expandIcon` and event.stopPropagation', () => {
584584
const data = [{ key: 0, name: 'Lucy', age: 27 }];
585-
const onExpand = jest.fn();
585+
const onExpand = vi.fn();
586586
const wrapper = mount(
587587
createTable({
588588
expandable: {
@@ -612,7 +612,7 @@ describe('Table.Expand', () => {
612612

613613
it('support invalid expandIcon', () => {
614614
const data = [{ key: 0, name: 'Lucy', age: 27 }];
615-
const onExpand = jest.fn();
615+
const onExpand = vi.fn();
616616
const wrapper = mount(
617617
createTable({
618618
expandable: {
@@ -629,7 +629,7 @@ describe('Table.Expand', () => {
629629

630630
it('warning for use `expandedRowRender` and nested table in the same time', () => {
631631
resetWarned();
632-
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
632+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
633633
mount(createTable({ expandedRowRender, data: [{ children: [] }] }));
634634
expect(errorSpy).toHaveBeenCalledWith(
635635
'Warning: `expandedRowRender` should not use with nested Table',

0 commit comments

Comments
 (0)