Conditional args to jest_test based on bazel command line config.

133 views
Skip to first unread message

James Lee

unread,
Oct 29, 2021, 4:05:47 AM10/29/21
to bazel-discuss
Hi all.
Based on other conversations, it may not be possible.
But still, I want to know whether there are other ways to achieve what I want to do.

So, as in jest_test macro sample, there is "--colors" arg passed to jest_test.
This jest cli produces log file with ANSI escape code to have color coding.
I do not want to pass "--colors", when "--config ci" is passed in command line to debugging easy in ci,
but want to pass "--colors" otherwise to see the color coding.

So, what will be the best approach given the jest_test is a macro and to pass some args to the macro conditionally based on bazel command line options?

Thank you.
- James

Philipp Schrader

unread,
Nov 3, 2021, 10:55:08 PM11/3/21
to bazel-discuss
Is the underlying "_jest_test" function a macro that inspects the arguments? If not, you should be able to use a select here.
Define a bool_flag() in a BUILD file and set it in your --config=ci config.
Then you'll want to patch the jest_test that you linked to look something like this:

templated_args = [
     "--no-cache",
     "--no-watchman",
     "--ci",

] + select({
    "//path/to:flag_config_setting": ["--colors"],
    "//conditions:default": [],
})
templated_args += ["--config", "$(rootpath %s)" % jest_config]

for src in srcs:

    templated_args += ["--runTestsByPath", "$(rootpath %s)" % src]

I.e. select() supports the + operator, but it doesn't support ".extend()".

Hope that makes sense.
Phil
Reply all
Reply to author
Forward
0 new messages