Anyone have a guide on setting up junit tests (or ...
# javascript
f
Anyone have a guide on setting up junit tests (or equivalent for js files/projects?
a
fitzoh: Hi Andrew! I don't think there is such a guide at the moment. Currently the support for unit testing is limited to QUnit v1 (we are working on improving that). What you can do right now is add kotlin-test to your test module dependencies, and then write tests like so:
Copy code
import kotlin.test.*
import org.junit.Test

class SomeTest {

    @Test fun testTest() {
        // Your test here
    }

}
f
Are those tests runnable in intellij?
There’s a run button in the gutter but when I click it I get a
nothing here
and
gradle test
doesn’t seem to run that either
@anton.bannykh
a
No, those tests are not runnable in intellij at the moment.
f
so how do you run them?
a
One way to run them would be by setting up a node configuration and launching it with NodeJs plugin
Another would be using the https://github.com/srs/gradle-node-plugin and doing basically the same thing but via gradle
If you are using Gradle, here is an example of how to run Karma + QUnit: https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/js/build.gradle#L255
@fitzoh By the way, are you just testing the waters, or do you have a certain use-case?
f
just trying to test some business logic
no browser/js specific stuff
foundhttps://github.com/Kotlin/kotlin-frontend-plugin and I’ve got karma running, still can’t get an actual test to execute
a
Did you try the frontend-only example? Does it work on your machine?
@fitzoh Do you see the test results in the browser (http://localhost:9876/), but neither in the IDE nor in console?
@cy ^^^
f
Out at lunch... I went to the karma page and sae an error about require not being defined... I'll try cloning the front end example when I get back, was just copy pasting into the existing project at first
just got back, cloned the project and the frontend example looks good
copied the setup wholesale to the new project and that works too, not sure what I was missing
a
Cool 😃
g
For my particular project I did a partial port of kotlintest and launch my tests in a single page: http://data2viz.io/dist/tests.html
f
that’s pretty cool
Not being able to quote test names in js makes me sad though 😞
g
d
I had configured with jest to run entirely in node.