Skip to content

chore: migrate jest to vitest #989

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

Merged
merged 11 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ jobs:
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}

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

needs: setup
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ package-lock.json
es/
.storybook
.doc
!tests/__mocks__/rc-util/lib
!__mocks__/rc-util/lib
examples/debug.tsx
.history
~*
Expand All @@ -42,4 +42,4 @@ examples/debug.tsx
.umi-production
.umi-test
.env.local
.dumi
.dumi
4 changes: 0 additions & 4 deletions jest.config.js

This file was deleted.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"compile": "father build && lessc assets/index.less assets/index.css",
"deploy": "npm run docs:build && npm run docs:deploy",
"prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
"test": "rc-test",
"coverage": "rc-test --coverage",
"test": "vitest",
"coverage": "vitest run --coverage",
"prepublishOnly": "npm run compile && np --no-cleanup --yolo --no-publish",
"lint": "eslint src/ --ext .tsx,.ts",
"lint:tsc": "tsc -p tsconfig.json --noEmit",
Expand All @@ -63,7 +63,6 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
"@types/enzyme": "^3.10.5",
"@types/jest": "^28.1.2",
"@types/react": "^17.0.35",
"@types/react-dom": "^18.0.5",
"@types/responselike": "^1.0.0",
Expand All @@ -86,7 +85,6 @@
"rc-animate": "^3.0.0",
"rc-dropdown": "~4.0.1",
"rc-menu": "~9.6.0",
"rc-test": "^7.0.14",
"rc-tooltip": "^5.2.1",
"react": "^16.0.0",
"react-dnd": "^2.5.4",
Expand All @@ -97,7 +95,11 @@
"react-window": "^1.8.5",
"regenerator-runtime": "^0.13.7",
"styled-components": "^5.0.1",
"typescript": "^4.8.4"
"typescript": "^4.8.4",
"@vitest/coverage-c8": "^0.31.0",
"@types/testing-library__jest-dom": "^5.14.5",
"jsdom": "^22.0.0",
"vitest": "^0.31.0"
},
"lint-staged": {
"**/*.{js,jsx,tsx,ts,md,json}": [
Expand Down
2 changes: 1 addition & 1 deletion src/stickyScrollBar.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useContext } from '@rc-component/context';
import classNames from 'classnames';
import addEventListener from 'rc-util/lib/Dom/addEventListener';
import { getOffset } from 'rc-util/lib/Dom/css';
import getScrollBarSize from 'rc-util/lib/getScrollBarSize';
import * as React from 'react';
import TableContext from './context/TableContext';
import { useContext } from '@rc-component/context';
import { useLayoutState } from './hooks/useFrame';

interface StickyScrollBarProps {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/Colgroup.spec.js → tests/Colgroup.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { mount } from 'enzyme';
import React from 'react';
import Table, { INTERNAL_COL_DEFINE } from '../src';

describe('Table.ColGroup', () => {
Expand Down
6 changes: 3 additions & 3 deletions tests/Deprecated.spec.js → tests/Deprecated.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';
import { mount } from 'enzyme';
import { resetWarned } from 'rc-util/lib/warning';
import React from 'react';
import Table from '../src';

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

beforeAll(() => {
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
});

beforeEach(() => {
Expand All @@ -34,7 +34,7 @@ describe('Table.Deprecated', () => {
removedProp => {
it(`warning for '${removedProp}'`, () => {
const props = {
[removedProp]: jest.fn(),
[removedProp]: vi.fn(),
};
mount(<Table {...props} />);

Expand Down
34 changes: 17 additions & 17 deletions tests/ExpandRow.spec.js → tests/ExpandRow.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { mount } from 'enzyme';
import { act } from 'react-dom/test-utils';
import { resetWarned } from 'rc-util/lib/warning';
import { spyElementPrototype } from 'rc-util/lib/test/domHook';
import { resetWarned } from 'rc-util/lib/warning';
import React from 'react';
import { act } from 'react-dom/test-utils';
import Table from '../src';

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

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

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

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

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

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

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

const wrapper = mount(
createTable({
Expand Down Expand Up @@ -400,7 +400,7 @@ describe('Table.Expand', () => {
});

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

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

it('fires onExpandedRowsChange event', () => {
const onExpandedRowsChange = jest.fn();
const onExpandedRowsChange = vi.fn();
const wrapper = mount(
createTable({
expandedRowRender,
Expand All @@ -473,7 +473,7 @@ describe('Table.Expand', () => {
});

it('expandRowByClick', () => {
const onExpand = jest.fn();
const onExpand = vi.fn();
const wrapper = mount(
createTable({
expandable: {
Expand Down Expand Up @@ -533,7 +533,7 @@ describe('Table.Expand', () => {
// https://github.com/ant-design/ant-design/issues/23894
it('should be collapsible when use `expandIcon` & `expandRowByClick`', () => {
const data = [{ key: 0, name: 'Lucy', age: 27 }];
const onExpand = jest.fn();
const onExpand = vi.fn();
const wrapper = mount(
createTable({
expandable: {
Expand Down Expand Up @@ -561,7 +561,7 @@ describe('Table.Expand', () => {
// https://github.com/ant-design/ant-design/issues/23894
it('should be collapsible when `expandRowByClick` without custom `expandIcon`', () => {
const data = [{ key: 0, name: 'Lucy', age: 27 }];
const onExpand = jest.fn();
const onExpand = vi.fn();
const wrapper = mount(
createTable({
expandable: {
Expand All @@ -582,7 +582,7 @@ describe('Table.Expand', () => {

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

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

it('warning for use `expandedRowRender` and nested table in the same time', () => {
resetWarned();
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
mount(createTable({ expandedRowRender, data: [{ children: [] }] }));
expect(errorSpy).toHaveBeenCalledWith(
'Warning: `expandedRowRender` should not use with nested Table',
Expand Down
12 changes: 6 additions & 6 deletions tests/FixedColumn-IE.spec.js → tests/FixedColumn-IE.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import { mount } from 'enzyme';
import { act } from 'react-dom/test-utils';
import { spyElementPrototype } from 'rc-util/lib/test/domHook';
import React from 'react';
import { act } from 'react-dom/test-utils';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import Table from '../src';
import RcResizeObserver from 'rc-resize-observer';
import Table from '../src';

jest.mock('rc-util/lib/Dom/styleChecker', () => {
vi.mock('rc-util/lib/Dom/styleChecker', () => {
return {
isStyleSupport: (name, val) => val !== 'sticky',
};
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('Table.FixedColumn', () => {
const data = [{ a: '123', b: 'xxxxxxxx', d: 3, key: '1' }];

it('not sticky', async () => {
jest.useFakeTimers();
vi.useFakeTimers();
const wrapper = mount(<Table columns={columns} data={data} scroll={{ x: 1200 }} />);

act(() => {
Expand All @@ -59,7 +59,7 @@ describe('Table.FixedColumn', () => {
});

await act(async () => {
jest.runAllTimers();
vi.runAllTimers();
await Promise.resolve();
wrapper.update();
});
Expand Down
12 changes: 6 additions & 6 deletions tests/FixedColumn.spec.js → tests/FixedColumn.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import RcResizeObserver from 'rc-resize-observer';
import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
import { resetWarned } from 'rc-util/lib/warning';
import { act } from 'react-dom/test-utils';
import { safeAct } from './utils';
import Table from '../src';
import { safeAct } from './utils';

describe('Table.FixedColumn', () => {
let domSpy;
beforeEach(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});
beforeAll(() => {
domSpy = spyElementPrototypes(HTMLElement, {
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('Table.FixedColumn', () => {
{ name: 'without data', data: [] },
].forEach(({ name, data: testData }) => {
it(`${scrollName} - ${name}`, async () => {
jest.useFakeTimers();
vi.useFakeTimers();
const wrapper = mount(<Table columns={columns} data={testData} scroll={scroll} />);

act(() => {
Expand All @@ -91,7 +91,7 @@ describe('Table.FixedColumn', () => {
});
await safeAct(wrapper);
expect(wrapper.render()).toMatchSnapshot();
jest.useRealTimers();
vi.useRealTimers();
});
});
});
Expand All @@ -107,7 +107,7 @@ describe('Table.FixedColumn', () => {
scroll={{ x: 'max-content' }}
/>,
);

await safeAct(wrapper);

expect(wrapper.find('colgroup').render()).toMatchSnapshot();
Expand Down Expand Up @@ -193,7 +193,7 @@ describe('Table.FixedColumn', () => {
let errorSpy;

beforeAll(() => {
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
});

beforeEach(() => {
Expand Down
Loading