| name | test |
| description | Run and write Vitest tests, mock Jaypie with testkit, CI matrix Use when this capability is needed. |
| metadata | {"author":"finlaysonstudio"} |
Test
How to run and write tests in this monorepo.
Running Tests
npm test
npm test -w packages/<name>
npm test -w workspaces/<name>
Never run bare vitest -- it defaults to watch mode and won't terminate. Always use npm test or vitest run.
Specific Test Shortcuts
npm run test:jaypie
npm run test:llm
npm run test:testkit
npm run test:express
npm run test:errors
LLM Client Tests (Integration)
Require API keys. Run locally or in CI when packages/llm/** changes:
npm run test:llm:client
npm run test:llm:all
npm run test:llm:joke
Test Framework
- Vitest with workspace configuration
vitest.workspace.ts at root discovers packages/*/vitest.config.{ts,js}
- Each package with tests has its own
vitest.config.ts and optional vitest.setup.ts
- Tests run across Node.js 22, 24, 25 in CI
Writing Tests
File Location
Tests live alongside source or in __tests__/ directories:
src/
├── services/
│ └── user.ts
└── __tests__/
└── user.spec.ts
# Or co-located:
src/
└── services/
├── user.ts
└── user.spec.ts
Test Structure
import { describe, expect, it, vi, beforeEach } from "vitest";
describe("MyFunction", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("does the expected thing", async () => {
const input = { key: "value" };
const result = await myFunction(input);
expect(result).toBeDefined();
});
});
Mocking Jaypie
Most packages mock jaypie in their vitest.setup.ts:
import { vi } from "vitest";
vi.mock("jaypie", async () => {
const { mockJaypie } = await import("@jaypie/testkit");
return mockJaypie(vi);
});
This mocks log, getSecret, sendMessage, and other Jaypie exports as vi.fn().
Using Mocks in Tests
import { log, getSecret } from "jaypie";
it("logs the operation", async () => {
await myFunction();
expect(log.info).toHaveBeenCalledWith("message");
});
it("reads a secret", async () => {
vi.mocked(getSecret).mockResolvedValue("mock-value");
await myFunction();
expect(getSecret).toHaveBeenCalledWith("secret-name");
});
Other Available Mocks
vi.mock("@jaypie/logger", async () => {
const { mockLogger } = await import("@jaypie/testkit");
return mockLogger(vi);
});
vi.mock("@jaypie/aws", async () => {
const { mockAws } = await import("@jaypie/testkit");
return mockAws(vi);
});
Testing Errors
import { NotFoundError } from "jaypie";
it("throws NotFoundError when missing", async () => {
await expect(myFunction("bad-id")).rejects.toThrow(NotFoundError);
});
Custom Matchers
import { matchers } from "@jaypie/testkit";
expect.extend(matchers);
it("throws a Jaypie error", async () => {
await expect(myFunction()).rejects.toBeJaypieError();
});
Vitest Config Template
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
coverage: {
reporter: ["text", "json", "html"],
},
globals: true,
setupFiles: ["./vitest.setup.ts"],
},
});
Build Before Test
Tests often depend on built artifacts. In CI, npm run build runs before npm test. Locally, if tests fail on import errors, rebuild first:
npm run build && npm test -w packages/<name>
Testkit Export Requirement
When adding a new export to any package, update packages/testkit to mock it -- otherwise tests across the monorepo will fail.
CI Testing Matrix
Tests run on Node.js 22, 24, 25 in npm-check.yml and on 22, 24 in stack deployment workflows. The continue-on-error typecheck job won't block merges but lint and test must pass.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.