-
Notifications
You must be signed in to change notification settings - Fork 161
Add tests for {node + jsdom, chrome, firefox, webworkers} #540
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,17 +21,11 @@ jobs: | |
- name: Setup Scala | ||
uses: japgolly/[email protected] | ||
|
||
- name: Build | ||
run: sbt -DCI=1 "++${{ matrix.scalaversion }}" package | ||
|
||
- name: Test generate documentation | ||
run: sbt -DCI=1 "++${{ matrix.scalaversion }}" doc | ||
|
||
- name: Build examples | ||
run: sbt -DCI=1 "++${{ matrix.scalaversion }}" example/compile | ||
- name: Build and test | ||
run: sbt -DCI=1 "++${{ matrix.scalaversion }}" test package doc | ||
|
||
- name: Validate formatting | ||
run: sbt -DCI=1 "++${{ matrix.scalaversion }}" scalafmtCheck | ||
run: sbt -DCI=1 "++${{ matrix.scalaversion }}" dom/scalafmtCheck | ||
|
||
- name: Validate api report | ||
if: matrix.scalaversion != '2.11.12' && matrix.scalaversion != '3.0.1' | ||
|
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
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
6 changes: 6 additions & 0 deletions
6
tests-chrome/src/test/scala/org/scalajs/dom/tests/chrome/ChromeTests.scala
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,6 @@ | ||
package org.scalajs.dom.tests.chrome | ||
|
||
import org.scalajs.dom.tests.shared._ | ||
import org.scalajs.dom.tests.webworker._ | ||
|
||
class ChromeTests extends SharedTests with WebWorkerTests |
6 changes: 6 additions & 0 deletions
6
tests-firefox/src/test/scala/org/scalajs/dom/tests/firefox/FirefoxTests.scala
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,6 @@ | ||
package org.scalajs.dom.tests.firefox | ||
|
||
import org.scalajs.dom.tests.shared._ | ||
import org.scalajs.dom.tests.webworker._ | ||
|
||
class FirefoxTests extends SharedTests with WebWorkerTests |
5 changes: 5 additions & 0 deletions
5
tests-node-jsdom/src/test/scala/org/scalajs/dom/tests/node/jsdom/NodeJsdomTests.scala
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,5 @@ | ||
package org.scalajs.dom.tests.node.jsdom | ||
|
||
import org.scalajs.dom.tests.shared._ | ||
|
||
class NodeJsdomTests extends SharedTests |
37 changes: 37 additions & 0 deletions
37
tests-shared/src/main/scala/org/scalajs/dom/tests/shared/AsyncTesting.scala
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,37 @@ | ||
package org.scalajs.dom.tests.shared | ||
|
||
import org.junit.Assert | ||
import scala.concurrent._ | ||
import scala.util._ | ||
import scala.scalajs.js.timers._ | ||
|
||
object AsyncTesting { | ||
|
||
type AsyncResult = Future[Try[Unit]] | ||
|
||
implicit def global: ExecutionContext = | ||
ExecutionContext.global | ||
|
||
def async(run: => Future[Any]): AsyncResult = { | ||
armanbilge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
val p = Promise[Try[Unit]]() | ||
val timeout = setTimeout(1200) { | ||
p.tryComplete(Failure(new RuntimeException("Test timed out."))) | ||
} | ||
setTimeout(1) { | ||
run.onComplete { ta => | ||
clearTimeout(timeout) | ||
p.complete(Success(ta.map(_ => ()))) | ||
} | ||
} | ||
p.future | ||
} | ||
|
||
implicit final class AsyncFutureOps[A](private val self: Future[A]) extends AnyVal { | ||
def tap(f: A => Any): Future[A] = | ||
self.map { a => f(a); a } | ||
|
||
def assertEquals(expect: A): Future[A] = | ||
tap(Assert.assertEquals(expect, _)) | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
tests-shared/src/main/scala/org/scalajs/dom/tests/shared/SharedTests.scala
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,31 @@ | ||
package org.scalajs.dom.tests.shared | ||
|
||
import java.util.UUID | ||
import org.junit.Test | ||
import org.scalajs.dom._ | ||
import org.scalajs.dom.raw._ | ||
|
||
trait SharedTests { | ||
import SharedTests._ | ||
|
||
// https://github.com/scala-js/scala-js-dom/issues/411 - console doesn't work in web workers | ||
@Test final def ConsoleLogTest(): Unit = | ||
console.log("Testing console.log") | ||
|
||
// https://github.com/scala-js/scala-js-dom/pull/432 - Avoid forcing evaluation of crypto | ||
@Test final def CryptoNonStrictTest(): Unit = { | ||
val _ = crypto.HashAlgorithm | ||
} | ||
|
||
@Test final def WindowIdbTest(): Unit = | ||
window.indexedDB.foreach(testIdb) | ||
|
||
} | ||
|
||
object SharedTests { | ||
def testIdb(idb: IDBFactory): Unit = { | ||
val open = idb.open(UUID.randomUUID().toString()) | ||
open.onerror = (e: Event) => sys.error("idb open failed: " + e) | ||
// TODO: Test properly in a different PR | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Client.scala
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,43 @@ | ||
package org.scalajs.dom.tests.webworker | ||
|
||
import org.scalajs.dom.raw._ | ||
import scala.concurrent._ | ||
import scala.scalajs.js | ||
import scala.util.Success | ||
|
||
final class Client(worker: Worker) { | ||
import Protocol._ | ||
|
||
private var preInit = new js.Array[Message] | ||
private var promises = new js.Array[Promise[String]] | ||
|
||
worker.onmessage = (e: MessageEvent) => { | ||
val m = e.data.asInstanceOf[Message] | ||
if (m._1 == ServerStarted) { | ||
preInit.foreach(worker.postMessage(_)) | ||
preInit = null | ||
} else | ||
promises(m._1).complete(Success(m._2)) | ||
} | ||
|
||
def send(cmd: WebWorkerCmd): Future[String] = { | ||
val id = promises.length | ||
val p = Promise[String]() | ||
val m = Message(id, cmd.id) | ||
promises.push(p) | ||
if (preInit eq null) | ||
worker.postMessage(m) | ||
else | ||
preInit.push(m) | ||
p.future | ||
} | ||
} | ||
|
||
object Client { | ||
|
||
def workerUrl: String = | ||
"file://" + BuildInfo.wwJsPath | ||
|
||
lazy val global = | ||
new Client(new Worker(workerUrl)) | ||
} |
14 changes: 14 additions & 0 deletions
14
tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Protocol.scala
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,14 @@ | ||
package org.scalajs.dom.tests.webworker | ||
|
||
import scala.scalajs.js | ||
|
||
object Protocol { | ||
|
||
type MsgId = Int | ||
type Message = js.Tuple2[MsgId, String] | ||
|
||
def Message(id: MsgId, data: String): Message = | ||
js.Tuple2(id, data) | ||
|
||
final val ServerStarted: MsgId = -1 | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.