-
Notifications
You must be signed in to change notification settings - Fork 77
[PM-23496] Add Sourcery library to automatically generate mocks #1724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…nerate mock files. Somehow they're not automatically included when building in the CI on the test run.
Great job, no security vulnerabilities found in this Pull Request |
…ow so it's available for Sourcery.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1724 +/- ##
==========================================
- Coverage 89.39% 85.76% -3.64%
==========================================
Files 798 996 +198
Lines 50600 60485 +9885
==========================================
+ Hits 45236 51875 +6639
- Misses 5364 8610 +3246 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran into an issue where I needed to bootstrap after the mock file was initially created. I think this is a case where we'll want to specify the generated file in the sources for Xcodegen and mark it as optional. It looks like you did this for the Generated
directory, but I'm not sure if that will apply for anything that's created in that directory after the fact. We may also need to specify it as an output file in the Sourcery build phase to get Xcode to correctly pick it up when it is initially generated. And we may want to add basedOnDependencyAnalysis: false
.
diff --git a/project-pm.yml b/project-pm.yml
index e92140496..af86a9abc 100644
--- a/project-pm.yml
+++ b/project-pm.yml
@@ -398,6 +398,9 @@ targets:
PATH="/opt/homebrew/bin:$PATH"
fi
mint run sourcery --config BitwardenShared/Sourcery/sourcery.yml
+ basedOnDependencyAnalysis: false
+ outputFiles:
+ - $(SRCROOT)/BitwardenShared/Sourcery/Generated/AutoMockable.generated.swift
BitwardenSharedTests:
type: bundle.unit-test
platform: iOS
@@ -418,6 +421,8 @@ targets:
- path: GlobalTestHelpers
- path: BitwardenShared/Sourcery/Generated
optional: true
+ - path: BitwardenShared/Sourcery/Generated/AutoMockable.generated.swift
+ optional: true
dependencies:
- target: Bitwarden
- target: BitwardenShared
Finally, in terms of CI I had to explicitly call Sourcery generation before bootstrapping in the
test.yml
workflow so the generated mocks are available to be used in the tests. Moreover, had to move installing Homebrew dependencies earlier soMint
is available for Sourcery.
If you make the changes above, I'd be curious if that also fixes CI without needing to make the additional workflow changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is showing up in the app's bundle. I think you can prevent this by removing it from a build phase (by specifying it's path and setting buildPhase: none
similar to swiftgen-pm.yml
) or by moving it to the root of the repo.
Lines 165 to 166 in 5ab1cf6
- path: swiftgen-pm.yml | |
buildPhase: none |
🎟️ Tracking
PM-23496
📔 Objective
Add Sourcery and configure it to be able to automatically generate mocks.
This library is powered by Stencil and we have one that acts as a template for the generated mocks: AutoMockable.stencil.
In terms of organization I've split what we use globally as the stencils/templates in
root -> Sourcery
and then specific targets configurations in each target. For the time being I've only configuredBitwardenShared
andAuthenticatorShared
which can be seen inBitwardenShared -> Sourcery -> sourcery.yml
or alike for BWA.Additionally, the generated mocks for
BitwardenShared
will be located inBitwardenShared -> Sourcery -> Generated
folder in a single file calledAutoMockable.generated.swift
.Usage
Add
// sourcery: AutoMockable
comment to any protocol so the mock is automatically generated.Contributing docs PR: bitwarden/contributing-docs#631
⏰ Reminders before review
🦮 Reviewer guidelines
:+1:
) or similar for great changes:memo:
) or ℹ️ (:information_source:
) for notes or general info:question:
) for questions:thinking:
) or 💭 (:thought_balloon:
) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion:art:
) for suggestions / improvements:x:
) or:warning:
) for more significant problems or concerns needing attention:seedling:
) or ♻️ (:recycle:
) for future improvements or indications of technical debt:pick:
) for minor or nitpick changes