Skip to content

Latest commit

 

History

History
94 lines (71 loc) · 1.51 KB

File metadata and controls

94 lines (71 loc) · 1.51 KB

Testing Guide

Setup

  1. Install dependencies:
    npm install

Running Tests

  • Run all tests:
    npm test
  • Run tests in watch mode:
    npm test -- --watch
  • Run a specific test file:
    npm test tests/unit/test_types.test.ts
  • Run tests with UI:
    npm run test:ui

Coverage

  • Run tests with coverage report:
    npm run test:coverage

Adding New Tests

  • Place unit tests in tests/unit/

  • Place integration tests in tests/integration/

  • Name test files as *.test.ts

  • Use Vitest conventions for test functions:

    import { describe, it, expect } from "vitest";
    
    describe("MyFunction", () => {
      it("should do something", () => {
        expect(true).toBe(true);
      });
    });

Test Patterns

Mocking Modules

import { vi } from "vitest";

vi.mock("../../src/module.js", () => ({
  functionName: vi.fn().mockReturnValue("value"),
}));

Mocking Environment Variables

import { vi } from "vitest";

vi.stubEnv("GITHUB_REPOSITORY", "org/repo");

Mocking Fetch

global.fetch = vi.fn().mockResolvedValue({
  ok: true,
  status: 200,
  json: async () => ({ data: "value" }),
});

Async Tests

it("should handle async operations", async () => {
  const result = await myAsyncFunction();
  expect(result).toBeDefined();
});

CI

Tests are automatically run on GitHub Actions for every push and pull request to main.