-
Notifications
You must be signed in to change notification settings - Fork 147
Testing section #246
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
Merged
Merged
Testing section #246
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| --- | ||
| layout: doc | ||
| title: Testing | ||
| --- | ||
|
|
||
| In this section we will discuss how to test Scala.js code managed as [Full cross project](./cross-build.html). All names | ||
| for example subproject name such as `fooJVM` are taken from | ||
| [cross compile example](https://github.com/scala-js/scalajs-cross-compile-example). | ||
|
|
||
| ## Directory Structure | ||
|
|
||
| <project root> | ||
| +- jvm | ||
| | +- src/main/scala | ||
| | +- src/test/scala | ||
| +- js | ||
| | +- src/main/scala | ||
| | +- src/test/scala | ||
| +- shared | ||
| +- src/main/scala | ||
| +- src/test/scala | ||
|
|
||
| Similarly to `{shared|js|jvm}/src/main/scala` folders that contain your code, there can be also | ||
| `{shared|js|jvm}/src/test/scala` folders that would contain your tests. Tests that verify correctness of shared code | ||
| should go to `shared` test folder, while tests that check Scala JVM code or Scala.js code only should go to `jvm` or | ||
| `js` test folders respectively. Calling `sbt> fooJVM/test` will execute all tests residing in `shared` and `jvm` | ||
| folders, thus testing Scala JVM code. Calling `sbt> fooJS/test` will execute all tests residing in `shared` and `js` | ||
| folders, so Scala.js code is tested. In case of the full cross project, root project aggregates JVM and JS | ||
| parts, so when calling `sbt> test` will effectively run both `fooJVM/test` and `fooJS/test`. | ||
|
|
||
| ## Integration testing | ||
|
|
||
| Configuring a regular non-Scala.js sbt project to have `it:test` is a well described task, see | ||
| [documentation](http://www.scala-sbt.org/0.13/docs/Testing.html#Integration+Tests) for more details. | ||
| In a `CrossProject` it won't work out-of-the-box because of 2 reasons. First reason is that by default Scala JVM and | ||
| Scala.js `it` configurations won't be aware of `shared/src/it/scala` folder. Second is that Scala.js `it` configuration | ||
| by default does not contain `ScalaJSClassLoader` definition required for running Scala.js tests. To fix that you need to | ||
| add the following settings to the crossProject definition along with `IntegrationTest` settings: | ||
|
|
||
| {% highlight scala %} | ||
| lazy val cross = crossProject.in(file(".")). | ||
| ... | ||
| // adding the `it` configuration | ||
| configs(IntegrationTest). | ||
| // adding `it` tasks | ||
| settings(Defaults.itSettings:_*). | ||
| // add `shared` folder to `jvm` source directories | ||
| jvmSettings(unmanagedSourceDirectories in IntegrationTest ++= | ||
| CrossType.Full.sharedSrcDir(baseDirectory.value, "it").toSeq). | ||
| // add `shared` folder to `js` source directories | ||
| jsSettings(unmanagedSourceDirectories in IntegrationTest ++= | ||
| CrossType.Full.sharedSrcDir(baseDirectory.value, "it").toSeq). | ||
| // adding ScalaJSClassLoader to `js` configuration | ||
| jsSettings(inConfig(IntegrationTest)(ScalaJSPluginInternal.scalaJSTestSettings):_*) | ||
| {% endhighlight %} | ||
|
|
||
| Now you can put tests in `{shared|jvm|js}/src/it/scala` and they will run when you call `sbt> it:test`. Similarly to | ||
| `test`, there is also two iterations and they can be executed separately by explicitely stating jvm or js project name, | ||
| for example `sbt> fooJS/it:test`. | ||
|
|
||
| ## Testing frameworks | ||
|
|
||
| A list of testing frameworks compatible with Scala.js can be found [here](../../libraries/testing.html). | ||
|
|
||
| Note: Don't forget to mark a test framework SBT dependency as `test,it` if you have both unit and integration tests. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double blank line.