@yandy-r/ycc-opencode 0.0.0-stage → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +39 -0
- package/LICENSE +21 -0
- package/README.md +50 -2
- package/agents/ansible-automation-expert.md +115 -0
- package/agents/api-docs-expert.md +146 -0
- package/agents/api-documenter.md +105 -0
- package/agents/architect.md +264 -0
- package/agents/architecture-analyst.md +99 -0
- package/agents/backport-conflict-resolver.md +476 -0
- package/agents/cloudflare-architect.md +85 -0
- package/agents/cloudflare-developer.md +196 -0
- package/agents/code-architect.md +101 -0
- package/agents/code-documenter.md +114 -0
- package/agents/code-explorer.md +99 -0
- package/agents/code-finder.md +83 -0
- package/agents/code-researcher.md +102 -0
- package/agents/code-reviewer.md +268 -0
- package/agents/code-simplifier.md +77 -0
- package/agents/codebase-advisor.md +130 -0
- package/agents/db-modifier.md +577 -0
- package/agents/docs-git-committer.md +220 -0
- package/agents/documentation-writer.md +92 -0
- package/agents/feature-researcher.md +121 -0
- package/agents/feature-writer.md +89 -0
- package/agents/frontend-ui-developer.md +98 -0
- package/agents/git-cleanup.md +174 -0
- package/agents/go-api-architect.md +172 -0
- package/agents/go-expert-architect.md +147 -0
- package/agents/implementor.md +167 -0
- package/agents/library-docs-writer.md +128 -0
- package/agents/nextjs-ux-ui-expert.md +127 -0
- package/agents/nodejs-backend-architect.md +112 -0
- package/agents/nodejs-backend-developer.md +184 -0
- package/agents/planner.md +257 -0
- package/agents/pr-comment-fixer.md +626 -0
- package/agents/practices-researcher.md +80 -0
- package/agents/project-file-cleaner.md +140 -0
- package/agents/prp-researcher.md +231 -0
- package/agents/python-developer.md +171 -0
- package/agents/python-expert-architect.md +188 -0
- package/agents/readme-generator.md +100 -0
- package/agents/release-fix-applier.md +558 -0
- package/agents/releaser.md +147 -0
- package/agents/research-specialist.md +106 -0
- package/agents/reverse-proxy-architect.md +131 -0
- package/agents/review-fixer.md +609 -0
- package/agents/root-cause-analyzer.md +105 -0
- package/agents/rust-build-resolver.md +183 -0
- package/agents/rust-expert-architect.md +149 -0
- package/agents/rust-reviewer.md +126 -0
- package/agents/sql-database-developer.md +195 -0
- package/agents/systems-engineering-expert.md +203 -0
- package/agents/terraform-architect.md +109 -0
- package/agents/terraform-developer.md +229 -0
- package/agents/test-strategy-planner.md +126 -0
- package/agents/turso-database-architect.md +139 -0
- package/agents/typescript-developer.md +170 -0
- package/agents/typescript-expert-architect.md +167 -0
- package/index.js +523 -0
- package/package.json +36 -4
- package/registration.json +7259 -0
- package/shared/references/agent-native-setup.md +121 -0
- package/shared/references/branch-prep.md +31 -0
- package/shared/references/branching-model.md +162 -0
- package/shared/references/ci-monitoring.md +455 -0
- package/shared/references/forge-detection.md +162 -0
- package/shared/references/goal-pairing.md +55 -0
- package/shared/references/pr-base-and-backport.md +143 -0
- package/shared/references/question-policy.md +99 -0
- package/shared/references/review-artifact-format.md +141 -0
- package/shared/references/review-checklist.md +161 -0
- package/shared/references/review-dispatch.md +73 -0
- package/shared/references/session-state.md +159 -0
- package/shared/references/standalone-dispatch.md +300 -0
- package/shared/references/target-capability-matrix.md +516 -0
- package/shared/references/visual-mode.md +155 -0
- package/shared/references/worktree-strategy.md +326 -0
- package/shared/scripts/backport-audit.sh +283 -0
- package/shared/scripts/ci-monitor.sh +637 -0
- package/shared/scripts/lib/backport-lib.sh +47 -0
- package/shared/scripts/lib/ci-classify.sh +103 -0
- package/shared/scripts/lib/forge.sh +264 -0
- package/shared/scripts/lib/release-state-lib.sh +300 -0
- package/shared/scripts/list-worktrees.sh +178 -0
- package/shared/scripts/merge-children.sh +82 -0
- package/shared/scripts/move-plan-to-worktree.sh +231 -0
- package/shared/scripts/pr-guard.sh +283 -0
- package/shared/scripts/prepare-feature-branch.sh +326 -0
- package/shared/scripts/release-ci-monitor.sh +671 -0
- package/shared/scripts/release-state-update.sh +216 -0
- package/shared/scripts/release-state.sh +178 -0
- package/shared/scripts/report-bundle-drift.sh +343 -0
- package/shared/scripts/require-python.sh +17 -0
- package/shared/scripts/resolve-plans-dir.sh +262 -0
- package/shared/scripts/rules-pointer.sh +20 -0
- package/shared/scripts/rules_pointer.py +267 -0
- package/shared/scripts/setup-worktree.sh +288 -0
- package/shared/scripts/validate-file-paths.sh +249 -0
- package/shared/scripts/visual-egress-guard.sh +303 -0
- package/shared/scripts/visual-recap-collect.sh +247 -0
- package/shared/scripts/worktree-paths.sh +91 -0
- package/skills/backport/SKILL.md +293 -0
- package/skills/backport/scripts/cherry-pick-pr.sh +232 -0
- package/skills/backport/scripts/find-pending.sh +199 -0
- package/skills/blueprint/SKILL.md +412 -0
- package/skills/blueprint/references/bootstrap-mapping.md +87 -0
- package/skills/bundle-author/SKILL.md +121 -0
- package/skills/bundle-author/references/surface-map.md +128 -0
- package/skills/bundle-author/references/templates/agent-template.md +21 -0
- package/skills/bundle-author/references/templates/skill-template.md +36 -0
- package/skills/bundle-author/references/when-not-to-scaffold.md +85 -0
- package/skills/bundle-author/scripts/scaffold-skill.sh +156 -0
- package/skills/bundle-release/SKILL.md +192 -0
- package/skills/bundle-release/references/release-checklist.md +196 -0
- package/skills/bundle-release/references/release-notes-template.md +48 -0
- package/skills/bundle-release/references/version-policy.md +156 -0
- package/skills/bundle-release/scripts/bump-version.sh +99 -0
- package/skills/bundle-release/scripts/draft-notes.sh +222 -0
- package/skills/bundle-release/scripts/preflight.sh +165 -0
- package/skills/bundle-release/scripts/release_versions.py +375 -0
- package/skills/clean/SKILL.md +109 -0
- package/skills/clean/references/agent-prompts.md +199 -0
- package/skills/clean/references/safety-config.md +125 -0
- package/skills/clean/scripts/detect-project-type.sh +423 -0
- package/skills/clean/scripts/generate-report.sh +245 -0
- package/skills/clean/scripts/validate-safety.sh +401 -0
- package/skills/code-report/SKILL.md +377 -0
- package/skills/code-report/scripts/check-prerequisites.sh +65 -0
- package/skills/code-report/templates/report-structure.md +202 -0
- package/skills/code-review/SKILL.md +155 -0
- package/skills/code-review/references/pr-procedure.md +311 -0
- package/skills/compatibility-audit/SKILL.md +229 -0
- package/skills/compatibility-audit/references/reading-the-report.md +162 -0
- package/skills/compatibility-audit/scripts/audit-install-assumptions.sh +431 -0
- package/skills/compatibility-audit/scripts/audit-target-features.sh +596 -0
- package/skills/deep-research/SKILL.md +251 -0
- package/skills/deep-research/references/analysis-prompts.md +702 -0
- package/skills/deep-research/references/completion-summary-template.md +66 -0
- package/skills/deep-research/references/persona-analogical.md +159 -0
- package/skills/deep-research/references/persona-archaeological.md +69 -0
- package/skills/deep-research/references/persona-contrarian.md +155 -0
- package/skills/deep-research/references/persona-futurist.md +70 -0
- package/skills/deep-research/references/persona-historical.md +142 -0
- package/skills/deep-research/references/persona-journalistic.md +69 -0
- package/skills/deep-research/references/persona-negative-space.md +70 -0
- package/skills/deep-research/references/persona-systems.md +69 -0
- package/skills/deep-research/references/synthesis-template.md +569 -0
- package/skills/deep-research/references/verification-log-template.md +32 -0
- package/skills/deep-research/scripts/check-prerequisites.sh +153 -0
- package/skills/deep-research/scripts/validate-research.sh +244 -0
- package/skills/feature-research/SKILL.md +294 -0
- package/skills/feature-research/scripts/validate-research.sh +159 -0
- package/skills/feature-research/scripts/validate-spec.sh +270 -0
- package/skills/feature-research/templates/research-agents.md +569 -0
- package/skills/feature-research/templates/spec-structure.md +437 -0
- package/skills/formatters/SKILL.md +209 -0
- package/skills/formatters/references/best-practices.md +78 -0
- package/skills/formatters/references/flag-reference.md +178 -0
- package/skills/formatters/references/stack-detection.md +119 -0
- package/skills/formatters/references/templates/husky-pre-commit.tmpl +13 -0
- package/skills/formatters/references/templates/justfile-snippet.just.tmpl +31 -0
- package/skills/formatters/references/templates/lefthook.yml.tmpl +22 -0
- package/skills/formatters/references/templates/lint-autofix.yml.tmpl +94 -0
- package/skills/formatters/references/templates/lint.yml.tmpl +85 -0
- package/skills/formatters/references/templates/makefile-snippet.mk.tmpl +34 -0
- package/skills/formatters/references/templates/package-json-scripts.json.tmpl +14 -0
- package/skills/formatters/references/templates/readme-section.md.tmpl +118 -0
- package/skills/formatters/scripts/apply-aliases.sh +245 -0
- package/skills/formatters/scripts/apply-ci.sh +136 -0
- package/skills/formatters/scripts/apply-docs.sh +187 -0
- package/skills/formatters/scripts/apply-hooks.sh +261 -0
- package/skills/formatters/scripts/bundle/format.sh +15 -0
- package/skills/formatters/scripts/bundle/go-tools.sh +119 -0
- package/skills/formatters/scripts/bundle/init-formatters.sh +517 -0
- package/skills/formatters/scripts/bundle/install-shellcheck.sh +85 -0
- package/skills/formatters/scripts/bundle/lib/excludes.sh +179 -0
- package/skills/formatters/scripts/bundle/lib/modified-files.sh +222 -0
- package/skills/formatters/scripts/bundle/lib/shellcheck-resolve.sh +81 -0
- package/skills/formatters/scripts/bundle/lib/shellcheck-version.sh +5 -0
- package/skills/formatters/scripts/bundle/lint.sh +15 -0
- package/skills/formatters/scripts/bundle/style.sh +1410 -0
- package/skills/formatters/scripts/bundle/templates/biome.json +81 -0
- package/skills/formatters/scripts/bundle/templates/clippy.toml +2 -0
- package/skills/formatters/scripts/bundle/templates/markdownlint.json +14 -0
- package/skills/formatters/scripts/bundle/templates/markdownlintignore +38 -0
- package/skills/formatters/scripts/bundle/templates/prettierignore +45 -0
- package/skills/formatters/scripts/bundle/templates/prettierrc.json +11 -0
- package/skills/formatters/scripts/bundle/templates/python-pyproject.toml +80 -0
- package/skills/formatters/scripts/bundle/templates/rustfmt.toml +41 -0
- package/skills/formatters/scripts/bundle/templates/tsconfig.json +21 -0
- package/skills/formatters/scripts/profile-style.sh +264 -0
- package/skills/frontend-design/SKILL.md +151 -0
- package/skills/frontend-patterns/SKILL.md +66 -0
- package/skills/frontend-patterns/references/animation.md +21 -0
- package/skills/frontend-patterns/references/components-and-state.md +40 -0
- package/skills/frontend-patterns/references/data-and-performance.md +34 -0
- package/skills/frontend-patterns/references/forms-errors-a11y.md +35 -0
- package/skills/git-cleanup/SKILL.md +300 -0
- package/skills/git-cleanup/references/active-code-rules.md +323 -0
- package/skills/git-cleanup/references/host-detection.md +217 -0
- package/skills/git-workflow/SKILL.md +132 -0
- package/skills/git-workflow/references/ci-monitoring-phase.md +130 -0
- package/skills/git-workflow/references/commit-phases.md +247 -0
- package/skills/git-workflow/references/examples-and-troubleshooting.md +47 -0
- package/skills/git-workflow/references/goal-pairing.md +23 -0
- package/skills/git-workflow/references/pr-creation.md +269 -0
- package/skills/git-workflow/scripts/analyze-changes.sh +266 -0
- package/skills/git-workflow/scripts/create-pr.sh +464 -0
- package/skills/git-workflow/scripts/validate-commit.sh +235 -0
- package/skills/git-workflow/templates/agent-prompts.md +518 -0
- package/skills/git-workflow/templates/commit-types.md +504 -0
- package/skills/git-workflow/templates/documentation-decision.md +509 -0
- package/skills/git-workflow/templates/pr-template.md +772 -0
- package/skills/go-patterns/SKILL.md +89 -0
- package/skills/go-patterns/references/design-and-tooling.md +336 -0
- package/skills/go-patterns/references/errors-and-concurrency.md +292 -0
- package/skills/go-testing/SKILL.md +133 -0
- package/skills/go-testing/references/advanced-testing.md +349 -0
- package/skills/go-testing/references/test-structure.md +277 -0
- package/skills/hooks-workflow/SKILL.md +232 -0
- package/skills/hooks-workflow/references/support-notes.md +134 -0
- package/skills/hooks-workflow/references/templates/claude-settings.json.tmpl +13 -0
- package/skills/hooks-workflow/references/templates/codex-config-fragment.toml.tmpl +9 -0
- package/skills/hooks-workflow/references/templates/cursor-rule-fragment.mdc.tmpl +16 -0
- package/skills/hooks-workflow/scripts/build-hook-config.sh +487 -0
- package/skills/hooks-workflow/scripts/verify-hooks.sh +257 -0
- package/skills/implement-plan/SKILL.md +223 -0
- package/skills/implement-plan/references/agent-task-prompt.md +214 -0
- package/skills/implement-plan/references/output-formats.md +150 -0
- package/skills/implement-plan/references/plan-inputs.md +126 -0
- package/skills/implement-plan/scripts/check-prerequisites.sh +78 -0
- package/skills/implement-plan/scripts/parse-dependencies.sh +206 -0
- package/skills/init/SKILL.md +274 -0
- package/skills/init/references/conventional-commits.md +114 -0
- package/skills/init/references/flag-reference.md +236 -0
- package/skills/init/references/label-taxonomy.md +115 -0
- package/skills/init/references/project-profile-heuristics.md +156 -0
- package/skills/init/references/template-library.md +129 -0
- package/skills/init/scripts/count-source-files.sh +60 -0
- package/skills/init/scripts/generate-agent-catalog.sh +193 -0
- package/skills/init/scripts/generate-mcp-catalog.sh +214 -0
- package/skills/init/scripts/migrate-rules.py +459 -0
- package/skills/init/scripts/migrate-rules.sh +26 -0
- package/skills/init/scripts/profile-project.sh +453 -0
- package/skills/init/scripts/render-template.py +226 -0
- package/skills/init/scripts/render-template.sh +25 -0
- package/skills/init/scripts/rules-report.sh +31 -0
- package/skills/init/scripts/rules_file_lib.py +41 -0
- package/skills/init/templates/AGENTS.md.tmpl +38 -0
- package/skills/init/templates/CLAUDE.md.tmpl +7 -0
- package/skills/init/templates/ai-rule.md.tmpl +3 -0
- package/skills/init/templates/cursor-rule.mdc.tmpl +7 -0
- package/skills/init/templates/git/commitlint.config.cjs.tmpl +40 -0
- package/skills/init/templates/git/gitignore.tmpl +121 -0
- package/skills/init/templates/git/gitmessage.tmpl +27 -0
- package/skills/init/templates/git/install-lefthook.sh.tmpl +131 -0
- package/skills/init/templates/git/lefthook-usage.md.tmpl +101 -0
- package/skills/init/templates/git/lefthook.yml.tmpl +64 -0
- package/skills/init/templates/github/bug_report.yml.tmpl +78 -0
- package/skills/init/templates/github/config.yml.tmpl +5 -0
- package/skills/init/templates/github/copilot-instructions.md.tmpl +24 -0
- package/skills/init/templates/github/docs_request.yml.tmpl +41 -0
- package/skills/init/templates/github/feature_request.yml.tmpl +59 -0
- package/skills/init/templates/github/labels.md.tmpl +75 -0
- package/skills/init/templates/github/pull_request_template.md.tmpl +66 -0
- package/skills/init/templates/github/workflows/pr-title-autofix.yml.tmpl +101 -0
- package/skills/init/templates/github/workflows/pr-title.yml.tmpl +55 -0
- package/skills/init/templates/workspace-report.md +83 -0
- package/skills/orchestrate/SKILL.md +165 -0
- package/skills/orchestrate/references/agent-catalog.md +601 -0
- package/skills/orchestrate/references/agent-prompts.md +495 -0
- package/skills/orchestrate/references/dispatch-playbook.md +333 -0
- package/skills/orchestrate/references/task-breakdown.md +410 -0
- package/skills/orchestrate/scripts/analyze-task.sh +139 -0
- package/skills/orchestrate/scripts/summarize-results.sh +160 -0
- package/skills/orchestrate/scripts/validate-agents.sh +92 -0
- package/skills/parallel-plan/SKILL.md +124 -0
- package/skills/plan/SKILL.md +136 -0
- package/skills/plan/references/enhanced-personas.md +131 -0
- package/skills/plan/references/personas-and-merge.md +77 -0
- package/skills/plan/references/plan-validation.md +65 -0
- package/skills/plan/references/planner-prompts.md +68 -0
- package/skills/plan/references/planning-tracks.md +73 -0
- package/skills/plan-workflow/SKILL.md +409 -0
- package/skills/plan-workflow/references/checkpoint-messages.md +370 -0
- package/skills/plan-workflow/references/plan-structure.md +238 -0
- package/skills/plan-workflow/references/planning-agents.md +511 -0
- package/skills/plan-workflow/references/research-agents-optimized.md +348 -0
- package/skills/plan-workflow/references/research-agents.md +436 -0
- package/skills/plan-workflow/references/shared-structure.md +152 -0
- package/skills/plan-workflow/references/validation-agents.md +363 -0
- package/skills/plan-workflow/scripts/check-prerequisites.sh +65 -0
- package/skills/plan-workflow/scripts/check-state.sh +190 -0
- package/skills/plan-workflow/scripts/persist-or-fail.sh +135 -0
- package/skills/plan-workflow/scripts/validate-analysis-artifacts.sh +216 -0
- package/skills/plan-workflow/scripts/validate-research-artifacts.sh +225 -0
- package/skills/plan-workflow/scripts/validate-shared.sh +229 -0
- package/skills/plan-workflow/scripts/validate-workflow-plan.sh +256 -0
- package/skills/pr-autofix/SKILL.md +309 -0
- package/skills/pr-autofix/references/ci-loop.md +64 -0
- package/skills/pr-autofix/references/comment-sources.md +197 -0
- package/skills/pr-autofix/references/data-shapes.md +87 -0
- package/skills/pr-autofix/references/goal-example.md +30 -0
- package/skills/pr-autofix/references/output-templates.md +162 -0
- package/skills/pr-autofix/references/prompt-injection-safety.md +165 -0
- package/skills/pr-autofix/references/related-skills.md +11 -0
- package/skills/pr-autofix/references/severity-mapping.md +146 -0
- package/skills/pr-autofix/scripts/fetch-pr-comments.sh +364 -0
- package/skills/pr-autofix/scripts/post-summary.sh +226 -0
- package/skills/pr-autofix/scripts/resolve-thread.sh +251 -0
- package/skills/prp-commit/SKILL.md +128 -0
- package/skills/prp-implement/SKILL.md +179 -0
- package/skills/prp-implement/references/agent-task-prompt.md +36 -0
- package/skills/prp-implement/references/detection.md +49 -0
- package/skills/prp-implement/references/dry-run.md +0 -0
- package/skills/prp-implement/references/report-output.md +204 -0
- package/skills/prp-implement/references/validation-and-failures.md +118 -0
- package/skills/prp-plan/SKILL.md +323 -0
- package/skills/prp-plan/references/enhanced-researchers.md +425 -0
- package/skills/prp-plan/references/parallel-additions.md +56 -0
- package/skills/prp-plan/references/plan-template.md +264 -0
- package/skills/prp-plan/references/synthesis-map.md +25 -0
- package/skills/prp-plan/scripts/validate-prp-plan.sh +368 -0
- package/skills/prp-pr/SKILL.md +404 -0
- package/skills/prp-prd/SKILL.md +444 -0
- package/skills/prp-spec/SKILL.md +276 -0
- package/skills/python-patterns/SKILL.md +103 -0
- package/skills/python-patterns/references/core-idioms.md +304 -0
- package/skills/python-patterns/references/design-and-tooling.md +407 -0
- package/skills/python-testing/SKILL.md +114 -0
- package/skills/python-testing/references/mocking-and-integration.md +395 -0
- package/skills/python-testing/references/pytest-core.md +366 -0
- package/skills/quick-fix/SKILL.md +246 -0
- package/skills/quick-review/SKILL.md +306 -0
- package/skills/release-model/SKILL.md +233 -0
- package/skills/release-model/references/pointer-and-labels.md +83 -0
- package/skills/release-model/references/signals-and-proposal.md +68 -0
- package/skills/release-model/references/template-placeholders.md +42 -0
- package/skills/release-model/references/upgrade-and-audit.md +131 -0
- package/skills/release-model/scripts/collect-signals.sh +459 -0
- package/skills/release-model/scripts/pointer-targets.sh +29 -0
- package/skills/release-model/templates/RELEASING.md.tmpl +151 -0
- package/skills/releaser/SKILL.md +253 -0
- package/skills/releaser/references/ci-optimization-checklist.md +149 -0
- package/skills/releaser/references/ci-templates/docker-release.yml +88 -0
- package/skills/releaser/references/ci-templates/generic-release.yml +69 -0
- package/skills/releaser/references/ci-templates/go-release.yml +50 -0
- package/skills/releaser/references/ci-templates/node-release.yml +126 -0
- package/skills/releaser/references/ci-templates/python-release.yml +95 -0
- package/skills/releaser/references/ci-templates/rust-release.yml +128 -0
- package/skills/releaser/references/ci-workflow-modes.md +42 -0
- package/skills/releaser/references/goal-pairing.md +37 -0
- package/skills/releaser/references/output-templates.md +143 -0
- package/skills/releaser/references/project-type-matrix.md +144 -0
- package/skills/releaser/references/release-branches.md +138 -0
- package/skills/releaser/references/release-ci-loop.md +249 -0
- package/skills/releaser/references/release-notes-template.md +42 -0
- package/skills/releaser/references/release-preparation.md +210 -0
- package/skills/releaser/scripts/check-release-branch.sh +235 -0
- package/skills/releaser/scripts/detect-project.sh +234 -0
- package/skills/releaser/scripts/draft-changelog.sh +387 -0
- package/skills/releaser/scripts/publish-release.sh +302 -0
- package/skills/research-to-issues/SKILL.md +287 -0
- package/skills/research-to-issues/references/label-taxonomy.md +48 -0
- package/skills/research-to-issues/references/parse-deep-research.md +86 -0
- package/skills/research-to-issues/references/parse-feature-spec.md +143 -0
- package/skills/research-to-issues/references/parse-parallel-plan.md +124 -0
- package/skills/research-to-issues/references/parse-prd.md +184 -0
- package/skills/research-to-issues/references/parse-prp-plan.md +237 -0
- package/skills/research-to-issues/references/plan-display-format.md +136 -0
- package/skills/research-to-issues/scripts/validate-prerequisites.sh +312 -0
- package/skills/research-to-issues/templates/feature-issue.md +131 -0
- package/skills/research-to-issues/templates/task-issue.md +104 -0
- package/skills/research-to-issues/templates/tracking-issue.md +126 -0
- package/skills/resume-session/SKILL.md +154 -0
- package/skills/review-fix/SKILL.md +231 -0
- package/skills/review-fix/references/fix-report.md +121 -0
- package/skills/review-fix/references/fixer-dispatch.md +79 -0
- package/skills/review-fix/references/plan.md +119 -0
- package/skills/rust-patterns/SKILL.md +85 -0
- package/skills/rust-patterns/references/concurrency-unsafe-modules.md +243 -0
- package/skills/rust-patterns/references/ownership-errors-types.md +262 -0
- package/skills/rust-testing/SKILL.md +99 -0
- package/skills/rust-testing/references/advanced-testing.md +247 -0
- package/skills/rust-testing/references/unit-and-integration.md +193 -0
- package/skills/save-session/SKILL.md +161 -0
- package/skills/shared-context/SKILL.md +101 -0
- package/skills/ts-patterns/SKILL.md +159 -0
- package/skills/ts-patterns/references/async-runtimes-tooling.md +375 -0
- package/skills/ts-patterns/references/types-errors-modules.md +336 -0
- package/skills/ts-testing/SKILL.md +151 -0
- package/skills/ts-testing/references/advanced-testing.md +350 -0
- package/skills/ts-testing/references/vitest-core.md +318 -0
- package/skills/visual-plan/SKILL.md +221 -0
- package/skills/visual-plan/references/canvas.md +132 -0
- package/skills/visual-plan/references/document-quality.md +178 -0
- package/skills/visual-plan/references/exemplar.md +120 -0
- package/skills/visual-plan/references/wireframe.md +212 -0
- package/skills/visual-plan/scripts/derive-visual-dir.sh +77 -0
- package/skills/visual-recap/SKILL.md +238 -0
- package/skills/visual-recap/references/wireframe.md +237 -0
- package/skills/write-docs/SKILL.md +354 -0
- package/skills/write-docs/scripts/audit-documentation.sh +190 -0
- package/skills/write-docs/scripts/generate-doc-index.sh +125 -0
- package/skills/write-docs/scripts/verify-links.sh +81 -0
- package/skills/write-docs/templates/docs-readme.md +34 -0
- package/skills/write-docs/templates/documentation-strategy.md +91 -0
- package/ycc-sensitive-guard/index.js +621 -0
- package/ycc-sensitive-guard/package.json +7 -0
- package/ycc-sensitive-guard/policy.json +40 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
# TypeScript Testing Patterns: Advanced Testing
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Parameterized Tests with `test.each`
|
|
6
|
+
- Property-Based Testing with fast-check
|
|
7
|
+
- Mocking
|
|
8
|
+
- Type-Level Testing
|
|
9
|
+
- Benchmarks
|
|
10
|
+
- CI Integration
|
|
11
|
+
- Alternatives to Vitest
|
|
12
|
+
|
|
13
|
+
## Parameterized Tests with `test.each`
|
|
14
|
+
|
|
15
|
+
### Table of Cases
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { describe, it, expect } from 'vitest';
|
|
19
|
+
|
|
20
|
+
describe('add', () => {
|
|
21
|
+
it.each([
|
|
22
|
+
{ a: 2, b: 3, expected: 5 },
|
|
23
|
+
{ a: -1, b: -2, expected: -3 },
|
|
24
|
+
{ a: 0, b: 0, expected: 0 },
|
|
25
|
+
{ a: -1, b: 1, expected: 0 },
|
|
26
|
+
{ a: 1_000_000, b: 2_000_000, expected: 3_000_000 },
|
|
27
|
+
])('add($a, $b) → $expected', ({ a, b, expected }) => {
|
|
28
|
+
expect(add(a, b)).toBe(expected);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Running a Whole Suite Against Multiple Configs
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
37
|
+
|
|
38
|
+
describe.each([{ db: 'postgres' as const }, { db: 'sqlite' as const }])('storage with $db', ({ db }) => {
|
|
39
|
+
let store: Store;
|
|
40
|
+
|
|
41
|
+
beforeEach(() => {
|
|
42
|
+
store = makeStore(db);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('writes and reads', async () => {
|
|
46
|
+
await store.set('key', 'value');
|
|
47
|
+
expect(await store.get('key')).toBe('value');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('enforces constraints', async () => {
|
|
51
|
+
await expect(store.set('', 'value')).rejects.toThrow();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Property-Based Testing with fast-check
|
|
57
|
+
|
|
58
|
+
### Basic Properties
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { describe } from 'vitest';
|
|
62
|
+
import { fc, test } from '@fast-check/vitest';
|
|
63
|
+
import { encode, decode } from './codec';
|
|
64
|
+
|
|
65
|
+
describe('codec', () => {
|
|
66
|
+
test.prop([fc.string()])('encode then decode returns input', (input) => {
|
|
67
|
+
const encoded = encode(input);
|
|
68
|
+
const decoded = decode(encoded);
|
|
69
|
+
return decoded === input;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test.prop([fc.array(fc.integer(), { maxLength: 100 })])('sort preserves length and is ordered', (arr) => {
|
|
73
|
+
const sorted = [...arr].sort((a, b) => a - b);
|
|
74
|
+
if (sorted.length !== arr.length) return false;
|
|
75
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
76
|
+
if (sorted[i - 1]! > sorted[i]!) return false;
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Custom Arbitraries
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { fc, test } from '@fast-check/vitest';
|
|
87
|
+
import { expect } from 'vitest';
|
|
88
|
+
import { User } from './user';
|
|
89
|
+
|
|
90
|
+
const validEmail = fc
|
|
91
|
+
.tuple(fc.stringMatching(/^[a-z]{1,10}$/), fc.stringMatching(/^[a-z]{1,5}$/))
|
|
92
|
+
.map(([user, domain]) => `${user}@${domain}.com`);
|
|
93
|
+
|
|
94
|
+
test.prop([validEmail])('accepts valid emails', (email) => {
|
|
95
|
+
expect(() => new User('Test', email)).not.toThrow();
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Mocking
|
|
100
|
+
|
|
101
|
+
### `vi.fn()` — a Fresh Spy
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
105
|
+
|
|
106
|
+
describe('processItems', () => {
|
|
107
|
+
it('invokes the callback for each item', () => {
|
|
108
|
+
const cb = vi.fn();
|
|
109
|
+
processItems([1, 2, 3], cb);
|
|
110
|
+
expect(cb).toHaveBeenCalledTimes(3);
|
|
111
|
+
expect(cb).toHaveBeenNthCalledWith(1, 1);
|
|
112
|
+
expect(cb).toHaveBeenLastCalledWith(3);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('returns configured values on sequential calls', async () => {
|
|
116
|
+
const loader = vi.fn<(id: string) => Promise<User>>();
|
|
117
|
+
loader
|
|
118
|
+
.mockResolvedValueOnce({ id: '1', name: 'Alice', email: 'a@x.com' })
|
|
119
|
+
.mockRejectedValueOnce(new Error('not found'));
|
|
120
|
+
|
|
121
|
+
await expect(loader('1')).resolves.toMatchObject({ name: 'Alice' });
|
|
122
|
+
await expect(loader('2')).rejects.toThrow('not found');
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### `vi.spyOn()` — Wrap an Existing Method
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
131
|
+
import { UserService } from './user-service';
|
|
132
|
+
|
|
133
|
+
describe('UserService.saveUser', () => {
|
|
134
|
+
afterEach(() => {
|
|
135
|
+
vi.restoreAllMocks();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('logs before saving', async () => {
|
|
139
|
+
const logger = { info: vi.fn(), error: vi.fn() };
|
|
140
|
+
const service = new UserService({ logger });
|
|
141
|
+
const saveSpy = vi.spyOn(service, 'save');
|
|
142
|
+
|
|
143
|
+
await service.saveUser({ id: '1', name: 'Alice', email: 'a@x.com' });
|
|
144
|
+
|
|
145
|
+
expect(logger.info).toHaveBeenCalledWith(expect.stringContaining('saving user'));
|
|
146
|
+
expect(saveSpy).toHaveBeenCalled();
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### `vi.mock()` — Module-Level Mock
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
155
|
+
import { sendEmail } from './mailer';
|
|
156
|
+
import { registerUser } from './auth';
|
|
157
|
+
|
|
158
|
+
vi.mock('./mailer', () => ({
|
|
159
|
+
sendEmail: vi.fn().mockResolvedValue({ id: 'msg_1' }),
|
|
160
|
+
}));
|
|
161
|
+
|
|
162
|
+
describe('registerUser', () => {
|
|
163
|
+
beforeEach(() => {
|
|
164
|
+
vi.clearAllMocks();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('sends a welcome email on success', async () => {
|
|
168
|
+
await registerUser({ name: 'Alice', email: 'alice@example.com' });
|
|
169
|
+
expect(sendEmail).toHaveBeenCalledWith(
|
|
170
|
+
expect.objectContaining({
|
|
171
|
+
to: 'alice@example.com',
|
|
172
|
+
subject: expect.stringMatching(/welcome/i),
|
|
173
|
+
})
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Dependency Injection > Module Mocks
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
// Good: inject an interface — no vi.mock() needed, fully type-checked
|
|
183
|
+
interface UserRepository {
|
|
184
|
+
findById(id: string): Promise<User | null>;
|
|
185
|
+
save(user: User): Promise<void>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
class UserService {
|
|
189
|
+
constructor(private readonly repo: UserRepository) {}
|
|
190
|
+
|
|
191
|
+
async getUser(id: string): Promise<User> {
|
|
192
|
+
const user = await this.repo.findById(id);
|
|
193
|
+
if (!user) throw new NotFoundError('user', id);
|
|
194
|
+
return user;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Test with a plain fake — type-checked, no runner magic
|
|
199
|
+
it('throws when user is missing', async () => {
|
|
200
|
+
const fakeRepo: UserRepository = {
|
|
201
|
+
findById: async () => null,
|
|
202
|
+
save: async () => {},
|
|
203
|
+
};
|
|
204
|
+
const service = new UserService(fakeRepo);
|
|
205
|
+
await expect(service.getUser('missing')).rejects.toThrow(NotFoundError);
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Type-Level Testing
|
|
210
|
+
|
|
211
|
+
### `expectTypeOf` (Built Into Vitest)
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
import { describe, it, expectTypeOf } from 'vitest';
|
|
215
|
+
import { parseJSON, type JsonValue } from './json';
|
|
216
|
+
|
|
217
|
+
describe('parseJSON types', () => {
|
|
218
|
+
it('returns JsonValue', () => {
|
|
219
|
+
expectTypeOf(parseJSON).returns.toEqualTypeOf<JsonValue>();
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('accepts string input', () => {
|
|
223
|
+
expectTypeOf(parseJSON).parameter(0).toEqualTypeOf<string>();
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### `expect-type` (Standalone Library)
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
import { expectTypeOf } from 'expect-type';
|
|
232
|
+
import type { User } from './user';
|
|
233
|
+
|
|
234
|
+
expectTypeOf<User>().toHaveProperty('email').toEqualTypeOf<string>();
|
|
235
|
+
expectTypeOf<User>().toHaveProperty('name').toEqualTypeOf<string>();
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### `tsd` (Separate Type-Only Test Suite)
|
|
239
|
+
|
|
240
|
+
```ts
|
|
241
|
+
// test-d/user.test-d.ts
|
|
242
|
+
import { expectType, expectError } from 'tsd';
|
|
243
|
+
import { makeUser } from '..';
|
|
244
|
+
|
|
245
|
+
expectType<{ id: string; name: string }>(makeUser('alice'));
|
|
246
|
+
expectError(makeUser(42)); // should fail type check
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**When to test types vs runtime:**
|
|
250
|
+
|
|
251
|
+
- Test **types** when authoring a library whose public API makes type-level
|
|
252
|
+
guarantees (inference, conditional return types, branded outputs).
|
|
253
|
+
- Test **runtime** for everything else — types catch compile-time bugs; runtime
|
|
254
|
+
tests catch the rest.
|
|
255
|
+
|
|
256
|
+
## Benchmarks
|
|
257
|
+
|
|
258
|
+
```ts
|
|
259
|
+
// src/join.bench.ts
|
|
260
|
+
import { bench, describe } from 'vitest';
|
|
261
|
+
|
|
262
|
+
const parts = ['hello', 'world', 'foo', 'bar', 'baz'];
|
|
263
|
+
|
|
264
|
+
describe('string join', () => {
|
|
265
|
+
bench('plus operator', () => {
|
|
266
|
+
let s = '';
|
|
267
|
+
for (const p of parts) s += p;
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
bench('Array.join', () => {
|
|
271
|
+
const _ = parts.join('');
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
bench('template literal', () => {
|
|
275
|
+
const _ = `${parts[0]}${parts[1]}${parts[2]}${parts[3]}${parts[4]}`;
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// $ vitest bench
|
|
280
|
+
// BenchmarkJoin
|
|
281
|
+
// plus operator 12,345,678 ops/sec
|
|
282
|
+
// Array.join 18,765,432 ops/sec
|
|
283
|
+
// template literal 22,109,876 ops/sec
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
For heavier, standalone benchmarks (stats, multiple runs, comparison reports),
|
|
287
|
+
reach for `tinybench` or `mitata` directly.
|
|
288
|
+
|
|
289
|
+
## CI Integration
|
|
290
|
+
|
|
291
|
+
```yaml
|
|
292
|
+
# .github/workflows/test.yml
|
|
293
|
+
name: test
|
|
294
|
+
on:
|
|
295
|
+
push:
|
|
296
|
+
branches: [main]
|
|
297
|
+
pull_request:
|
|
298
|
+
|
|
299
|
+
jobs:
|
|
300
|
+
test:
|
|
301
|
+
runs-on: ubuntu-latest
|
|
302
|
+
steps:
|
|
303
|
+
- uses: actions/checkout@v4
|
|
304
|
+
- uses: pnpm/action-setup@v4
|
|
305
|
+
with: { version: 10 }
|
|
306
|
+
- uses: actions/setup-node@v4
|
|
307
|
+
with:
|
|
308
|
+
node-version: '22'
|
|
309
|
+
cache: 'pnpm'
|
|
310
|
+
|
|
311
|
+
- run: pnpm install --frozen-lockfile
|
|
312
|
+
|
|
313
|
+
- name: Type check
|
|
314
|
+
run: pnpm exec tsc --noEmit
|
|
315
|
+
|
|
316
|
+
- name: Lint
|
|
317
|
+
run: pnpm exec biome ci .
|
|
318
|
+
|
|
319
|
+
- name: Run tests with coverage
|
|
320
|
+
run: pnpm exec vitest run --coverage
|
|
321
|
+
|
|
322
|
+
- uses: codecov/codecov-action@v4
|
|
323
|
+
with:
|
|
324
|
+
files: ./coverage/lcov.info
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
## Alternatives to Vitest
|
|
328
|
+
|
|
329
|
+
The ecosystem has several other runners; reach for them when the constraints fit.
|
|
330
|
+
|
|
331
|
+
- **Jest** — legacy-common, large plugin ecosystem. Vitest's `describe` / `it` /
|
|
332
|
+
`expect` / `vi.fn` / `vi.mock` surface is intentionally Jest-compatible, so
|
|
333
|
+
migration usually means aliasing imports and adjusting config. Prefer Vitest for
|
|
334
|
+
new projects — it's faster, has native ESM/TS, and shares config with Vite.
|
|
335
|
+
- **`node:test`** — Node's built-in test runner (Node 18+). Zero dependencies.
|
|
336
|
+
Good fit for small libraries or when avoiding bundler/transform deps. Lacks
|
|
337
|
+
Vitest's mocking ergonomics, snapshot polish, and watch-mode UI.
|
|
338
|
+
- **`bun test`** — Bun's built-in runner, Jest-compatible API, very fast
|
|
339
|
+
install-plus-run cycle. Good on Bun-first projects; some Vitest plugins don't
|
|
340
|
+
have Bun equivalents.
|
|
341
|
+
- **`deno test`** — Deno's built-in runner using the standard `@std/assert`
|
|
342
|
+
module. Good for Deno-native code. Permissions model means integration tests
|
|
343
|
+
need explicit flags.
|
|
344
|
+
- **Playwright** — end-to-end browser testing. _Complements_ Vitest rather than
|
|
345
|
+
replacing it — use Vitest for unit and integration, Playwright for real-browser
|
|
346
|
+
e2e flows.
|
|
347
|
+
|
|
348
|
+
**Remember**: Tests are documentation. They show how your code is meant to be used.
|
|
349
|
+
Keep them clear, fast, and strict-mode-compliant. The best test is one that fails
|
|
350
|
+
loudly when the behavior it describes breaks — and stays silent the rest of the time.
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
# TypeScript Testing Patterns: Vitest Core
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- TDD Workflow for TypeScript
|
|
6
|
+
- Unit Tests
|
|
7
|
+
- Assertions
|
|
8
|
+
- Error and Rejection Testing
|
|
9
|
+
- Integration Tests
|
|
10
|
+
- Async Tests and Fake Timers
|
|
11
|
+
|
|
12
|
+
## TDD Workflow for TypeScript
|
|
13
|
+
|
|
14
|
+
### The RED-GREEN-REFACTOR Cycle
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
RED → Write a failing test first
|
|
18
|
+
GREEN → Write minimal code to pass the test
|
|
19
|
+
REFACTOR → Improve code while keeping tests green
|
|
20
|
+
REPEAT → Continue with next requirement
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Step-by-Step TDD in TypeScript
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
// calculator.ts — RED: stub with a placeholder that throws
|
|
27
|
+
export function add(a: number, b: number): number {
|
|
28
|
+
throw new Error('not yet implemented');
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
// calculator.test.ts — write the test first
|
|
34
|
+
import { describe, it, expect } from 'vitest';
|
|
35
|
+
import { add } from './calculator';
|
|
36
|
+
|
|
37
|
+
describe('add', () => {
|
|
38
|
+
it('sums two numbers', () => {
|
|
39
|
+
expect(add(2, 3)).toBe(5);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// $ vitest
|
|
44
|
+
// FAIL calculator.test.ts > add > sums two numbers
|
|
45
|
+
// Error: not yet implemented
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
// GREEN: minimal implementation
|
|
50
|
+
export function add(a: number, b: number): number {
|
|
51
|
+
return a + b;
|
|
52
|
+
}
|
|
53
|
+
// $ vitest → PASS, then REFACTOR while tests stay green
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Unit Tests
|
|
57
|
+
|
|
58
|
+
### Colocated Unit Tests
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
// src/user.ts
|
|
62
|
+
export class User {
|
|
63
|
+
constructor(
|
|
64
|
+
public readonly name: string,
|
|
65
|
+
public readonly email: string
|
|
66
|
+
) {
|
|
67
|
+
if (!email.includes('@')) {
|
|
68
|
+
throw new Error(`invalid email: ${email}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get displayName(): string {
|
|
73
|
+
return this.name;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
// src/user.test.ts — colocated with the source
|
|
80
|
+
import { describe, it, expect } from 'vitest';
|
|
81
|
+
import { User } from './user';
|
|
82
|
+
|
|
83
|
+
describe('User', () => {
|
|
84
|
+
it('creates a user with a valid email', () => {
|
|
85
|
+
const user = new User('Alice', 'alice@example.com');
|
|
86
|
+
expect(user.displayName).toBe('Alice');
|
|
87
|
+
expect(user.email).toBe('alice@example.com');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('rejects invalid emails', () => {
|
|
91
|
+
expect(() => new User('Bob', 'not-an-email')).toThrow('invalid email');
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**File conventions:**
|
|
97
|
+
|
|
98
|
+
- `.test.ts` or `.spec.ts` are picked up by Vitest by default.
|
|
99
|
+
- Colocation (`src/user.ts` + `src/user.test.ts`) or a `__tests__/` directory both
|
|
100
|
+
work — colocation is more common and easier to navigate.
|
|
101
|
+
- Configure via `test.include` in `vitest.config.ts`.
|
|
102
|
+
|
|
103
|
+
## Assertions
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { expect } from 'vitest';
|
|
107
|
+
|
|
108
|
+
expect(2 + 2).toBe(4); // strict equality
|
|
109
|
+
expect({ a: 1 }).toEqual({ a: 1 }); // deep equality
|
|
110
|
+
expect([1, 2, 3]).toContain(2); // array contains
|
|
111
|
+
expect('hello world').toMatch(/world/); // regex match
|
|
112
|
+
expect(value).toBeDefined(); // not undefined
|
|
113
|
+
expect(value).toBeNull(); // strict null
|
|
114
|
+
expect(value).toBeTruthy(); // JS truthy
|
|
115
|
+
expect(0.1 + 0.2).toBeCloseTo(0.3); // float compare
|
|
116
|
+
expect({ a: 1, b: 2, c: 3 }).toMatchObject({ a: 1 }); // partial deep equal
|
|
117
|
+
expect(fn).toHaveBeenCalledWith('expected-arg'); // spy assertion
|
|
118
|
+
|
|
119
|
+
// Snapshots
|
|
120
|
+
expect(result).toMatchInlineSnapshot(`
|
|
121
|
+
{
|
|
122
|
+
"items": [1, 2, 3],
|
|
123
|
+
"status": "ok",
|
|
124
|
+
}
|
|
125
|
+
`);
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Custom Matchers
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { expect } from 'vitest';
|
|
132
|
+
|
|
133
|
+
expect.extend({
|
|
134
|
+
toBeValidEmail(received: string) {
|
|
135
|
+
const pass = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(received);
|
|
136
|
+
return {
|
|
137
|
+
pass,
|
|
138
|
+
message: () => `expected ${received} ${pass ? 'not ' : ''}to be a valid email`,
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Extend Vitest's type surface
|
|
144
|
+
declare module 'vitest' {
|
|
145
|
+
interface Assertion<T = unknown> {
|
|
146
|
+
toBeValidEmail(): T;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
expect('alice@example.com').toBeValidEmail();
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Error and Rejection Testing
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
import { describe, it, expect } from 'vitest';
|
|
157
|
+
|
|
158
|
+
describe('parseConfig', () => {
|
|
159
|
+
it('throws on invalid input', () => {
|
|
160
|
+
expect(() => parseConfig('}{invalid')).toThrow();
|
|
161
|
+
expect(() => parseConfig('}{invalid')).toThrow(/invalid JSON/);
|
|
162
|
+
expect(() => parseConfig('}{invalid')).toThrow(SyntaxError);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('fetchUser', () => {
|
|
167
|
+
it('rejects for missing users', async () => {
|
|
168
|
+
await expect(fetchUser('missing')).rejects.toThrow('not found');
|
|
169
|
+
await expect(fetchUser('missing')).rejects.toBeInstanceOf(NotFoundError);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('resolves for valid users', async () => {
|
|
173
|
+
await expect(fetchUser('alice')).resolves.toMatchObject({ name: 'Alice' });
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Integration Tests
|
|
179
|
+
|
|
180
|
+
### File Layout
|
|
181
|
+
|
|
182
|
+
```text
|
|
183
|
+
my-pkg/
|
|
184
|
+
├── src/
|
|
185
|
+
│ ├── app.ts
|
|
186
|
+
│ └── app.test.ts # unit tests colocated
|
|
187
|
+
├── tests/ # integration tests
|
|
188
|
+
│ ├── api.test.ts
|
|
189
|
+
│ ├── helpers.ts
|
|
190
|
+
│ └── setup.ts # global setup/teardown
|
|
191
|
+
├── vitest.config.ts
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Global Setup and Teardown
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
// tests/setup.ts
|
|
198
|
+
import { afterAll, beforeAll } from 'vitest';
|
|
199
|
+
import { startTestServer, stopTestServer } from './helpers';
|
|
200
|
+
|
|
201
|
+
beforeAll(async () => {
|
|
202
|
+
await startTestServer();
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
afterAll(async () => {
|
|
206
|
+
await stopTestServer();
|
|
207
|
+
});
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
// vitest.config.ts
|
|
212
|
+
import { defineConfig } from 'vitest/config';
|
|
213
|
+
|
|
214
|
+
export default defineConfig({
|
|
215
|
+
test: {
|
|
216
|
+
setupFiles: ['./tests/setup.ts'],
|
|
217
|
+
include: ['src/**/*.test.ts', 'tests/**/*.test.ts'],
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Writing an Integration Test
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
// tests/api.test.ts
|
|
226
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
227
|
+
import { App, Config } from '../src/app';
|
|
228
|
+
|
|
229
|
+
describe('full request lifecycle', () => {
|
|
230
|
+
let app: App;
|
|
231
|
+
|
|
232
|
+
beforeEach(() => {
|
|
233
|
+
app = new App(Config.testDefault());
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('handles /health', async () => {
|
|
237
|
+
const res = await app.handleRequest('/health');
|
|
238
|
+
expect(res.status).toBe(200);
|
|
239
|
+
expect(await res.text()).toBe('OK');
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('returns 404 for unknown paths', async () => {
|
|
243
|
+
const res = await app.handleRequest('/nope');
|
|
244
|
+
expect(res.status).toBe(404);
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Async Tests and Fake Timers
|
|
250
|
+
|
|
251
|
+
### Native Async Tests
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
import { describe, it, expect } from 'vitest';
|
|
255
|
+
|
|
256
|
+
describe('async operations', () => {
|
|
257
|
+
it('resolves after fetching', async () => {
|
|
258
|
+
const data = await fetchData('/api');
|
|
259
|
+
expect(data.items).toHaveLength(3);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('races against a timeout', async () => {
|
|
263
|
+
// Abort the loser so slowOp stops running after the timeout wins
|
|
264
|
+
const controller = new AbortController();
|
|
265
|
+
let timeout: ReturnType<typeof setTimeout>;
|
|
266
|
+
try {
|
|
267
|
+
await expect(
|
|
268
|
+
Promise.race([
|
|
269
|
+
slowOp(controller.signal),
|
|
270
|
+
new Promise<never>((_, reject) => {
|
|
271
|
+
timeout = setTimeout(() => {
|
|
272
|
+
reject(new Error('timeout'));
|
|
273
|
+
controller.abort();
|
|
274
|
+
}, 100);
|
|
275
|
+
}),
|
|
276
|
+
])
|
|
277
|
+
).rejects.toThrow('timeout');
|
|
278
|
+
} finally {
|
|
279
|
+
clearTimeout(timeout!);
|
|
280
|
+
controller.abort();
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Fake Timers
|
|
287
|
+
|
|
288
|
+
```ts
|
|
289
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
290
|
+
|
|
291
|
+
describe('debounce', () => {
|
|
292
|
+
beforeEach(() => {
|
|
293
|
+
vi.useFakeTimers();
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
afterEach(() => {
|
|
297
|
+
vi.useRealTimers();
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('delays execution by the wait period', () => {
|
|
301
|
+
const cb = vi.fn();
|
|
302
|
+
const debounced = debounce(cb, 1000);
|
|
303
|
+
|
|
304
|
+
debounced();
|
|
305
|
+
expect(cb).not.toHaveBeenCalled();
|
|
306
|
+
|
|
307
|
+
vi.advanceTimersByTime(1000);
|
|
308
|
+
expect(cb).toHaveBeenCalledTimes(1);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('advances all pending timers', async () => {
|
|
312
|
+
const spy = vi.fn();
|
|
313
|
+
setTimeout(spy, 5000);
|
|
314
|
+
await vi.runAllTimersAsync();
|
|
315
|
+
expect(spy).toHaveBeenCalled();
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
```
|