Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScalaJS testing #7

Closed
zstone1 opened this issue Jun 1, 2022 · 5 comments
Closed

ScalaJS testing #7

zstone1 opened this issue Jun 1, 2022 · 5 comments

Comments

@zstone1
Copy link

zstone1 commented Jun 1, 2022

Firstly, you saved me a lot of work figuring this out. So thank you.

I'm cross building with this plugin, which works reasonably well, but I don't yet have tests for the JS artifacts. Do you have a plan for running tests? Ideally, I'd just want a task like 'testJS', which runs my scalatest library in node. Is this something this plugin would handle? I currently use gradle-scalatest for JVM tests.

@dubinsky
Copy link
Owner

dubinsky commented Jun 1, 2022

@zstone1

Firstly, you saved me a lot of work figuring this out. So thank you.

Thank you for your kind words!

I'm cross building with this plugin, which works reasonably well,

Any suggestions for improving the plugin are more than welcome :)

I am curious about you cross-building setup.
If I understand correctly, in the sbt world one needs two plugins to set up cross-building: "sbt-scalajs" and "sbt-scalajs-crossproject".
I want to enhance this plugin to support cross-builds, but since this is my first exposure to ScalaJS, I am not sure what are the accepted conventions for such a setup.

but I don't yet have tests for the JS artifacts. Do you have a plan for running tests?
Ideally, I'd just want a task like 'testJS', which runs my scalatest library in node.
Is this something this plugin would handle?
I currently use gradle-scalatest for JVM tests.

By gradle-scalates, do you mean the 'com.github.maiflai.scalatest' Gradle plugin? That is what I use...

I do want to enhance this plugin to handle Node-run tests for ScalaJS (this is what this issue is about),
but I wouldn't call that wish a plan quite yet: still trying to understand what it'd take to replicate the setup
from https://www.scala-js.org/doc/tutorial/basic/ Step 6: Testing and https://www.scala-js.org/doc/project/testing.html.
It seems that support for cross-building might have to come before the support for testing.

Again, any clues and pointers are appreciated.

@zstone1
Copy link
Author

zstone1 commented Jun 2, 2022

Regarding cross-building, I should clarify that I'm writing a library, not an executable. And I only care about Scala 3 on JVM and ScalaJS. I'm intending on calling it from an separate JVM server application, and an separate JS browser application. I really don't want to duplicate code between the applications, as consistency across the environments is critical for me. Almost all my code is pure scala in a shared/src folder. I have a java/src/MyJavaInterface.java file which calls into the shared and presents a Java-y interface. I also have a js/src/MyJSInterface.scala with a Scala object that calls into shared, and is has a @JSTopLevelExport annotation.

Currently, the ./gradlew jar creates a real jar file, and ./fullLinkJS creates a real JS module. I then bundle that JS module with a package.json and a d.ts file, and it works as an NPM package. I have tested it, and it seems to work great (although there is still a few more opportunities for things to go wrong, I'm reasonably hopeful). This is my first exposure to ScalaJS as well, so I'm equally unsure of idioms.

One minor complaint is that I don't really want the .classes file for MyInterface.scala. But I need to configure my source set to have all three folders. It doesn't seem to hurt anyone, and I could always clean it up in my ./gradlew jar task if I really cared.

By gradle-scalates, do you mean the 'com.github.maiflai.scalatest' Gradle plugin? That is what I use...

Yes. But I don't know much about it's guts. Because so much of my code is in shared, I can live with just JVM tests for some time, and I haven't looked into it much. So I have little to offer regarding hints. Sadly. I will post again here when I get a chance to do more homework.

@dubinsky
Copy link
Owner

dubinsky commented Jun 2, 2022

I only care about Scala 3 on JVM and ScalaJS.

So do I ;)

I really don't want to duplicate code between the applications, as consistency across the environments is critical for me.

Me too.

Almost all my code is pure scala in a shared/src folder. I have a java/src/ ... I also have a js/src ...
This is my first exposure to ScalaJS as well, so I'm equally unsure of idioms.

I think that the sbt approach (which should probably be followed as somewhat of a standard) is also to have three directories with 'src' under them: 'shared', 'jvm' and 'js'.... Only with Gradle, each of those directories probably will end up as subproject, so that sourcesets can be configured properly (shared+jvm and shared+js).

Plugin should configure the sourcesets, compilation, linking, testing and packaging correctly, and I hope eventually it will.

By gradle-scalates, do you mean the 'com.github.maiflai.scalatest' Gradle plugin? That is what I use...

Yes. But I don't know much about it's guts.

Neither do I... ScalaTest itself is available for SclalaJS, but I suspect that Node-based tests will need to be run not by gradle-scalatest...

I will post again here when I get a chance to do more homework.

Thank you!

(I won't be able to work on this for the next seven days.)

@dubinsky
Copy link
Owner

@zstone1 I am working on the test functionality for the plugin; as expected, Gradle ScalaTest plugin is not going to help: ScalaJS tests run on Node; I am trying to integrate test adapters from ScalaJS with Gradle...

@dubinsky
Copy link
Owner

Basic support is in version 0.0.2 of the plugin.
Further enhancements are tracked under #8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants