This directory contains unit tests for the Dyad application.
We use Vitest as our testing framework, which is designed to work well with Vite and modern JavaScript.
Add these commands to your package.json:
"test": "vitest run",
"test:watch": "vitest",
"test:ui": "vitest --ui"npm run test- Run tests oncenpm run test:watch- Run tests in watch mode (rerun when files change)npm run test:ui- Run tests with UI reporter
When mocking the node:fs module, use a default export in the mock:
vi.mock("node:fs", async () => {
return {
default: {
mkdirSync: vi.fn(),
writeFileSync: vi.fn(),
// Add other fs methods as needed
},
};
});When mocking isomorphic-git, provide a default export:
vi.mock("isomorphic-git", () => ({
default: {
add: vi.fn().mockResolvedValue(undefined),
commit: vi.fn().mockResolvedValue(undefined),
// Add other git methods as needed
},
}));When testing IPC handlers, mock the Electron IPC system:
vi.mock("electron", () => ({
ipcMain: {
handle: vi.fn(),
on: vi.fn(),
},
}));- Create a new file with the
.test.tsor.spec.tsextension - Import the functions you want to test
- Mock any dependencies using
vi.mock() - Write your test cases using
describe()andit()
See chat_stream_handlers.test.ts for an example of testing IPC handlers with proper mocking.