-
Notifications
You must be signed in to change notification settings - Fork 163
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
Make MockBuilder support build_extensions option. #685
Make MockBuilder support build_extensions option. #685
Conversation
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.
LGTM, but we need:
- Some documentation update to mention this feature, maybe even a FAQ entry;
- Maybe add
build_extensions
toexample/
project?
Corr: actually |
I agree so I've added them. Also, I found some edge cases with my implementation so I took care of them, I'll list them:
|
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.
Thanks!
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.
Could you please accept my changes and squash all commits into one?
We should be able to squash for the internal commit - generally it's easier to avoid force-pushing over shared history in a PR. |
This is useful to change the destination of the generated files. i.e: instead of having them on the same folder, you can specify a diferent folder for the mocks. Closes #545
Well didn't read that in time, sorry ^^ should I revert it then? |
No need - we can work with it either way. I was just hoping to inform on best practices since I frequently use shared PR history when reviewing in |
lib/src/builder.dart
Outdated
// While it can be acceptable that we get more than 2 allowedOutputs, | ||
// because it's the general one and the user defined one. Having |
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 don't understand this - user defined configuration for the .dart
input will override the default. I would expect that the allowed outputs should always have a single value.
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.
Oh I see, the examples are using a ^test
in the build extensions to substitute for a generate_for
. cc @jakemac53 - did we predict this would happen when we enhanced the build extension syntax?
Maybe it would be better to only do a full override and not do a merge.
@override
final Map<String, List<String>> buildExtensions;
MockBuilder({Map<String, List<String>>? buildExtensions})
: buildExtensions = buildExtensions ??
const {
'.dart': ['.mocks.dart'],
};
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.
Having the commit history would be helpful now ahah, but that was my first implementation, but there's a reason I changed it into a merge. I've discovered this when making the example for this config, example/build_extensions
, when doing the full override and only having an input pattern that only partially covers all .dart
files, the unmatched .dart
files wouldn't be processed, even though there's a generate_for
for those files. So my fix was to merge the user rules with the generic one ( .dart
=>.mocks.dart
)
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.
when doing the full override and only having an input pattern that only partially covers all
.dart
files, the unmatched.dart
files wouldn't be processed, even though there's agenerate_for
for those files.
I think not processing them is preferable to silently falling back on potentially unexpected behavior. I think it is reasonable to expect the overridden config to cover all inputs.
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 think not processing them is preferable to silently falling back on potentially unexpected behavior. I think it is reasonable to expect the overridden config to cover all inputs.
I can understand your perspective, in this case it's best to be consistent and not introduce any unexpected behavior, even though I think my approach is more ergonomic for developers. I'll try to change it then.
Co-authored-by: Nate Bosch <nbosch1@gmail.com>
Well, actually Copybara already does the squash, so it's mostly about getting a nicer CL description, as now it will list all the commits. We should probably just fix our Copybara config to copy the PR description into CL. |
We need to wait for the resolution of the discussion above. Also please convert the added double-quotes in the test file into single quotes: we have a lint complaining about that internally. |
The previous behaviour was that if the user adds a build_extension, the build would inject the generic build extension to cover all files. This was useful to simplify the build.yaml file at the cost of unexpected behaviour. To avoid potencial unexpected behaviour, if the user provides custom build_extensions we assume that the patterns cover all files and therefore we do not merge the generic build_extension.
Co-authored-by: Nate Bosch <nbosch1@gmail.com>
Now the formatter complains :) Could you please re-format it? |
Done. It seems that Dart 3.0 has a different formatting than Dart 2.19, a quick setup in github codespaces allowed me to format the files in the CI version 😅. |
Arghh, I see. Yes, I think we did change the formatter some time ago. Damn, then we should have just bumped the required SDK version I guess... I wonder if now formatter will start complaining internally, since we use more or less HEAD version... But let's wait. |
Nope, it worked fine, thanks! |
…ld-extensions PiperOrigin-RevId: 558114686
This PR changes the behaviour of the
buildMocks
factory, in order to support thebuild_extensions
option.This is useful in order to change the destination directory of the mocks, allowing for more customizability as in this article.
This change is a bit opinionated, because it forces the end-user to have a output filename pattern that ends with
.mocks.dart
in order to be consistent with the already generated files from mockito. It also forces the user, to have an input pattern ending with.dart
.Closes #545
Contribution guidelines:
dart format
.Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.