After the callback hell there is the js testing fr...
# javascript
g
After the callback hell there is the js testing frameworks hell: how to find the correct configuration that works. testing coroutines works with mocha but not qunit. testing browser code needs karma. testing multi-module code needs a testing framework compatible with requirejs or commonjs or to pack modules before tests. packing modules is long karma + commonjs is fast but not working on windows. karma + browserify + qunit is slower but works also on windows (but doesn’t work with coroutines). #jsfatigue 😪
z
so looks like karma + mocha + browserify is the answer
f
karma + mocha + webpack works for us
g
with coroutines asynch testing?
f
testing browser code needs karma
Actually, jsdom is often enough for unit tests
g
It’s really the js testing frameworks hell 😅
☝️ 2
This is the test code :
Copy code
@Test
    fun loadBigJson() = promise {
        val request = window.fetch(Request("base/build/classes/kotlin/test/ny.json"))
        val response = request.await()
        val text = response.text().await()
        val time = Date.now()
        val featureCollection = text.toGeoJson().asFeatureCollection()
        val multi = featureCollection.multipolygons
        val polygons = multi.flatMap { it.coordinates.toList() }
        assertEquals(108, polygons.size)
    }
I need browser API and not just DOM.
z
with coroutines asynch testing?
Well as far as I know
mocha
supports
async/await
out of the box, so that’s the only question of setting all it up together. That’s the challenge, but it sounds achievable
f
Basically there are two ways to write async tests in mocha: async functions (which are in fact any functions returning promise,
async/await
is just a sugar for those), and
done
callback
👍 1