Skip to content

test: dedupe shared test setup (console spies, program, channel fixture)#248

Merged
scottlovegrove merged 4 commits into
mainfrom
test/dedupe-shared-test-helpers
May 22, 2026
Merged

test: dedupe shared test setup (console spies, program, channel fixture)#248
scottlovegrove merged 4 commits into
mainfrom
test/dedupe-shared-test-helpers

Conversation

@scottlovegrove
Copy link
Copy Markdown
Collaborator

Summary

Audit + dedupe of repeated test scaffolding across the suite. Three focused commits, each its own concern:

  • captureConsole() (src/test-helpers/console.ts) — replaces ~209 inline vi.spyOn(console, ...).mockImplementation(() => {}) spies across 25 files and removes ~159 manual mockRestore() calls (auto-restores via onTestFinished).
  • createTestProgram(register) (src/test-helpers/program.ts) — collapses 24 identical local createProgram() definitions; call sites unchanged via a one-line wrapper. Drops now-unused commander imports.
  • createChannelFixture() (src/lib/__fixtures__/channels.ts) — replaces 4 byte-identical sampleChannel literals (channel add/remove/set/members), matching the existing accounts-fixture pattern.

Net: −367 lines (29 files), no behavior change.

Deliberately not done

  • makeTwistClientMock — the per-command client mocks are each a different SDK subset; a generic helper would be a no-op {...overrides} wrapper (premature abstraction).
  • Shared apiMocks/refsMocks factories — real dup exists in the 4 channel-membership files, but vi.hoisted runs before imports so a shared factory can't be imported into it (TDZ); the __mocks__/ alternative would force all 16 api-mocking files onto one global mock surface.
  • Single-use entity factories (thread/message/comment/conversation) left in place — relocating them wouldn't reduce duplication.

Test plan

  • npm run type-check clean
  • npm run lint:check clean
  • npm test — 677 passed (43 files)

🤖 Generated with Claude Code

scottlovegrove and others added 3 commits May 22, 2026 22:36
Replace ~209 inline `vi.spyOn(console, ...).mockImplementation(() => {})`
spies across 25 test files with a shared `captureConsole()` helper that
silences output and auto-restores via onTestFinished, removing the
redundant manual mockRestore() calls.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace 24 identical local `createProgram()` definitions with a shared
`createTestProgram(register)` helper; each test keeps a one-line wrapper
so call sites are unchanged. Drops the now-unused commander imports.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace four byte-identical `sampleChannel` literals (add/remove/set/
members) with a shared `createChannelFixture()` factory in __fixtures__,
matching the existing accounts fixture pattern.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@scottlovegrove scottlovegrove self-assigned this May 22, 2026
@doistbot doistbot requested a review from gnapse May 22, 2026 21:48
Copy link
Copy Markdown
Member

@doistbot doistbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR effectively cleans up the test suite by deduplicating console spies, program initialization, and channel fixtures into shared helpers. This provides a great boost to maintainability by dropping nearly 400 lines of boilerplate while thoughtfully avoiding premature abstractions. A few minor adjustments are needed to ensure the new test helpers directory is properly excluded from the published build output and to strictly type the channel fixture overrides so we maintain the safety of the original inline literals.

Share FeedbackReview Logs

Comment thread src/test-helpers/console.ts
Comment thread src/commands/channel/add.test.ts
Add src/test-helpers to tsconfig.build.json excludes so the published
dist/ no longer pulls in vitest-importing helpers. Type
createChannelFixture against the SDK Channel shape (Partial<Channel>
overrides, Channel return) to keep the type safety of the inline literals.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@scottlovegrove scottlovegrove merged commit 5b59d79 into main May 22, 2026
5 checks passed
@scottlovegrove scottlovegrove deleted the test/dedupe-shared-test-helpers branch May 22, 2026 22:00
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.

3 participants