Testing¶
Running tests¶
The project uses Vitest for testing.
Test structure¶
Tests live in src/lib/ alongside the modules they test, following the *.test.ts naming convention:
src/lib/
cli.test.ts -- tests for CLI binary resolution and auto-download
auth.test.ts -- tests for OAuth sign-in and auth checks
Writing tests¶
Conventions¶
- Write tests in the same directory as the module under test
- Name test files
moduleName.test.ts - Use Vitest's
describe/it/expectAPI - Mock external dependencies (file system, child process, network) using
vi.mock
Example¶
import { describe, it, expect, vi } from "vitest";
describe("resolveGleanCli", () => {
it("returns null when no binary is found and download fails", async () => {
// Arrange
vi.mock("fs", () => ({
existsSync: vi.fn(() => false),
}));
// Act
const result = await resolveGleanCli();
// Assert
expect(result).toBeNull();
});
});
Mock patterns¶
The project provides shared mocks in __mocks__/:
__mocks__/child_process.ts— mocksexecFile,spawn,exec__mocks__/fs.ts— mocksexistsSync,readFileSync,writeFileSync,mkdirSync,chmodSync,createWriteStream__mocks__/@raycast/api.ts— mocks Raycast API (environment,showToast,open,Toast)
Import these in your test to avoid hitting real filesystem or network.
Running a single test file¶
Coverage¶
To generate a coverage report:
This requires @vitest/coverage-v8 to be installed.