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

[FR]: How to integrate custom test rules with configure #778

Open
antspy opened this issue Nov 21, 2024 · 0 comments
Open

[FR]: How to integrate custom test rules with configure #778

antspy opened this issue Nov 21, 2024 · 0 comments
Labels
enhancement New feature or request untriaged Requires traige

Comments

@antspy
Copy link

antspy commented Nov 21, 2024

What is the current behavior?

Hi,

I am using rules_ts with bazel, and by default it will create a ts_project rule for each .ts file found in a directory. The same applies to test files ending in .spec.ts..

This behavior can be modified to a limited extent using gazelle directives, but I don't see a way to get the behavior I want.

Describe the feature

I have a custom rule I want to use for tests. Nothing special, but it combines a ts_project for the test file with a vitest run from load("@npm//:vitest/package_json.bzl", vitest_bin = "bin").

So the idea is that I would be able to write

ts_test(
    name = 'mytest', 
    srcs = ['my.test.ts'],
    deps = [...], 
)

and that's all. I don't see how to get the behavior I want though.

  1. I cannot use a simple aspect:map_kind directive, because I want the substitution ts_project -> ts_test to happen only for test files, not for every filetype (other ts files should still use the ts_project rule).
  2. I looked into the Starlark Extension API (which seems really cool!) but I have found 2 issues:
    • The first is that the default ts_project behavior is not changes, so now I have both a ts_test rule and a ts_project rule, which is not what I want
    • The second is that I would have to write my own logic for ts_test dependencies. Here I just want to reuse the same logic from ts_project, just set in a different macro - but I don't want to rewrite the whole 'parse file import to add dependencies' logic.

So my question is - what can I do about this? I am very new to this space, so perhaps there's something obvious I am missing.
One thing that I think might work is to add a gazelle directive to specify which rule should be used for the .spec.ts targets, so that I could set it to my own rule using the aspect:map_kind directive and have everything else work as it is, without having to write a custom starlark plugin

Another idea would be exporting the whole logic as a starlark extension so one could change it without having to fork / recompile the CLI, but directly adding a new plugin.

Any help would be appreciated. Thanks a lot!

@antspy antspy added the enhancement New feature or request label Nov 21, 2024
@github-actions github-actions bot added the untriaged Requires traige label Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request untriaged Requires traige
Projects
None yet
Development

No branches or pull requests

1 participant