is there any way to disable the behavior that test...
# javascript
j
is there any way to disable the behavior that tests run when the test file/module is loaded?
e
Not that I am aware of. But then how would you start them?
j
By invoking an exported function
The way everything else in the ecosystem works
I think I can just fake it by exposing my own
describe
function that no-ops. Not great, but good enough.
e
> By invoking an exported function That's what I wanted to do too. I was experimenting with using K/JS for VS Code extensions development, and needed to export a function like
Copy code
function run(): Promise<void>
But couldn't find a way to not execute the test cases when the file got loaded
Ended up writing my own test suite generation with KSP. A lot of work for a mediocre result
I think I can just fake it by exposing my own
describe
function that no-ops.
I'd have to see an example to understand this part
j
you're just emulating what mocha or jasmine or any of the JS testing frameworks expose
and then not actually running anything
e
But you'll still have those tests running once the file gets loaded tho.
j
the suite would be loaded, but that's just a function
you don't actually have to execute it
it's only when there's no testing framework present does the default implementation in kotlin.test run things immediately
e
it's only when there's no testing framework present does the default implementation in kotlin.test run things immediately
Ahhh I wasn't aware of this. So basically if there is e.g. Mocha, it will not run the test cases on file load, but it'll wait for Mocha to call them?
I did read the test sources but I thought the test cases were run immediately
j
they are still loaded into the test framework synchronously when the module is loaded
but as to whether the tests themselves are run or not is up to the framework
e
So I see in the JS source that there is an "adapter"
Copy code
function suite(name, ignored, suiteFn) {
  _init_properties_TestApi_kt__c5696e();
  adapter().suite(name, ignored, suiteFn);
}
I suppose that it's what you're talking about, it detects the test framework and calls the appropriate function
j
yeah it looks for a
QUnit
object or the
describe
+
it
top-level functions
e
So what you want to do is just compile the test sources, exporting your
xyz
function, and you'll call that
xyz
function via your own tool
j
yep
e
But from the
xyz
function, how do you actually run the test cases? That's the bit I'm missing now
I'm still talking about test cases you define via the
@Test
annotation
j
for those you'd have to capture a list of them as invoked by the
describe
function for later invocation
that's not what i'm actually doing though, i just want to prevent the default execution
e
Looks like there is no way to inject your own
FrameworkAdapter
, that would have been the easy route probably
At least for what I can see. Maybe I missed it.