Skip to content

Commit

Permalink
111
Browse files Browse the repository at this point in the history
  • Loading branch information
dengfuping committed Feb 18, 2024
1 parent a51be6a commit 5aed8ff
Show file tree
Hide file tree
Showing 17 changed files with 883 additions and 79 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}\"",
Expand Down Expand Up @@ -121,6 +121,8 @@
"ts-node": "^10.9.2",
"typescript": "^5.3.3",
"vanilla-jsoneditor": "^0.21.5",
"vite-tsconfig-paths": "^4.3.1",
"vitest": "^1.3.0",
"web-vitals": "^3.5.2",
"yorkie": "^2.0.0"
}
Expand Down
7 changes: 4 additions & 3 deletions packages/design/src/drawer/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { render } from '@testing-library/react';
import { vi } from 'vitest';
import { Drawer } from '@oceanbase/design';
import type { DrawerProps } from '@oceanbase/design';
import { waitFakeTimer } from '../../../../../tests/util';
Expand All @@ -18,11 +19,11 @@ const DrawerTest: React.FC<DrawerProps> = props => (

describe('Drawer', () => {
beforeEach(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});
afterEach(() => {
jest.useRealTimers();
jest.clearAllTimers();
vi.useRealTimers();
vi.clearAllTimers();
});

it('render correctly', async () => {
Expand Down
7 changes: 4 additions & 3 deletions packages/design/src/tag/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { render } from '@testing-library/react';
import { Tag } from '@oceanbase/design';
import type { TagProps } from '@oceanbase/design';
import { vi } from 'vitest';

const TagTest: React.FC<TagProps> = props => (
<Tag {...props}>
Expand All @@ -16,11 +17,11 @@ const TagTest: React.FC<TagProps> = props => (

describe('Tag', () => {
beforeEach(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});
afterEach(() => {
jest.useRealTimers();
jest.clearAllTimers();
vi.useRealTimers();
vi.clearAllTimers();
});

it('default ellipsis', async () => {
Expand Down
11 changes: 6 additions & 5 deletions packages/design/src/tooltip/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React, { useState } from 'react';
import { render, fireEvent } from '@testing-library/react';
import { vi } from 'vitest';
import { Tooltip } from '@oceanbase/design';
import { waitFakeTimer, isTooltipOpen } from '../../../../../tests/util';
import { CloseCircleOutlined } from '@oceanbase/icons';

describe('Tooltip', () => {
beforeEach(() => {
jest.useFakeTimers();
vi.useFakeTimers();
});
afterEach(() => {
jest.useRealTimers();
jest.clearAllTimers();
vi.useRealTimers();
vi.clearAllTimers();
});

it('default close icon should render correctly', async () => {
Expand Down Expand Up @@ -51,7 +52,7 @@ describe('Tooltip', () => {
});

it('check `onOpenChange` arguments', async () => {
const onClose = jest.fn();
const onClose = vi.fn();
const { container } = render(
<Tooltip title="This is prompt text" closeIcon={true} onClose={onClose}>
<div id="hello">Hello world!</div>
Expand Down Expand Up @@ -138,7 +139,7 @@ describe('Tooltip', () => {
});

it('should hide when title is none', async () => {
const onOpenChange = jest.fn();
const onOpenChange = vi.fn();

const { container, rerender } = render(
<Tooltip
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { render } from '@testing-library/react';
import ContentWithQuestion from '..';
import { ContentWithQuestion } from '@oceanbase/ui';

describe('ContentWithQuestion', () => {
it('渲染正常', async () => {
Expand Down
20 changes: 10 additions & 10 deletions packages/ui/src/Login/__test__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import React from 'react';
import { cleanup, fireEvent, render, waitFor } from '@testing-library/react';
// import Login from '..';
// import Login from '@oceanbase/icons';

describe('Login', () => {
beforeAll(() => {
jest.useFakeTimers();
vi.useFakeTimers();
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
value: vi.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // Deprecated
removeListener: jest.fn(), // Deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
addListener: vi.fn(), // Deprecated
removeListener: vi.fn(), // Deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});
});
Expand All @@ -25,7 +25,7 @@ describe('Login', () => {
it('', () => {});
// it('登录', async () => {
// // https://github.com/testing-library/react-testing-library/issues/54
// const fakeFn = jest.fn();
// const fakeFn = vi.fn();
// const { getByTestId, debug } = render(
// <Login
// loginProps={{
Expand All @@ -37,7 +37,7 @@ describe('Login', () => {
// );
// debug(getByTestId('login.form'));
// fireEvent.submit(getByTestId('login.form'));
// jest.advanceTimersByTime(1000);
// vi.advanceTimersByTime(1000);
// expect(fakeFn).toBeCalledTimes(1);
// });

Expand Down
10 changes: 5 additions & 5 deletions packages/ui/src/Ranger/__test__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ describe('Ranger ', () => {
const FORMAT_TYPE = 'YYYY-MM-DD HH:mm:ss';
MockDate.set(moment('2017-09-18T03:30:07.795').format(FORMAT_TYPE));

jest.mock('antd', () => {
const antd = jest.requireActual('antd');
vi.mock('antd', async () => {
const mockReact = (await vi.importActual('react')) as typeof React;
const antd = await vi.importActual('antd');
const DatePicker = () => <div></div>;
DatePicker.RangePicker = ({ value }) => (
<div data-testid="range-picker">
Expand All @@ -26,7 +27,6 @@ describe('Ranger ', () => {
const Select = ({ onSelect, value, children }) => {
// 考虑 cloneElement 不能有 undefined 的情况,但是实际执行是可以的
const filtered = children.filter(c => !!c);
const mockReact = jest.requireActual('react');
return (
<div data-testid="select">
<div data-testid="select-value">{value}</div>
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('Ranger ', () => {
// });

// // it('selects 选中后, onChange 结果正常', () => {
// // const fakeChange = jest.fn();
// // const fakeChange = vi.fn();
// // const { getAllByTestId } = render(
// // <Ranger selects={[Ranger.TODAY, Ranger.YESTERDAY]} onChange={fakeChange} />,
// // );
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('Ranger ', () => {
// expect(getByTestId('select-value').textContent).toBe(name);
// });
// it('onChange 正常', () => {
// const fakeChange = jest.fn();
// const fakeChange = vi.fn();
// const { getAllByTestId } = render(
// <Ranger.QuickPicker selects={[Ranger.TODAY, Ranger.YESTERDAY]} onChange={fakeChange} />
// );
Expand Down
12 changes: 6 additions & 6 deletions packages/ui/src/Welcome/__test__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ describe('Welcome', () => {
beforeAll(() => {
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
value: vi.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // Deprecated
removeListener: jest.fn(), // Deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
addListener: vi.fn(), // Deprecated
removeListener: vi.fn(), // Deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});
});
Expand Down
Loading

0 comments on commit 5aed8ff

Please sign in to comment.