Skip to content
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

Consider configuring the builder to run on test/ directory only by default #502

Closed
evanweible-wf opened this issue Jan 18, 2022 · 2 comments
Labels
P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@evanweible-wf
Copy link

evanweible-wf commented Jan 18, 2022

More details in dart-lang/build#3238, but currently the mockito builder in this package specifies .dart as the build extension for its inputs and doesn't configure the generate_for option at all. As a result, the builder runs on every dart file in a project, which is significant because the builder is implemented in such a way that it fully resolves every Dart library. For large projects, this is an extremely expensive default behavior, especially considering that this builder was added to this library in a minor release and is auto-applied to any project that already depended on mockito and used build_runner.

Given the nature of this library, it might make more sense for the default configuration to be that it only runs on files in the test/ directory. Running the builder on files in other directories would still be possible, it would just require explicit configuration (which seems justifiable).

A change like this would be breaking, but I think it's worth considering.

@srawlins srawlins added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug labels Jan 18, 2022
@natebosch
Copy link
Member

+1 on adding a default generate_for: test/** since thats what most folks will want.

Slight possibility this would break someone, but they could override generate_for to get unstuck.

@cc-nogueira
Copy link

+1 on this!

My flutter project has an examples folder and mockito builder was trying to generate mocks in all examples test folders.
This generation spent unnecessary time and gave false errors for types not found.

I have added the following build.yaml to my flutter root (first time I customize flutter builders). Seems to work.

targets:
  $default:
    builders:
      mockito|mockBuilder:
        enabled: true
        generate_for: ["test/**"]

natebosch added a commit that referenced this issue Mar 23, 2023
Closes #502

Most users only need mocks for test files. The mockito generator performs
resolution, so running the generator across all files in `lib/` that are
unlikley to use mocks is not worthwhile.

Users who do want mocks generated for files in `lib/` will need to manually add
a `generate_for` configuration.

PiperOrigin-RevId: 512017662
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants