Skip to content

test: write unit tests for lib/github.cjs (#134)#147

Merged
snipcodeit merged 1 commit intomainfrom
issue/134-write-unit-tests-for-lib-github-cjs
Mar 2, 2026
Merged

test: write unit tests for lib/github.cjs (#134)#147
snipcodeit merged 1 commit intomainfrom
issue/134-write-unit-tests-for-lib-github-cjs

Conversation

@snipcodeit
Copy link
Owner

Summary

  • Adds test/github.test.cjs with 46 test cases covering all 10 exported functions in lib/github.cjs
  • Uses the module cache invalidation mock pattern (delete require.cache + mock.method(childProcess, 'execSync', ...)) so no real gh CLI calls are made during test runs
  • Every function has at least one error-path test confirming that execSync throws propagate correctly

Closes #134

Milestone Context

  • Milestone: v3.5 — Foundation Hardening
  • Phase: 32 — Test Coverage
  • Issue: 1 of 9 in milestone

Changes

  • test/github.test.cjs (new, 684 lines) — full unit test suite for lib/github.cjs
    • getRepo — 2 tests: correct command construction, error propagation
    • getIssue — 4 tests: parsed return value, command shape (number + fields), string arg, error path
    • listIssues — 8 tests: no-filter base case, each filter flag (--label, --milestone, --assignee, --state), assignee: "all" exclusion, error path
    • getMilestone — 3 tests: parsed return value, two-call sequence (getRepo then gh api), error path
    • getRateLimit — 4 tests: field values, command, no extra keys, error path
    • closeMilestone — 3 tests: parsed return value, PATCH command with state=closed, error path
    • createRelease — 7 tests: raw string return, base command, --notes, --draft, --prerelease, false opts omission, error path
    • createProject — 3 tests: {number, url} extraction, command shape, error path
    • addItemToProject — 3 tests: raw string return, command shape, error path
    • postMilestoneStartAnnouncement — 9 tests: Discussion success, no-Announcements-category fallback, GraphQL-throws fallback, both-fail {posted:false}, no-repo no-op, boardUrl in body, "not configured" when absent, issue rows in body, em-dash for unassigned

Test Plan

  • Checkout branch, run npm test
  • Confirm output shows tests 50 / pass 50 / fail 0
  • Confirm no network or gh CLI invocations occur (all mocked)

Add comprehensive unit tests for all 10 exported functions in
lib/github.cjs using node:test built-in runner with execSync mocked
via module cache invalidation — no real gh CLI calls made.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@snipcodeit
Copy link
Owner Author

We need to add a deployment ci cd run this to ensure nothing breaks.

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.

Write unit tests for lib/github.cjs

1 participant