Skip to content

refactor(action): replace mock.module with dependency injection in tests#780

Merged
danadajian merged 13 commits into
mainfrom
refactor/remove-mock-module-action
May 27, 2026
Merged

refactor(action): replace mock.module with dependency injection in tests#780
danadajian merged 13 commits into
mainfrom
refactor/remove-mock-module-action

Conversation

@danadajian
Copy link
Copy Markdown
Contributor

Summary

  • Removes all mock.module calls from the action test suite, following the same pattern established for the backend in refactor(backend): replace mock.module with dependency injection in tests #778
  • Introduces a Deps interface with a makeDefaultDeps() factory, so production code runs unchanged while tests inject fakes directly
  • GitHub Actions inputs (getInput, getBooleanInput, getMultilineInput) are now driven via INPUT_* environment variables in tests, exercising the real @actions/core implementation
  • GitHub context fields (repo, runId, serverUrl) are driven via GITHUB_* environment variables; runAttempt is part of deps since the context singleton is frozen at import time
  • octokit.ts is deleted — octokit is now created lazily inside makeDefaultDeps() and injected wherever needed

Changes

  • New action/src/deps.ts — defines Deps and makeDefaultDeps()
  • run(), downloadBaseImages(), uploadAllImages(), uploadOriginalNewImages(), deleteHashImages(), uploadBaseImages() all accept a deps parameter threaded through from the top
  • createGithubComment() accepts an octokit parameter
  • disableAutoMerge() and getLatestVisualRegressionStatus() accept deps / octokit
  • resizeImageIfNeeded() accepts a jimp parameter
  • run.test.ts and comment.test.ts rewritten: zero mock.module calls, fake deps constructed inline and passed directly to tested functions

Test plan

  • cd action && bun test — all 69 tests pass
  • Verify no mock.module calls remain: grep -r "mock.module" action/test/ returns nothing

Generated with Claude Code

danadajian and others added 13 commits May 27, 2026 12:01
…ests

Refactor shared/s3 to a factory pattern and inject dependencies explicitly
into app/backend modules so tests can pass fakes without mutating the global
module registry via mock.module.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Rename deps.ts→dependencies.ts and Deps interface→Dependencies.
Expand deps.context from { runAttempt } to the full shape needed from
@actions/github (runId, serverUrl, repo, issue), so tests no longer
need GITHUB_* env vars — all context is supplied via deps.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…encies

Export defaultS3Operations from shared/s3 and use it as the deps.s3
default. The s3 type in Dependencies is now S3Operations rather than a
manual Pick of the methods the action uses.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@danadajian danadajian merged commit 596ace0 into main May 27, 2026
2 checks passed
@danadajian danadajian deleted the refactor/remove-mock-module-action branch May 27, 2026 18:38
@eg-oss-ci
Copy link
Copy Markdown

🎉 This PR is included in version 1.44.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants