What is the recommended way to unit test suspendin...
# javascript
c
What is the recommended way to unit test suspending code in Kotlin/JS? I've been using https://stackoverflow.com/questions/47956444/how-to-unit-test-kotlin-js-code-with-coroutines for a while, but when there are many tests, some timeout. If I run tests by one, they never timeout, but if I run all of them, 2–3 tests timeout (different ones everytime). I'm starting to think returning a Promise means they all start at the same time, and some have to wait for the others to finish so there are enough threads? What can I do to solve this?
t
nothing changed since
r
The JS test runners have a global timeout that I think is 2 seconds by default. You can override for node by doing something like this in your gradle file
Copy code
js {
        nodejs {
            testTask {
                useMocha {
                    timeout = "120s"
                }
            }
        }
    }
and you can override for browser by adding a directory named
karma.config.d
, and placing within it a
.js
file with contents like this
Copy code
config.set({
  "client": {
    "mocha": {
      "timeout": 120000
    },
  },
  "browserDisconnectTimeout": 120000
});
There might be a way to do the browser one from gradle by now but there wasn't when I last dug into this stuff last spring
a
Thanks @russhwolf, Been looking for this for a while now
s
Is this still working?
r
As far as I know, yes. Stately uses it for stress tests.
s
Thank you so much @russhwolf. I checked Stately, and found my
karma.config.d
directory was in the wrong folder 🤦