Skip to content

[FR]: Support adding testonly to a glob of folders/files with gazelle plugin #669

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

Open
Aghassi opened this issue Apr 18, 2024 · 6 comments
Labels
enhancement New feature or request need: discussion We have to do some design work in a meeting

Comments

@Aghassi
Copy link

Aghassi commented Apr 18, 2024

What is the current behavior?

You can't isolate out a folder and say "for this folder, please give me source targets and add testonly to make sure this folder doesn't get used in production". This means we can do build file generation on a folder like mocks but we have to manually add testonly.

Describe the feature

We should be able to pass a directive like #gazelle:treat_as_testonly **/mocks/** that will generate targets in any mocks folder found, but add testonly to the ts_project target. This prevents anything from mocks being used downstream and ending up in production.

@Aghassi Aghassi added the enhancement New feature or request label Apr 18, 2024
@jbedard jbedard added the need: discussion We have to do some design work in a meeting label Apr 25, 2025
@jbedard
Copy link
Member

jbedard commented Apr 25, 2025

Could this not be handled using js_test_files?

@Aghassi
Copy link
Author

Aghassi commented Apr 28, 2025

Could this not be handled using js_test_files?

In this case it would treat the mocks as test files I believe and generate a test target for them. I think this may be acceptable. But I would have to do it for every mocks folder right?

@jbedard
Copy link
Member

jbedard commented Apr 29, 2025

You can just configure it once so mocks have their own "test target". In your root BUILD you can just do:

# gazelle:js_test_files mocks **/mocks/**

Then anywhere that glob finds files you'll get the extra target:

ts_project(name = "mocks", testonly = True, srcs = [...])

@shanshanzhu
Copy link

Is there any documentation on what glob pattern we should use?

This glob cannot find the mocks folder in our code base and there is no logging to help debug

# gazelle:js_test_files mocks **/mocks/**

@alexeagle alexeagle added need: repro We don't know how to reproduce. Please create a minimal reproducible example. can close? Waiting on confirmation of resolution from reporter before closing and removed need: discussion We have to do some design work in a meeting labels May 20, 2025
@alexeagle
Copy link
Member

@shanshanzhu do you have a minimal repro of that problem? I think @jbedard is claiming that no work is needed here.

@shanshanzhu
Copy link

shanshanzhu commented May 20, 2025

#847

I tried to add a preliminary test cases to show the idea. But I'm not sure how to run the test.

Basically

  1. We expect a BUILD.bazel in every folder to contain ts_project with correct testOnly attribute.
  2. We expect adding this in the root BUILD.bazel will create the BUILD.bazel for every folder for us.
# gazelle:js_test_files mocks **/__mocks__/**
# gazelle:js_test_files **/*.test.ts

@alexeagle alexeagle added need: discussion We have to do some design work in a meeting and removed need: repro We don't know how to reproduce. Please create a minimal reproducible example. can close? Waiting on confirmation of resolution from reporter before closing labels May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request need: discussion We have to do some design work in a meeting
Projects
None yet
Development

No branches or pull requests

4 participants