Files
moreminimore-vibe/backups/backup-20251218-094212/src/__tests__
Kunthawat Greethong 5660de49de
Some checks failed
CI / test (map[image:macos-latest name:macos], 1, 4) (push) Has been cancelled
CI / test (map[image:macos-latest name:macos], 2, 4) (push) Has been cancelled
CI / test (map[image:macos-latest name:macos], 3, 4) (push) Has been cancelled
CI / test (map[image:macos-latest name:macos], 4, 4) (push) Has been cancelled
CI / test (map[image:windows-latest name:windows], 1, 4) (push) Has been cancelled
CI / test (map[image:windows-latest name:windows], 2, 4) (push) Has been cancelled
CI / test (map[image:windows-latest name:windows], 3, 4) (push) Has been cancelled
CI / test (map[image:windows-latest name:windows], 4, 4) (push) Has been cancelled
CI / merge-reports (push) Has been cancelled
feat: integrate custom features for smart context management
- Added a new integration script to manage custom features related to smart context.
- Implemented handlers for smart context operations (get, update, clear, stats) in ipc.
- Created a SmartContextStore class to manage context snippets and summaries.
- Developed hooks for React to interact with smart context (useSmartContext, useUpdateSmartContext, useClearSmartContext, useSmartContextStats).
- Included backup and restore functionality in the integration script.
- Validated integration by checking for custom modifications and file existence.
2025-12-18 15:56:48 +07:00
..

Test Documentation

This directory contains unit tests for the Dyad application.

Testing Setup

We use Vitest as our testing framework, which is designed to work well with Vite and modern JavaScript.

Test Commands

Add these commands to your package.json:

"test": "vitest run",
"test:watch": "vitest",
"test:ui": "vitest --ui"
  • npm run test - Run tests once
  • npm run test:watch - Run tests in watch mode (rerun when files change)
  • npm run test:ui - Run tests with UI reporter

Mocking Guidelines

Mocking fs module

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
    },
  };
});

Mocking isomorphic-git

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
  },
}));

Testing IPC Handlers

When testing IPC handlers, mock the Electron IPC system:

vi.mock("electron", () => ({
  ipcMain: {
    handle: vi.fn(),
    on: vi.fn(),
  },
}));

Adding New Tests

  1. Create a new file with the .test.ts or .spec.ts extension
  2. Import the functions you want to test
  3. Mock any dependencies using vi.mock()
  4. Write your test cases using describe() and it()

Example

See chat_stream_handlers.test.ts for an example of testing IPC handlers with proper mocking.