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

Scala.js support for ScalaTest 3.0.0 #152

Merged
merged 23 commits into from Jan 7, 2017
Merged

Conversation

maqdev
Copy link
Contributor

@maqdev maqdev commented Sep 12, 2016

Hi!
This is an implementation targeting support Scala.js 0.6.12. I believe that supporting Scala.js will improve ScalaMock, considering the fact that ScalaTest 3.0.0 now supports Scala.js. At this point, I don't know any other mock library for Scala.js

I've created build.sbt file instead of existing Build.scala and split projects to JS/JVM with moving specific code to appropriate directories. It seems that shell prompt functionality is broken here. It would be great if someone could elaborate more on this.

Things that aren't supported when building for Scala.js are:

  • org.scalamock.scalatest.proxy.MockFactory support, due to reflection;
  • Java specific tests;

There are problems with ScalaTest's traits OneInstancePerTest, RandomTestOrder. It's required to override method newInstance which I did for all tests in ScalaMock.
Also I would like to mention that this pull-request includes #149 , kudos to @dvic

@cheeseng
Copy link
Collaborator

@maqdev This now seems to have conflicts, do you mind rebase it on the latest master? Thanks.

@maqdev
Copy link
Contributor Author

maqdev commented Sep 25, 2016

@cheeseng done. If you didn't notice I've previously updated this pull-request to cross-compile with scala 2.10 so there will be no need for a separate branch.

If you'll merge this I have a branch with reworked requests #56 and #144, so I could update working code without conflicts for these two requests as well.

It's good to see some life here :)

@cheeseng
Copy link
Collaborator

@maqdev Thanks, I'll take a look and see if I can merge them in today.

@chipsenkbeil
Copy link

@cheeseng, any reason this hasn't been merged in? Too much time needed to look over all of the changes?

@maqdev
Copy link
Contributor Author

maqdev commented Jan 6, 2017

Conflicts resolved again and updated to latest Scala.js: 0.6.14.

Scala.js now requires NodeJS to run tests, if you want to avoid NodeJS installation you have to use scalaJSUseRhino in Global := true

@barkhorn barkhorn removed the triage label Jan 7, 2017
@barkhorn barkhorn added this to the v3.5.0 milestone Jan 7, 2017
@barkhorn
Copy link
Collaborator

barkhorn commented Jan 7, 2017

Hi, this is a pretty big change, with a few structural changes. It'll take a while to review it.
Would be really helpful to know from a high level why files were renamed/moved.
Also, I'm a little confused about node.js - is this only required for the scala.js builds, or for the whole project, after the merge? What is the benefit?

@sjrd
Copy link

sjrd commented Jan 7, 2017

File moves: in a cross-project Scala/JVM + Scala.js, a lot of code can typically be shared between the two platforms. For most projects, virtually all of it can be shared, in fact. This one of the major selling points of Scala.js. However, sometimes, and in particular for "low-level" projects (e.g., a testing framework, or a mocking framework), you sometimes need platform-specific code. This why source files are categories under shared/, jvm/ and js/. Hence, a lot of source files typically move from src/... to shared/src/... when porting a project into a cross-project.

Node.js is the software used to run Scala.js code. Just like you need a JRE to run .class files, you need Node.js to run the .js files produced by Scala.js. This is only required to run/test Scala.js projects, obviously. It is not necessary to run/test Scala/JVM projects. Talking about "benefit" does not really make sense: without it you plain cannot test the Scala.js projects (the Rhino alternative is deprecated and will be removed in Scala.js 1.0.0; it had several severe issues, the least being extremely slow (orders of magnitude) compared to Node.js).

@maqdev
Copy link
Contributor Author

maqdev commented Jan 7, 2017

Hi,
on the high level, files where moved to achieve Scalia.js cross build. Files that have common code targeting both JS and JVM targets are moved into 'shared'. And JVM/JS specific files are moved into jvm/js folders correspondingly. You can read more about cross build structure here https://www.scala-js.org/doc/project/cross-build.html

Node.js is required only to run tests targeting JS platform. If you just run sbt compile, everything should work out of the box. If you run sbt test without nodejs, the tests targeting JS will fail.

@barkhorn
Copy link
Collaborator

barkhorn commented Jan 7, 2017

great, thanks.
By using Rhino, can we still run the JS tests successfully?
I think that would be preferrable, to keep the setup simpler for people who want to contribute to this project.

@xavier-fernandez
Copy link

@barkhorn Now Node.js is the default test runner for ScalaJS: https://www.scala-js.org/news/2016/10/17/announcing-scalajs-0.6.13/

@sjrd
Copy link

sjrd commented Jan 7, 2017

By using Rhino, can we still run the JS tests successfully?

With Scala.js 0.6.x, yes. Rhino won't be supported by Scala.js 1.0.0, however.

If you are concerned about a simpler setup, I suggest recommending in the Readme that people only run the JVM tests while they develop on their machines. The CI will catch JS-specific errors (which should be rare in practice). Only if one stumbles on a JS-specific error does one need to install Node.js to locally debug it.

@barkhorn barkhorn merged commit f95734d into paulbutcher:master Jan 7, 2017
@barkhorn
Copy link
Collaborator

barkhorn commented Jan 7, 2017

I will add the directive to use Rhino for now, until the documentation is updated to state something similar to @sjrd's comment.

@barkhorn
Copy link
Collaborator

barkhorn commented Jan 22, 2017

hi @maqdev @sjrd , version 3.5.0 has been published now.
Grateful if you could test this with some scala.js stuff and see how it works out.

@maqdev
Copy link
Contributor Author

maqdev commented Jan 24, 2017

Thanks @barkhorn! I'll check that

@maqdev
Copy link
Contributor Author

maqdev commented Feb 4, 2017

@barkhorn so far this is working fine for me, my library is compiling/testing fine under Scala 2.10-2.12 along with JS. Thank you!

@barkhorn
Copy link
Collaborator

barkhorn commented Feb 5, 2017

great news @maqdev . curious which library that is - is it on github?

@maqdev
Copy link
Contributor Author

maqdev commented Feb 5, 2017

Sure, it's Json serialization library for Scala/Scala.JS
https://github.com/hypertino/json-binders

@maqdev
Copy link
Contributor Author

maqdev commented Feb 5, 2017

Actually, ScalaMock isn't used in json-binders itself, it is used in binders https://github.com/hypertino/binders here :-)
This one isn't yet documented, it's a dependency for json-binders.

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

Successfully merging this pull request may close these issues.

None yet

6 participants