frontend/README.md
This is the frontend of the OpenHands project. It is a React application that provides a web interface for the OpenHands project.
npm, bun, or any other package manager that supports the package.json file# Clone the repository
git clone https://github.com/OpenHands/OpenHands.git
# Change the directory to the frontend
cd OpenHands/frontend
# Install the dependencies
npm install
We use msw to mock the backend API. To start the application with the mocked backend, run the following command:
npm run dev
This will start the application in development mode. Open http://localhost:3001 to view it in the browser.
NOTE: The backend is partially mocked using msw. Therefore, some features may not work as they would with the actual backend.
See the Development.md for extra tips on how to run in development mode.
To run the application with the actual backend:
# Build the application from the root directory
make build
# Start the application
make run
Or to run backend and frontend separately.
# Start the backend from the root directory
make start-backend
# Serve the frontend
make start-frontend or
cd frontend && npm start -- --port 3001
Start frontend with Mock Service Worker (MSW), see testing for more info.
npm run dev:mock or npm run dev:mock:saas
The frontend application uses the following environment variables:
| Variable | Description | Default Value |
|---|---|---|
VITE_BACKEND_BASE_URL | The backend hostname without protocol (used for WebSocket connections) | localhost:3000 |
VITE_BACKEND_HOST | The backend host with port for API connections | 127.0.0.1:3000 |
VITE_MOCK_API | Enable/disable API mocking with MSW | false |
VITE_MOCK_SAAS | Simulate SaaS mode in development | false |
VITE_USE_TLS | Use HTTPS/WSS for backend connections | false |
VITE_FRONTEND_PORT | Port to run the frontend application | 3001 |
VITE_INSECURE_SKIP_VERIFY | Skip TLS certificate verification | false |
VITE_GITHUB_TOKEN | GitHub token for repository access (used in some tests) | - |
You can create a .env file in the frontend directory with these variables based on the .env.sample file.
frontend
├── __tests__ # Tests
├── public
├── src
│ ├── api # API calls
│ ├── assets
│ ├── components
│ ├── context # Local state management
│ ├── hooks # Custom hooks
│ ├── i18n # Internationalization
│ ├── mocks # MSW mocks for development
│ ├── routes # React Router file-based routes
│ ├── services
│ ├── state # Redux state management
│ ├── types
│ ├── utils # Utility/helper functions
│ └── root.tsx # Entry point
└── .env.sample # Sample environment variables
Components are organized into folders based on their domain, feature, or shared functionality.
components
├── features # Domain-specific components
├── layout
├── modals
└── ui # Shared UI components
We use the following testing tools:
To run all tests:
npm run test
To run tests with coverage:
npm run test:coverage
Component Testing
renderWithProviders() that wraps the components we want to test in our providers. It is especially useful for components that use Reduxrender() from React Testing Library to render componentsUser Event Simulation
userEvent for simulating realistic user interactionsMocking
vi.fn() to create mock functions for callbacks and event handlers.toHaveBeenCalledWith(), .toHaveBeenCalledTimes()Accessibility Testing
toBeInTheDocument() to check element presenceState and Prop Testing
Internationalization (i18n) Testing
Example Test Structure:
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, it, expect, vi } from "vitest";
describe("ComponentName", () => {
it("should render correctly", () => {
render(<Component />);
expect(screen.getByRole("button")).toBeInTheDocument();
});
it("should handle user interactions", async () => {
const mockCallback = vi.fn();
const user = userEvent.setup();
render(<Component onClick={mockCallback} />);
const button = screen.getByRole("button");
await user.click(button);
expect(mockCallback).toHaveBeenCalledOnce();
});
});
For real-world examples of testing, check out these test files:
Chat Input Component Test:
__tests__/components/chat/chat-input.test.tsx
File Explorer Component Test:
__tests__/components/file-explorer/file-explorer.test.tsx
Tests are automatically run during:
Please read the CONTRIBUTING.md file for details on our code of conduct, and the process for submitting pull requests to us.
TODO