Skip to content

Add comprehensive test coverage and development documentation#49

Merged
YusukeHirao merged 9 commits intomainfrom
claude/add-cli-unit-tests-Y3fbo
Mar 6, 2026
Merged

Add comprehensive test coverage and development documentation#49
YusukeHirao merged 9 commits intomainfrom
claude/add-cli-unit-tests-Y3fbo

Conversation

@YusukeHirao
Copy link
Copy Markdown
Member

@YusukeHirao YusukeHirao commented Mar 5, 2026

Summary

This PR adds extensive unit test coverage for CLI commands and report generation modules, along with comprehensive development documentation. The changes establish testing patterns and contributor guidelines for the project.

closes: #13

Key Changes

Test Coverage

  • CLI command tests (crawl.spec.ts): Added tests for startCrawl and crawl functions covering:

    • URL list handling and file input (--list-file)
    • Output path specification (--output)
    • Archive file path return values
    • Error handling with process.exit() mocking
    • Diff mode (--diff) with two-file comparison
    • Resume functionality (--resume) with absolute/relative path resolution
    • Conflicting flag detection
  • Diff utility tests (diff.spec.ts): New test suite for archive comparison:

    • Active internal page URL extraction
    • Filtering of external pages, non-HTML assets, and error status codes
    • URL sorting and file output
    • Archive opening and closing
  • Plugin tests: Added comprehensive test suites for analysis plugins:

    • analyze-markuplint: HTML validation with violation reporting
    • analyze-textlint: Text linting with severity mapping
    • analyze-main-contents: Main content detection and element counting
    • analyze-search: Keyword and selector searching within scoped elements
  • Report generation tests: Added tests for Google Sheets data generation:

    • create-image-list: Image extraction from pages
    • create-discrepancies: Diff report generation
    • create-links: Link metadata collection
    • create-referrers-relational-table: Referrer relationship mapping
    • create-resources-relational-table: Resource dependency tracking
    • create-resources: Resource metadata collection
  • Event handling tests (event-assignments.spec.ts): Event listener and error handling patterns

  • Debug utilities tests (debug.spec.ts): Debug namespace configuration

