Testing Strategy
Relevant source files
The following files were used as context for generating this wiki page:
The testing strategy for the pubm project is designed to ensure the reliability and stability of a multi-registry publishing CLI. It combines high coverage requirements with specialized test suites for core logic and command-line interfaces. The project enforces strict quality gates before any code can be merged, focusing on both unit and end-to-end verification.
Testing is primarily executed using Vitest within a Bun workspace environment. The architecture separates testing into package-specific suites, ensuring that both the @pubm/core SDK and the pubm CLI are independently and collectively verified.
Sources: CLAUDE.md:1-55, CONTRIBUTING.md:1-110
Testing Infrastructure and Requirements
The project follows a strict set of rules for maintaining code quality. Every new source file must have a matching test file located in tests/unit/ within its respective package.
Coverage Thresholds
The project enforces high coverage thresholds per package, defined in vitest.config.mts.
| Metric | Threshold |
|---|---|
| Lines, Functions, Statements | 95% |
| Branches | 90% |
Developers are prohibited from lowering these thresholds and must run bun run coverage before committing to ensure the gate is met.
Sources: CLAUDE.md:55-65, CONTRIBUTING.md:100-110
Test Execution Flow
Tests are executed using the forks pool with a 30s timeout to handle intensive operations like Git simulations or file system mocks.
The diagram shows how the build system uses Turborepo to distribute test execution across packages before running coverage checks.
Sources: CLAUDE.md:40-65, CONTRIBUTING.md:85-95
Unit Testing Patterns
Unit tests in pubm focus on isolating logic through extensive mocking of the file system, Git, and child processes.
Command Initialization Testing
Tests for the init command verify the interactive setup wizard. These tests mock enquirer for user prompts and node:fs to prevent actual file writes during the test run. They verify:
- Detection of monorepo vs. single-package structures.
- Generation of
pubm.config.ts. - Creation of GitHub Action workflows for releases and changesets.
Sources: packages/pubm/tests/unit/commands/init.test.ts:10-100, packages/pubm/tests/unit/commands/init-workflows.test.ts:10-50
Task Runner and Pipeline Verification
The core task runner uses a specialized testing helper called makeTestContext to simulate different project states (CI vs. Local mode, dry-run, etc.).
The sequence diagram illustrates the mocked flow of a version bump and tagging operation during a unit test.
Sources: packages/core/tests/unit/tasks/runner-coverage.test.ts:1-200, packages/core/tests/unit/tasks/runner.test.ts:1-150
Prerequisite and Condition Checks
Specific test suites target the pre-publish safety checks:
- Branch Verification: Ensures the user is on the correct release branch.
- Remote History: Verifies that local history is synchronized with the remote.
- Working Tree: Checks for uncommitted changes.
- Commit History: Verifies that new commits exist since the last tag.
Sources: packages/core/tests/unit/tasks/prerequisites-check.test.ts:1-350
Mocking Strategy
The project utilizes vi.mock and vi.hoisted heavily to isolate the core logic from external side effects.
| Component | Mocking Approach |
|---|---|
| Git | Full class mock with vi.fn() for branch, push, tag, and commit. |
| FileSystem | node:fs methods like mkdirSync and writeFileSync are intercepted. |
| Exec | child_process and custom exec wrappers are mocked to return fixed strings. |
| UI/Console | ui.success, ui.warn, and ui.error are mocked to verify user feedback without cluttering logs. |
Sources: packages/pubm/tests/unit/commands/init.test.ts:15-60, packages/core/tests/unit/tasks/runner-coverage.test.ts:10-150
Pre-commit Checklist
A mandatory four-step checklist must pass before any commit is finalized. This is enforced to prevent regressions and maintain the coverage gate.
bun run format: Auto-fixes linting and formatting via Biome.bun run typecheck: Ensures TypeScript type safety.bun run test: Executes the full test suite.bun run coverage: Verifies coverage thresholds are not breached.
Sources: CLAUDE.md:48-53, CONTRIBUTING.md:105-110
Summary
The pubm testing strategy relies on a multi-layered approach using Vitest and Bun. By enforcing a 95% coverage threshold and utilizing a robust mocking infrastructure for Git and file systems, the project ensures that its complex publishing pipelines remain reliable across different environments and monorepo configurations. The pre-commit checklist serves as the final manual gate to guarantee that code quality standards are consistently met.