was someone able to write hierarchical mocha tests...
# javascript
r
was someone able to write hierarchical mocha tests which are displayed correctly in intellij's test view? something like:
Copy code
describe("foo") {
  context("bar") {
    it("should add numbers correctly") {
        assertEquals(4, 2 + 2)
    }
  }
}
external fun describe(name: String, block: () -> Unit)
external fun context(name: String, block: () -> Unit)
external fun it(name: String, block: () -> Unit)
Works in gradle but intellij does not pick it up correctly, i.e. not all tests are shown in the test view (it is picked up correctly in the build view though)
a
May I ask you to create an issue for it and attach a screenshot with a description about expected behavior?
e
intellij's test view
Wouldn't this require a specialized test reporter? Kotlin/JS has its own reporter for
kotlin.test
tests, but I don't think IJ will recognize you're running Mocha tests.
r
it recognises some but not all as it seems. I'll create a bug report/feature request later
e
How do you start them btw? Are you able to use the gutter icons? That would be surprising to be honest. Or are you running the outputted JS code directly, without passing by Kotlin?
r
I put it into a test and start it via gutter yes:
Copy code
@Test
fun foo() {
describe("foo") {
  context("bar") {
    it("should add numbers correctly") {
        assertEquals(4, 2 + 2)
    }
  }
}
}
e
Ahhhhh, that
@Test
annotated function was the missing piece of context
r
well.. I was surprised that it actually runs the tests but since it does it would be nice if they are displayed correctly 😄
e
Well, the compiled
foo
test case itself runs inside a Mocha
it
, so you're basically creating a test suite inside of a test case.
A better approach, and a possible Kotlin/JS feature to report in YouTrack, would be allowing nested test classes. You would then have your desired hierarchical result.
r
of course, I think this feature request is there (also for JVM) since kotlin.test started so I doubt this will happen soonish
c
You can actually do nested tests in kotlin-test on JS, that's how https://opensavvy.gitlab.io/groundwork/prepared/docs/ works
r
and this is picked up by intellij?
c
yes
however, you won't get the green arrow in the code to run a specific test, but it will report all of them in the result
r
that's not such a big deal I run into this bug anyway 😄
what do you see in the test view, several tests or just one?
@CLOVIS you might be interested in the approach I took in Atrium (an assertion library you could mention in the readme as well - shall I create a PR 🙂). I have an own @TestFactory annotation which maps to junits TestFactory on JVM and currently only to Test in JS. This way I can at least get the normal dynamic behaviour in JVM
c
Nevermind, even there I had to emulate nesting 😕
@robstoll yep you can definitely add a mention to mention another assertion library 🙂
so each test is actually a different test in the report, but they're not displayed as nested
r
that's already better than what I have currently
c
I think it's because kotlin-test doesn't support nesting deeper than 1 level
@Oliver.O is working on something to have true nesting on all platforms, but AFAIK it's not ready yet
r
saw it in the issue, you probably refer to https://github.com/OliverO2/kotlin-test-framework-prototype
c
yes
o
I hope to release it in the next couple of days, although the reporting problem still exists. Quoting from my docs on limitations:
The IDE does not report more than one level of suite nesting for tests using the Kotlin/JS infra (JS/Browser, JS/Node, Wasm/JS/Browser). While all suites appear, they are not properly nested, because the names of intermediate levels are cut out on their way from the test framework to the IDE.
r
One observation I made is that the Build-Tool window shows the intermediate levels (flattened though) at least for JS/Node
o
Yep. Same here, although the Build Output hierarchy will only show failed tests.
r
@Oliver.O is this a JS only problem or does the same occur for native platforms?
o
In my case, it is JS only. For native targets, I create test reports in IntelliJ‘s own ijLog format, which is compatible with nesting.