Documentation

  • CONTRIBUTING.md (new): Comprehensive contributor guide including:

    • Environment setup (Node.js 24.x, Yarn 4.x via Corepack)
    • Development workflow and branch strategy
    • Commit message conventions (Conventional Commits)
    • PR requirements and CI expectations
    • Complete command reference
    • Testing guidelines (unit and E2E)
    • Release procedures (stable and pre-release)
    • Troubleshooting section
    • @d-zero/* package update procedures
  • README.md: Added development section with quick start and command reference

  • ARCHITECTURE.md: Updated package dependency diagram

CI/CD

  • ci.yml: Added E2E test job and push trigger for main branch

Implementation Details

  • Mock setup patterns use vi.mock() with named exports for better test isolation
  • Test helpers (e.g., createMockPage, createMockOrchestrator) encapsulate complex mock creation
  • Error handling tests use sentinel ExitError class to capture process.exit() calls
  • Archive and file I/O operations are fully mocked to avoid filesystem dependencies
  • Plugin tests validate both success paths and edge cases (missing elements, null values, etc.)
  • Event emission tests use controllable mock orchestrators with synchronous event dispatch

https://claude.ai/code/session_01BE2QTpMfUWRHtXa29QLVpe

claude added 5 commits March 5, 2026 13:00
crawl.spec.ts に crawl() 関数の未テスト分岐を追加:
- --diff モード(引数バリデーション、diff() 呼び出し)
- --resume モード(resumeCrawl 呼び出し、--output 同時指定エラー)
- --verbose / --silent フラグの処理
- --list-file / --list + args のマージ
- 単一 URL / 引数なしの分岐

新規テストファイル:
- crawl/event-assignments.spec.ts: イベント登録・silent モード・resolve/reject
- crawl/diff.spec.ts: アーカイブ比較・ページフィルタリング(外部/非ページ/ステータス)
- crawl/debug.spec.ts: log 名前空間・verbosely() の debug.enable 制御

Closes #13

https://claude.ai/code/session_01BE2QTpMfUWRHtXa29QLVpe
🔴 重大:
- startCrawl のエラーパス(errStack → process.exit(1))のテスト追加
- diff.spec.ts の Archive.open モックを archiveA/B 別に分離し独立検証

🟡 推奨:
- --resume テストで絶対パス/相対パスの path.resolve を具体値で検証
- event-assignments.spec.ts に afterEach(vi.restoreAllMocks) を追加
- diff.spec.ts に複数ページのソート+改行区切り結合テストを追加
- --list-file テストで readList に渡すパスを具体値で検証
- diff.spec.ts に Archive.open へのファイルパス引数検証テストを追加

https://claude.ai/code/session_01BE2QTpMfUWRHtXa29QLVpe
- CONTRIBUTING.md を新規作成(セットアップ手順、開発ワークフロー、リリース手順、
  @d-zero/* パッケージ更新手順、トラブルシューティング)
- CI に E2E テストジョブと main ブランチ push トリガーを追加
- README.md に開発者向けクイックスタートセクションを追加
- analyze-main-contents, analyze-markuplint, analyze-search, analyze-textlint の
  ユニットテストを追加
- report-google-sheets の create-discrepancies, create-resources, create-links,
  create-image-list, create-referrers-relational-table,
  create-resources-relational-table, add-to-summary のユニットテストを追加

https://claude.ai/code/session_01BE2QTpMfUWRHtXa29QLVpe
- README.md: 「開発」セクションを Crawl と Analyze の間から末尾に移動
- CONTRIBUTING.md: renovate.json の ignoreDeps に関する誤った記述を修正
  (config 系パッケージのみが対象で、ランタイム依存は自動更新対象)
- CONTRIBUTING.md: @d-zero/google-auth, @d-zero/google-sheets, @d-zero/readtext
  を対象パッケージ一覧に追加
- ARCHITECTURE.md: 依存グラフに report-google-sheets → @d-zero/google-sheets
  と @d-zero/dealer の関係を追加

https://claude.ai/code/session_01BE2QTpMfUWRHtXa29QLVpe
…entation

The test was checking for ExitError (via process.exit mock) but startCrawl
now throws CrawlAggregateError directly. Updated test to match.

https://claude.ai/code/session_01BE2QTpMfUWRHtXa29QLVpe
@YusukeHirao YusukeHirao force-pushed the claude/add-cli-unit-tests-Y3fbo branch from 0f25455 to 690da07 Compare March 5, 2026 13:09
claude added 4 commits March 6, 2026 01:01
…sults

- Increase global hookTimeout from 60s to 120s and testTimeout from 30s to 60s
- Remove per-file timeout overrides in failing E2E tests so global config applies
- Guard cleanup() and afterAll() against undefined results when beforeAll times out

https://claude.ai/code/session_01BE2QTpMfUWRHtXa29QLVpe
E2E tests require Puppeteer with --no-sandbox in CI, which the crawler
doesn't currently support. This is out of scope for issue #13 (CLI unit
tests). Revert E2E-related CI changes and restore original E2E test
timeouts.

https://claude.ai/code/session_01BE2QTpMfUWRHtXa29QLVpe
Issue #13 のスコープは CLI ユニットテストの追加。
スコープ外で追加された以下の変更を revert:
- report-google-sheets の spec ファイル7件
- ARCHITECTURE.md の依存グラフ修正
- README.md の開発者セクション追加

https://claude.ai/code/session_01BE2QTpMfUWRHtXa29QLVpe
- ARCHITECTURE.md: report-google-sheets が @d-zero/dealer と
  @d-zero/google-sheets に依存している実装を依存グラフに反映
- CONTRIBUTING.md: commitlint が Git フックに組み込まれていない
  実装に合わせて記述を修正

https://claude.ai/code/session_01BE2QTpMfUWRHtXa29QLVpe
@YusukeHirao YusukeHirao merged commit 06c54b1 into main Mar 6, 2026
3 checks passed
@YusukeHirao YusukeHirao deleted the claude/add-cli-unit-tests-Y3fbo branch March 6, 2026 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

テストカバレッジ: CLI コマンドのユニットテスト追加

2 participants