How can I pass a parameter from the Gradle command...
# javascript
o
How can I pass a parameter from the Gradle command line to my JS tests (Node, browser, Wasm)? Example: Indicate if tests run on CI.
v
Afair there is not really a good way unless you generate some code from the input that you then use in the tests
o
The Kotlin/JS test infra has a way to transport the
--tests
filters.
v
Does it? Which test framework do you use?
kotest
for example cannot work with
--tests
on JS. It can work with
--tests
but only on class level for JVM, but not on test level. On JVM you can set a special system property to filter on class level and also on test level. On JVM and Native you can set a special environment variable to filter on class level and also on test level. On JS afair it does not have a way currently.
o
I'm using/developing TestBalloon testballoon, which uses the Kotlin/JS test infra (KGP) under the hood. This combination actually does support the test filters except for Wasm/JS/Browser and Wasm/WASI. So the KGP-based infra does transport the filters to Mocha in Node and browser (via Karma). The mechanism is there. I just want to transport some extra info beyond that.
e
The Kotlin/JS test infra has a way to transport the
--tests
filters.
Yes because as far as I recall that's passed in as a Mocha CLI argument.
👍 1
o
Exactly, good point! Do you have an idea how to extend that mechanism to transport extra parameters?
e
I don't think there is a way to be honest. There is a
KotlinJsTest.nodeJsArgs
input, but I've never used it.
But I feel like I don't have the overall picture here
o
Thanks, probably none of us has.
e
@Ilya Goncharov [JB] could probably offer some insight for this use case. Maybe write down a TL;DR so there is no need to look at all previous message.
thank you color 1
o
Still the original question remains. Answering that just for kotlin-test would suffice:
How can I pass a parameter from the Gradle command line to my JS tests (Node, browser, Wasm)? Example: Indicate if tests run on CI.
Seeing the latest work on KGP's JS test infra by @Adam Semenenko: Could you provide some guidance?
a
I don't know off the top of my head... iirc KGP should the current environment variables to the launched test process. Are you able to check to see if the
CI
environment variable is set in GitHub Actions?
thank you color 1
i
How can I pass a parameter from the Gradle command line to my JS tests (Node, browser, Wasm)? Example: Indicate if tests run on CI.
In
KotlinJsTest
you can provide environment variable to test process. But it will work only with Node.js tests (because tests are run exactly in the same node.js process). For browser I am not sure that it works like that, because tests are run in a browser, but environment variables are set for node.js process. For karma it is a bit tricky You can use something following in
karma.config.d/env.js
:
Copy code
config.client = config.client || {};
config.client.env = {
    IS_CI: true
}
In your runtime you don’t have environment variables in browser, so they are emulated in an object
Copy code
window.__karma__.config.client
thank you color 1
o
Are you able to check to see if the
CI
environment variable is set in GitHub Actions?
I'm actually using my own, but yes, I can see it. Using environment variables in Node.js is fine (I'm already doing that for the JVM and Native). I'll explore the Karma tip for the JS+Wasm/JS browser-based tests, that sounds very useful! I'll report back my results.
👍 1
The above Karma config works. Karma does not provide
window.__karma__.config.client
. But
window.__karma__.config.env['IS_CI']
works. kodee happy (Note that
env
appears only if at least one environment variable is present.)