Kotlin JavaScript

I seem to need a good article describing the workflow for Kotlin as JavaScript. I can get an example compiling, but I'm hitting several problems: 1) There are no .map files generated with the javascript, and I'm unable to set breakpoints. 2) The Kotlin (JavaScript) debug configuration doesn't run the url in a webserver like JavaScript debug does 3) I have no idea how to set up or run unit tests in JavaScript.

I’m using IntelliJ 13.1.5

Hi, Nicholas!

> I seem to need a good article describing the workflow for Kotlin as JavaScript.
Right now I can recommend you only one – http://blog.jetbrains.com/kotlin/2013/10/writing-kotlin-in-the-browser/

  1. Try to turn on “Generate source maps” in Preferences -> Build, Execution, Deployment -> Compiler -> Kotlin Compiler.
  2. It’s obsolete please use “JavaScript Debug”
  3. We don’t have general way to run tests, but I believe that it’s achievable with most JS test frameworks.

If you have any further questions, please feel free to ask them.

Hi,  Thanks for the response.

I seem to need a good article describing the workflow for Kotlin as JavaScript. Right now I can recommend you only one -- http://blog.jetbrains.com/kotlin/2013/10/writing-kotlin-in-the-browser/

I've read that, and it was helpful but doesn't quite get me to a smooth workflow for JavaScript.

1. Try to turn on "Generate source maps" in Preferences -> Build, Execution, Deployment -> Compiler -> Kotlin Compiler.
Perfect, that got debugging working.
2. It's obsolete please use "JavaScript Debug"
What are you doing to compile then? Hitting Ctrl+F9 Then Shift+F9? There doesn't seem to be a way to tell the JavaScript Debug launch configuration to Make before running.
We don't have general way to run tests, but I believe that it's achievable with most JS test frameworks.
Awesome, I popped QUnit in and it works perfectly, thank you.  I was trying to get IntelliJ to run the tests in the IntelliJ test runner like you do in the JVM version, and they would try to run but just give me a java.lang.NoClassDefFoundError

Thanks,
-Nick

Nicholas,

In the pipeline are a few tasks for create tutorials/docs for JavaScript. It would be great to get your feedback on what areas you saw missing in the blog post so we make sure we cover. Is it only the points in the original question?

Thanks.

I've read that, and it was helpful but doesn't quite get me to a smooth workflow for JavaScript.
I can't tell ETA, but of course we going to provide more content about Kotlin JS. Anyway feel free to share your experience ;-)
What are you doing to compile then? Hitting Ctrl+F9 Then Shift+F9? There doesn't seem to be a way to tell the JavaScript Debug launch configuration to Make before running.
In IDEA 14 You can setup make with "Before launch" option(reladet issue IDEA-130914).

So possible solutions:

  • use IDEA 14
  • ask to backport this fix to IDEA 13
  • workaround:
      1. Create an artifact(“Other”) which depends to Kotlin JS module output.
      2. Add build your artifact to “Before launch” section.
      3. PROFIT! :slight_smile:
Awesome, I popped QUnit in and it works perfectly, thank you.
Could you please share your experience? (share your project or any simple project)
I was trying to get IntelliJ to run the tests in the IntelliJ test runner like you do in the JVM version, and they would try to run but just give me a java.lang.NoClassDefFoundError
Could you please provide more information(e.g. any project where we can reproduce it)? Then we can try to help You.

If have any further questions please feel free to ask them.

I'm planning on writing up a blog post when I have some time.

Could you please provide more information(e.g. any project where we can reproduce it)? Then we can try to help You.
I was meaning to say that I was trying to run kotlinjs unit tests the same way you do kotlinjvm unit tests. That is, by right clicking the test and clicking 'debug helloTest()'. This creates a junit launch configuration and that doesn't work with kotlinjs, only kotlinjvm. If I create an html page and run qunit with a jsdebug configuration, that works fine.

The ideal workflow would be how it is for Java, in Java I can be in one of my classes, press Ctrl+shift+T which prompts me to create a new test, or navigates me to an existing one, then I can right click anywhere in that test, either the method or the class itself, and that automatically creates a junit configuration. Then the test is run right in the idea console. Part of this works for KotlinJVM (ctrl+shift+T doesn’t work) and none of it works for KotlinJS.

In IDEA 14 You can setup make with "Before launch" option(reladet issue IDEA-130914).
The Kotlin plugin (0.9.223) doesn't work with 14.

Thanks for the clarification!

The Kotlin plugin (0.9.223) doesn't work with 14.

I believe that 0.9.206(for IDEA 14) not worse than 0.9.223(for IDEA 13). Also in IDEA 14 You can use nightly or bootstrap builds.

ah, yep, 0.9.206 works in 14.

I am writing my blog post and I have one more question.

When I create my unit tests, if I mark the tests folder as test sources root (and not sources root), they cannot see the classes in my sources root. The type hinting is there, but compiling I get an Unresolved reference error.

Marking it as sources root works, but then the test classes are compiled in with production classes.

-N

Right now JS backend doesn't support multimodule projects. Please file your case in our tracker.

Thanks!