Skip to content

Commit

Permalink
migrate to vitest
Browse files Browse the repository at this point in the history
Signed-off-by: Teo Koon Peng <teokoonpeng@gmail.com>
  • Loading branch information
koonpeng committed Jul 26, 2024
1 parent 34c22fe commit 5478d89
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 606 deletions.
8 changes: 4 additions & 4 deletions packages/react-components/lib/alert-dialog.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe('AcknowledgeAndCloseAlertDialog', () => {
},
];
};
const acknowledge = jest.fn();
const dismiss = jest.fn();
const acknowledge = vi.fn();
const dismiss = vi.fn();
const root = render(
<ThemeProvider theme={theme}>
<AlertDialog
Expand Down Expand Up @@ -60,8 +60,8 @@ describe('AcknowledgeAndCloseAlertDialog', () => {
},
];
};
const acknowledge = jest.fn();
const close = jest.fn();
const acknowledge = vi.fn();
const close = vi.fn();
const root = render(
<ThemeProvider theme={theme}>
<AlertDialog
Expand Down
4 changes: 2 additions & 2 deletions packages/react-components/lib/confirmation-dialog.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { ConfirmationDialog } from './confirmation-dialog';

describe('ConfirmDialogActions', () => {
it('calls onClose when cancel button is clicked', () => {
const onClose = jest.fn();
const onClose = vi.fn();
const root = render(<ConfirmationDialog open={true} onClose={onClose} />);
fireEvent.click(root.getByText('Cancel'));
expect(onClose).toHaveBeenCalled();
});

it('calls onSubmit when form is submitted', () => {
const onSubmit = jest.fn();
const onSubmit = vi.fn();
const root = render(<ConfirmationDialog open={true} onSubmit={onSubmit} />);
fireEvent.click(root.getByText('OK'));
expect(onSubmit).toHaveBeenCalled();
Expand Down
2 changes: 1 addition & 1 deletion packages/react-components/lib/header-bar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { HeaderBar } from './header-bar';

describe('Header Bar', () => {
it('renders correctly', () => {
const mockOnTabChange = jest.fn();
const mockOnTabChange = vi.fn();
render(
<HeaderBar>
<NavigationBar onTabChange={mockOnTabChange} value={'building'}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { makeLift, makeLiftState } from './test-utils.spec';

describe('Lift request form', () => {
it('destination is required', async () => {
const mockOnClose = jest.fn();
const mockOnClose = vi.fn();
const lift = makeLift();
const liftState = makeLiftState();
render(
Expand Down
2 changes: 1 addition & 1 deletion packages/react-components/lib/logo-button.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LogoButton } from './logo-button';

describe('LogoButton', () => {
it('renders and is clickable', () => {
const mockOnClick = jest.fn();
const mockOnClick = vi.fn();
render(
<LogoButton
src="/base/test-data/assets/roshealth-logo-white.png"
Expand Down
2 changes: 1 addition & 1 deletion packages/react-components/lib/navigation-bar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { NavigationBar } from './navigation-bar';

describe('Banner Tab', () => {
it('renders correctly', () => {
const mockOnTabChange = jest.fn();
const mockOnTabChange = vi.fn();
render(
<NavigationBar onTabChange={mockOnTabChange} value={'building'}>
<Tab
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ describe('Mutex group table', () => {
requestedBy: ['fleet1/robot2'],
},
];
const group1Click = jest.fn();
const group2Click = jest.fn();
const group1Click = vi.fn();
const group2Click = vi.fn();
const root = render(
<MutexGroupTable
mutexGroups={mutexGroups}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('RobotTable', () => {
});

it('onRobotClick is called when row is clicked', () => {
const onRobotClick = jest.fn();
const onRobotClick = vi.fn();
const root = render(
<RobotDataGridTable
robots={[{ fleet: 'test_fleet', name: 'test_robot' }]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('EventEditDeletePopup', () => {
const currentValue = 'current';
const allValue = 'all';
const value = 'current';
const onChange = jest.fn();
const onChange = vi.fn();

it('handles onChange event', () => {
const { getByLabelText } = render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ describe('Tasks table', () => {

tasks.data = [makeTaskState('task_0'), makeTaskState('task_1')];
let root: RenderResult;
let mockAddMoreRows: ReturnType<typeof jest.fn>;
let mockAddMoreRows: ReturnType<typeof vi.fn>;

beforeEach(() => {
const setFilterFields: FilterFields = {
model: undefined,
};

mockAddMoreRows = jest.fn();
mockAddMoreRows = vi.fn();
root = render(
<TaskDataGridTable
tasks={tasks}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-components/lib/transfer-list.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('TransferList', () => {
});

it('transfers correct items', () => {
const spy = jest.fn();
const spy = vi.fn();
const root = render(<TransferList leftItems={left} rightItems={right} onTransfer={spy} />);
fireEvent.click(root.getByText('one'));
fireEvent.click(root.getByLabelText('move selected right', { selector: 'button' }));
Expand Down
13 changes: 5 additions & 8 deletions packages/react-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"lint": "tsc && eslint --max-warnings 0 lib",
"prepack": "pnpm run lint && jest",
"start": "storybook dev -p 6006",
"test": "jest --watch",
"test:coverage": "jest --coverage"
"test": "vitest",
"test:coverage": "vitest --coverage"
},
"author": "koonpeng@openrobotics.org",
"license": "Apache-2.0",
Expand All @@ -35,7 +35,6 @@
"date-fns": "^2.30.0",
"debug": "^4.2.0",
"eventemitter3": "^4.0.7",
"jest-environment-jsdom": "^29.7.0",
"node-vibrant": "^3.1.6",
"rbush": "^3.0.1",
"react": "^18.2.0",
Expand Down Expand Up @@ -63,11 +62,9 @@
"@storybook/react-vite": "^8.2.6",
"@storybook/test": "^8.0.5",
"@testing-library/dom": "^9.3.4",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^14.2.2",
"@testing-library/user-event": "^14.5.2",
"@types/debug": "^4.1.5",
"@types/jest": "^29.5.12",
"@types/react": "^18.2.14",
"@types/react-dom": "^18.2.6",
"@types/react-grid-layout": "^1.3.2",
Expand All @@ -80,14 +77,14 @@
"eslint-plugin-storybook": "^0.8.0",
"file-loader": "^6.2.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.7.0",
"jsdom": "^24.1.1",
"process": "0.11.10",
"puppeteer": "*",
"require-from-string": "^2.0.2",
"storybook": "^8.0.5",
"ts-jest": "^29.1.2",
"typescript": "~5.4.3",
"typescript-eslint": "^7.5.0"
"typescript-eslint": "^7.5.0",
"vitest": "^2.0.4"
},
"eslintConfig": {
"extends": [
Expand Down
1 change: 1 addition & 0 deletions packages/react-components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"types": ["vitest/globals"],
"module": "ESNext",
"skipLibCheck": true,

Expand Down
5 changes: 5 additions & 0 deletions packages/react-components/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: { globals: true, environment: 'jsdom', passWithNoTests: true },
});
Loading

0 comments on commit 5478d89

Please sign in to comment.