- Install dependencies:
npm install
- 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
- Run tests with coverage report:
npm run test:coverage
-
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); }); });
import { vi } from "vitest";
vi.mock("../../src/module.js", () => ({
functionName: vi.fn().mockReturnValue("value"),
}));import { vi } from "vitest";
vi.stubEnv("GITHUB_REPOSITORY", "org/repo");global.fetch = vi.fn().mockResolvedValue({
ok: true,
status: 200,
json: async () => ({ data: "value" }),
});it("should handle async operations", async () => {
const result = await myAsyncFunction();
expect(result).toBeDefined();
});Tests are automatically run on GitHub Actions for every push and pull request to main.