Skip to content

Import the JS Envs projects from the Scala.js core repository. #1

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 150 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
5cef245
Fix scala-js/scala-js#446: Make setting out of jsEnv (and sanitize st…
gzm0 Apr 2, 2014
f335399
Fix scala-js/scala-js#441: Add Node.js environment
gzm0 Apr 3, 2014
59f457a
Fix scala-js/scala-js#500: Avoid removal of duplicate percentage sign…
gzm0 Apr 22, 2014
63bebcf
Fix scala-js/scala-js#561: Make hacked Node.js console accept non-Str…
gzm0 Apr 29, 2014
1423cf6
Add JS dependency tracking via manifests.
gzm0 Apr 30, 2014
9629ea0
Add full support for projects requiring DOM
gzm0 Apr 9, 2014
8c71267
Send printlns to the console, not the logger.
sjrd May 2, 2014
8f4a06e
Merge pull request scala-js/scala-js#587 from sjrd/fix-console-log-ou…
gzm0 May 2, 2014
89f4229
Fix scala-js/scala-js#610: Restructure classpaths for clean linking API
gzm0 May 16, 2014
037d57a
Fix scala-js/scala-js#688: Remove return value of JSEnv#runJS.
gzm0 May 27, 2014
65f0a3f
Fix scala-js/scala-js#740: Allow to run stuff with names that are not…
gzm0 Jun 19, 2014
a962a32
Fix scala-js/scala-js#799: Make PhantomJS runner fail if JS code fails
gzm0 Jul 3, 2014
3e26c6c
Fix scala-js/scala-js#865: Inherit existing shell environment in exte…
gzm0 Jul 24, 2014
9c11baf
Fix scala-js/scala-js#706: Add mechanism to support CommonJS style re…
gzm0 Jul 27, 2014
577a49f
Cross-build Scala.js tools
gzm0 Jul 11, 2014
2d9d124
Implement System.exit() through environment setting (scala-js/scala-j…
gzm0 Aug 22, 2014
b0ab774
Fix scala-js/scala-js#1016: Respect NODE_PATH from the environment.
gzm0 Sep 11, 2014
350652e
Fix scala-js/scala-js#1054: Automatically enable source-map-support i…
gzm0 Sep 18, 2014
3dbe808
Remove deprecated members
gzm0 Sep 19, 2014
7f012bb
Fix scala-js/scala-js#1163: Remove packager and non-direct full optim…
gzm0 Oct 14, 2014
d023c68
Refactor JSEnv to support async running
gzm0 Oct 18, 2014
a96ecd6
Remove JSEnv constructor-blow up. Use default args
gzm0 Nov 3, 2014
c98cb19
Add ComJSEnv and make RhinoJSEnv a ComJSEnv
gzm0 Nov 4, 2014
6abedd5
Make NodeJSEnv a ComJSEnv
gzm0 Nov 4, 2014
7744c34
Get rid of unnamed tuple in CompleteClasspath
gzm0 Nov 6, 2014
509d7a0
Fix scala-js/scala-js#1240: Add stop() to AsyncJSEnv
gzm0 Nov 7, 2014
13946a5
Merge pull request scala-js/scala-js#1246 from gzm0/async-stop
sjrd Nov 7, 2014
b2f790a
Fix scala-js/scala-js#1239: Don't assume in ExtJSEnv that VM supports…
gzm0 Nov 10, 2014
a797c41
Fix scala-js/scala-js#1241: Add Future based API to AsyncJSEnv
gzm0 Nov 11, 2014
8dada1f
Fix scala-js/scala-js#1266: Proper connection closing on Node.js ComJ…
gzm0 Nov 14, 2014
478bba9
Increase max supported message size for NodeJSEnv
gzm0 Nov 18, 2014
3064e5d
Additional tests for ComJSEnvs
gzm0 Nov 25, 2014
6203577
Fix scala-js/scala-js#1304: Fragment messages to limit total size to …
gzm0 Nov 25, 2014
5573bbe
Centralize overriding of stop in ComJSEnv
gzm0 Nov 26, 2014
1fba71f
Improve information in thrown ComClosedExceptions
gzm0 Nov 27, 2014
ee10cd4
Fix scala-js/scala-js#1073: New test framework interface (aligned wit…
gzm0 Nov 20, 2014
8688060
Decouple VirtualFileMaterializer from sbt.IO
gzm0 Nov 27, 2014
a4fe854
Remove sbtplugin.JSUtils
gzm0 Nov 27, 2014
150ee02
Fix scala-js/scala-js#1287: Reorganize package names and artifacts
gzm0 Nov 27, 2014
2b3dee7
Fix scala-js/scala-js#1325: Repeatedly decode incoming Node.js Com me…
gzm0 Nov 28, 2014
3a11645
Get rid of ugly isAlive hack
gzm0 Nov 28, 2014
5eec47d
Fix scala-js/scala-js#1328: Handle socket errors in Node.js com
gzm0 Nov 28, 2014
de318a2
Add a JSEnv test for future completion when stopping (closes scala-js…
gzm0 Nov 30, 2014
7078273
Restructure AsyncJSRunner to be Future based
gzm0 Nov 30, 2014
a75473b
Fix scala-js/scala-js#1315: Add timeout to AsyncJSRunner.await and us…
gzm0 Nov 30, 2014
c2706f5
Fix scala-js/scala-js#1343: Add a RetryingComJSEnv and use it for CI
gzm0 Dec 1, 2014
4f976a1
Fix scala-js/scala-js#1059: Add a (basic) way to turn off source mapping
gzm0 Dec 4, 2014
8340efb
Only fail JSEnv test if log is bad
gzm0 Dec 3, 2014
a2363a6
Fix scala-js/scala-js#1321: Implement setTimeout (et al.) in Rhino
gzm0 Dec 2, 2014
da14e87
Fix scala-js/scala-js#1377: Remove flakyness of JSEnv test
gzm0 Dec 11, 2014
a9c4fe9
Add source map support detection to NodeJSEnv
gzm0 Dec 12, 2014
a386982
Automatically set correct tags for tests
gzm0 Dec 11, 2014
87cab2a
Fix scala-js/scala-js#1377 (again): Stabilize JSEnv timeout tests
gzm0 Dec 15, 2014
ada787c
Merge pull request scala-js/scala-js#1380 from gzm0/auto-tags
sjrd Dec 16, 2014
f31e1b7
Add support for timeouts in ComJSRunner.receive().
sjrd Jan 20, 2015
c5f19e5
Strengthen the guarantees of AsyncJSRunner.stop().
sjrd Jan 21, 2015
84f63eb
Fix scala-js/scala-js#1452: PhantomJS sometimes doesn't shut down pro…
sjrd Jan 20, 2015
50b5b67
Fix scala-js/scala-js#1482: Node.js throws if JVM closes connection t…
gzm0 Feb 9, 2015
15feede
Fix scala-js/scala-js#1536: NodeJSEnv is unable to send characters la…
gzm0 Mar 16, 2015
4606eec
Increase Node.js' connection timeout to 5 s.
sjrd Mar 16, 2015
a82b8c3
Move NodeJSEnv.acceptTimeout as a protected val.
sjrd Mar 16, 2015
0141889
Add a customInitFiles() hook in ExternalJSEnv.
sjrd May 1, 2015
593e07b
Fix a bunch of style issues discovered by Scalastyle.
sjrd May 29, 2015
27a842c
Add Scalastyle with a basic configuration.
sjrd May 29, 2015
e215281
Fix scala-js/scala-js#1917: Add -Xfatal-warnings for ScalaDoc generation
gzm0 Oct 23, 2015
0c85ccd
Fix scala-js/scala-js#1990: Do not duplicate % for 1-arg console.log …
sjrd Oct 30, 2015
c1e3714
Factor basic JSEnv tests in trait
gzm0 Nov 27, 2015
b4f5755
Fix scala-js/scala-js#2053: Always use UTF8 in PhantomJSEnv
gzm0 Nov 27, 2015
c3f97a3
Log exact command executed by ExternalJSEnv.
nicolasstucki Dec 1, 2015
bcb242d
Fix minor typo in doc
gzm0 Dec 3, 2015
4370568
Tools refactoring
gzm0 Jan 17, 2016
eac5177
Make private everything that can be in tools and js-envs.
sjrd Jan 17, 2016
a814cc3
Add DOMJSEnv based on 'jsdom' in Node.js.
nicolasstucki Dec 21, 2015
3ffff10
Fix scala-js/scala-js#2250: Split jsEnvs, creating jsEnvsTestKit, jsE…
nicolasstucki Apr 25, 2016
6f1be71
Fix scala-js/scala-js#2375: Move Node and Phantom CustomInitFilesTest…
nicolasstucki May 2, 2016
03388d4
Fix scala-js/scala-js#2368: Support single-arg setTimeout in Rhino
gzm0 Apr 30, 2016
ac662e6
Fix scala-js/scala-js#2376: PhantomJSEnv does not escape JS code
gzm0 May 1, 2016
b21dab5
Remove LinkingUnitJSEnv.
sjrd Mar 24, 2017
5c64e4d
Move the implemention of commonJSName to the sbt plugin.
sjrd Mar 28, 2017
86fedd1
Use VirtualJSFiles instead of ResolvedJSDependency in the JSEnv API.
sjrd Mar 28, 2017
a236c71
Unify the parameter names of external JS env constructors.
sjrd Apr 8, 2017
3711a9b
Merge '0.6.x' into 'master'.
sjrd Apr 9, 2017
c02c1bd
Fix scala-js/scala-js#2874: Remove the distinction libs/code in the J…
sjrd Apr 10, 2017
6558802
Fix scala-js/scala-js#2875: Remove JSEnv.loadLibs, resolvedJSEnv and …
sjrd Apr 12, 2017
67d9982
Separate all jsDependencies-related things in separate projects.
sjrd May 12, 2017
ba9e5a0
Avoid using `sys.env`.
sjrd May 26, 2017
590927c
Merge '0.6.x' into 'master'.
sjrd May 29, 2017
44cd5ab
Introduce a new surface API for JS envs with `Config` objects.
sjrd Jun 9, 2017
709ef34
Merge '0.6.x' into 'master'.
sjrd Jun 15, 2017
cedc304
Remove the deprecated APIs in JS envs.
sjrd Jun 16, 2017
927b8b1
Fix scala-js/scala-js#2877: Internal JS envs config amenable to binco…
sjrd Jun 16, 2017
a2310a8
Extract JSDOMNodeJSEnv in its own project.
sjrd Jun 22, 2017
52c8510
Mitigate scala-js/scala-js#3206: Send stderr of Node.js to the `JSCon…
sjrd Dec 6, 2017
b54c2f9
Merge '0.6.x' into 'master'.
sjrd Dec 26, 2017
f7f33df
Make the constructors and underlying vals of AnyVals private.
sjrd Dec 27, 2017
068d9d5
Move `ir.Utils.escapeJS` to `io.JSUtils`.
sjrd Jan 9, 2018
81b911d
Get rid of the `core` and `tools` package namespaces.
sjrd Jan 19, 2018
392e44a
Fix scala-js/scala-js#3033: Rehaul JSEnv API
gzm0 Dec 10, 2017
1135bac
Reduce acceptTimeout
eatkins Apr 26, 2018
7c6e5fe
Remove VirtualFileMaterializer
gzm0 Mar 31, 2018
050b9d7
Use VirtualBinaryFile in jsenv.Input
gzm0 Apr 14, 2018
61feecc
Merge '0.6.x' into 'master'.
sjrd May 19, 2018
5c9a28c
Fix scala-js/scala-js#3351: Use Buffer.alloc and Buffer.from instead …
sjrd May 21, 2018
f48f51d
Remove most of the VirtualFile API that is now unused.
gzm0 Apr 16, 2018
4ccb51a
Make MemVirtualBinaryFile immutable
gzm0 Apr 29, 2018
918865e
Merge pull request scala-js/scala-js#3347 from gzm0/no-js-files
gzm0 May 25, 2018
3266e12
Merge '0.6.x' into 'master'.
sjrd Jun 25, 2018
dcd5ed3
Fix scala-js/scala-js#3393: Correctly report VM crashes as failed fut…
sjrd Jun 26, 2018
d95880a
Merge '0.6.x' into 'master'.
sjrd Jun 29, 2018
ede2024
Fix scala-js/scala-js#3400: Do not crash if source-map-support is una…
sjrd Jul 2, 2018
6401ae1
[no-master] Fix scala-js/scala-js#3408: Survive concurrent calls to `…
sjrd Jul 13, 2018
183409d
Fix scala-js/scala-js#3410: Add supportsExit to JSEnvSuiteConfig.
gzm0 Jul 21, 2018
40e8167
Fix scala-js/scala-js#3412: Throw an IOException in noThrowOnBadFileTest
gzm0 Jul 21, 2018
3a03cce
Fix scala-js/scala-js#3411: Do not call onMessage immediately after init
gzm0 Jul 21, 2018
cf6a59b
Backport exception tests from SeleniumJSEnv
gzm0 Jul 22, 2018
d3b0c92
Fix a typo in a method name
gzm0 Jul 22, 2018
4c7068f
Fix scala-js/scala-js#3420: Make timeout tests less restrictive
gzm0 Aug 12, 2018
052901f
Skip the [no-master] commits ecd52f4dd and 65c123d2a
gzm0 Sep 1, 2018
6b3cc5f
Simplify largeMessage test
gzm0 Sep 23, 2018
c563156
Fix scala-js/scala-js#3457: Give timeout tests some slack
gzm0 Oct 9, 2018
e65a1d2
Fix scala-js/scala-js#3414: Better test kit
gzm0 Aug 12, 2018
e057dfc
Replace FrameworkDetector test with JSEnv test
gzm0 Oct 10, 2018
fdad432
Fix scala-js/scala-js#3462: Apache License Version 2.0.
sjrd Oct 11, 2018
396acc1
Merge '0.6.x' into 'master'.
sjrd Oct 16, 2018
ccd71b6
Fix scala-js/scala-js#3476: Specify that com messages must be valid U…
sjrd Oct 24, 2018
e2032ac
[no-master] Fix scala-js/scala-js#2175: Add support for ECMAScript 20…
sjrd Oct 25, 2018
116600c
Make `UnsupportedInputException` a normal (non-case) class.
sjrd Dec 5, 2018
802518a
Add the distinction between Script and CommonJS module in Input.
sjrd Nov 16, 2018
2a81c37
Fix scala-js/scala-js#2175: Add support for ECMAScript 2015 modules.
sjrd Oct 25, 2018
339cfe0
Merge '0.6.x' into 'master'.
sjrd Dec 8, 2018
b4a627f
Remove the hack to fix percentage signs in Node.js.
sjrd Dec 9, 2018
a46ed82
Remove System.exit / __ScalaJSEnv.exitFunction
gzm0 Dec 5, 2018
0d65d88
[no-master] Fix scala-js/scala-js#3528: Use `console.error(e)` to rep…
sjrd Jan 25, 2019
6b18524
Skip the [no-master] commit 12a7988.
sjrd Jan 28, 2019
5938bcb
Make JSEnvSuite compile warning free on Java 9
gzm0 Apr 13, 2019
628443b
Split `escapeJS` in `linker` and `js-envs`.
sjrd May 14, 2019
6ece659
Fix scala-js/scala-js#3589: Use java.nio.file.Path instead of Virtual…
gzm0 Apr 12, 2019
31259a2
Add a JSEnv test using the default filesystem
gzm0 May 19, 2019
94c5ec3
Fix several typos in comments and debug strings
asakaev Jun 8, 2019
1169011
[no-master] Remove `@deprecatedName`s that were introduced in 0.6.16.
sjrd Jun 17, 2019
ffa58d2
[no-master] Enable Scala 2.13.0 in the tools and all the other artifa…
sjrd Jun 18, 2019
df599a8
Enable Scala 2.13.0 in the linker and all the other artifacts.
sjrd Jun 18, 2019
2b26cbf
Skip the [no-master] commits until ab398e8d7.
sjrd Jul 8, 2019
03edf0c
Remove two unused imports of `JavaConverters`.
sjrd Aug 14, 2019
6fb7b91
Merge '0.6.x' into 'master'.
sjrd Sep 5, 2019
23112c7
Fix scala-js/scala-js#3616: Do not force all JSEnv inputs to be of th…
gzm0 Aug 6, 2019
e7613ec
Fix typos
bwignall Dec 6, 2019
7c7c509
Merge '0.6.x' into 'master'.
sjrd May 13, 2020
9e0a9c0
Add `()` at relevant call sites in the JS env test kit.
sjrd Jun 4, 2020
f3a156c
Import the JS Envs projects from the Scala.js core repository.
sjrd Jun 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
31 changes: 31 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
sudo: false
language: scala
script:
- sbt ++$TRAVIS_SCALA_VERSION scalajs-js-envs/test
- sbt ++$TRAVIS_SCALA_VERSION scalajs-js-envs/doc
- sbt ++$TRAVIS_SCALA_VERSION scalajs-js-envs/mimaReportBinaryIssues
- sbt ++$TRAVIS_SCALA_VERSION scalajs-js-envs/headerCheck scalajs-js-envs/test:headerCheck
- sbt ++$TRAVIS_SCALA_VERSION scalajs-js-envs-test-kit/test
- sbt ++$TRAVIS_SCALA_VERSION scalajs-js-envs-test-kit/doc
- sbt ++$TRAVIS_SCALA_VERSION scalajs-js-envs-test-kit/mimaReportBinaryIssues
- sbt ++$TRAVIS_SCALA_VERSION scalajs-js-envs-test-kit/headerCheck scalajs-js-envs-test-kit/test:headerCheck
- sbt ++$TRAVIS_SCALA_VERSION scalajs-env-nodejs/test
- sbt ++$TRAVIS_SCALA_VERSION scalajs-env-nodejs/doc
- sbt ++$TRAVIS_SCALA_VERSION scalajs-env-nodejs/mimaReportBinaryIssues
- sbt ++$TRAVIS_SCALA_VERSION scalajs-env-nodejs/headerCheck scalajs-env-nodejs/test:headerCheck
scala:
- 2.11.12
- 2.12.11
- 2.13.2
jdk:
- openjdk8

cache:
directories:
- "$HOME/.cache/coursier"
- "$HOME/.ivy2/cache"
- "$HOME/.sbt"
before_cache:
- rm -fv $HOME/.ivy2/.sbt.ivy.lock
- find $HOME/.ivy2/cache -name "ivydata-*.properties" -print -delete
- find $HOME/.sbt -name "*.lock" -print -delete
143 changes: 143 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
val previousVersion: Option[String] = Some("1.1.0")
val newScalaBinaryVersionsInThisRelease: Set[String] = Set()

inThisBuild(Def.settings(
version := "1.1.1-SNAPSHOT",
organization := "org.scala-js",
scalaVersion := "2.12.11",
crossScalaVersions := Seq("2.11.12", "2.12.11", "2.13.2"),
scalacOptions ++= Seq(
"-deprecation",
"-feature",
"-Xfatal-warnings",
"-encoding", "utf-8",
),

// Licensing
homepage := Some(url("https://github.com/scala-js/scala-js-js-envs")),
startYear := Some(2013),
licenses += (("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0"))),
scmInfo := Some(ScmInfo(
url("https://github.com/scala-js/scala-js-js-envs"),
"scm:git:git@github.com:scala-js/scala-js-js-envs.git",
Some("scm:git:git@github.com:scala-js/scala-js-js-envs.git"))),

// Publishing
publishMavenStyle := true,
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (version.value.endsWith("-SNAPSHOT"))
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
pomExtra := (
<developers>
<developer>
<id>sjrd</id>
<name>Sébastien Doeraene</name>
<url>https://github.com/sjrd/</url>
</developer>
<developer>
<id>gzm0</id>
<name>Tobias Schlatter</name>
<url>https://github.com/gzm0/</url>
</developer>
<developer>
<id>nicolasstucki</id>
<name>Nicolas Stucki</name>
<url>https://github.com/nicolasstucki/</url>
</developer>
</developers>
),
pomIncludeRepository := { _ => false },
))

val commonSettings = Def.settings(
// Links to the JavaDoc do not work
Compile / doc / scalacOptions -= "-Xfatal-warnings",
Comment on lines +57 to +58
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I deactivate fatal warnings in Scaladoc, because links to the JavaDoc, including in @throws sections, do not work and report errors. We could fix this by doing all the heavy machinery that we do in scala-js/scala-js to patch up the JavaDoc links, but I found that overkill right now.


// Scaladoc linking
apiURL := {
val name = moduleName.value
val scalaBinVer = scalaBinaryVersion.value
val ver = version.value
Some(url(s"https://javadoc.io/doc/org.scala-js/${name}_$scalaBinVer/$ver/"))
},
autoAPIMappings := true,

// sbt-header configuration
headerLicense := Some(HeaderLicense.Custom(
s"""Scala.js JS Envs (${homepage.value.get})
|
|Copyright EPFL.
|
|Licensed under Apache License 2.0
|(https://www.apache.org/licenses/LICENSE-2.0).
|
|See the NOTICE file distributed with this work for
|additional information regarding copyright ownership.
|""".stripMargin
)),

// MiMa auto-configuration
mimaPreviousArtifacts ++= {
val scalaV = scalaVersion.value
val scalaBinaryV = scalaBinaryVersion.value
val thisProjectID = projectID.value
previousVersion match {
case None =>
Set.empty
case _ if newScalaBinaryVersionsInThisRelease.contains(scalaBinaryV) =>
// New in this release, no binary compatibility to comply to
Set.empty
case Some(prevVersion) =>
/* Filter out e:info.apiURL as it expects 1.1.1-SNAPSHOT, whereas the
* artifact we're looking for has 1.1.0 (for example).
*/
val prevExtraAttributes =
thisProjectID.extraAttributes.filterKeys(_ != "e:info.apiURL")
val prevProjectID =
(thisProjectID.organization % thisProjectID.name % prevVersion)
.cross(thisProjectID.crossVersion)
.extra(prevExtraAttributes.toSeq: _*)
Set(prevProjectID)
}
},
)

lazy val root = project
.in(file("."))

lazy val `scalajs-js-envs` = project
.in(file("js-envs"))
.settings(
commonSettings,
libraryDependencies ++= Seq(
"org.scala-js" %% "scalajs-logging" % "1.1.1",
"com.novocode" % "junit-interface" % "0.11" % "test",
),
)

lazy val `scalajs-js-envs-test-kit` = project
.in(file("js-envs-test-kit"))
.settings(
commonSettings,
libraryDependencies ++= Seq(
"com.google.jimfs" % "jimfs" % "1.1",
"junit" % "junit" % "4.12",
"com.novocode" % "junit-interface" % "0.11" % "test"
),
)
.dependsOn(`scalajs-js-envs`)

lazy val `scalajs-env-nodejs` = project
.in(file("nodejs-env"))
.settings(
commonSettings,
libraryDependencies ++= Seq(
"com.google.jimfs" % "jimfs" % "1.1",
"com.novocode" % "junit-interface" % "0.11" % "test"
),
)
.dependsOn(`scalajs-js-envs`, `scalajs-js-envs-test-kit` % "test")
151 changes: 151 additions & 0 deletions js-envs-test-kit/src/main/scala/org/scalajs/jsenv/test/ComTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* Scala.js JS Envs (https://github.com/scala-js/scala-js-js-envs)
*
* Copyright EPFL.
*
* Licensed under Apache License 2.0
* (https://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package org.scalajs.jsenv.test

import org.junit.{Before, Test, AssumptionViolatedException}
import org.junit.Assume._

import org.scalajs.jsenv._
import org.scalajs.jsenv.test.kit.TestKit

private[test] class ComTests(config: JSEnvSuiteConfig) {
private val kit = new TestKit(config.jsEnv, config.awaitTimeout)

@Before
def before: Unit = {
assumeTrue("JSEnv needs com support", config.supportsCom)
}

@Test
def basicTest: Unit = {
kit.withComRun("""
scalajsCom.init(function(msg) { scalajsCom.send("received: " + msg); });
scalajsCom.send("Hello World");
""") { run =>

run.expectMsg("Hello World")

for (i <- 0 to 10) {
run
.send(i.toString)
.expectMsg(s"received: $i")
}

run.expectNoMsgs()
.closeRun()
}
}

@Test
def jsExitsOnMessageTest: Unit = {
val exitStat = config.exitJSStatement.getOrElse(
throw new AssumptionViolatedException("JSEnv needs exitJSStatement"))

kit.withComRun(s"""
scalajsCom.init(function(msg) { $exitStat });
for (var i = 0; i < 10; ++i)
scalajsCom.send("msg: " + i);
""") { run =>

for (i <- 0 until 10)
run.expectMsg(s"msg: $i")

run
.send("quit")
.expectNoMsgs()
.succeeds()
}
}

@Test
def multiEnvTest: Unit = {
val n = 10
val runs = List.fill(5) {
kit.startWithCom("""
scalajsCom.init(function(msg) {
scalajsCom.send("pong");
});
""")
}

try {
for (_ <- 0 until n) {
runs.foreach(_.send("ping"))
runs.foreach(_.expectMsg("pong"))
}

runs.foreach {
_.expectNoMsgs()
.closeRun()
}
} finally {
runs.foreach(_.close())
}
}

private def replyTest(msg: String) = {
kit.withComRun("scalajsCom.init(scalajsCom.send);") {
_.send(msg)
.expectMsg(msg)
.expectNoMsgs()
.closeRun()
}
}

@Test
def largeMessageTest: Unit = {
/* 1MB data.
* (i & 0x7f) limits the input to the ASCII repertoire, which will use
* exactly 1 byte per Char in UTF-8. This restriction also ensures that we
* do not introduce surrogate characters and therefore no invalid UTF-16
* strings.
*/
replyTest(new String(Array.tabulate(1024 * 1024)(i => (i & 0x7f).toChar)))
}

@Test
def highCharTest: Unit = { // #1536
replyTest("\uC421\u8F10\u0112\uFF32")
}

@Test
def noInitTest: Unit = {
kit.withComRun("") {
_.send("Dummy")
.expectNoMsgs()
.closeRun()
}
}

@Test
def separateComStdoutTest: Unit = {
// Make sure that com and stdout do not interfere with each other.
kit.withComRun("""
scalajsCom.init(function (msg) {
console.log("got: " + msg)
});
console.log("a");
scalajsCom.send("b");
scalajsCom.send("c");
console.log("d");
""") {
_.expectOut("a\n")
.expectMsg("b")
.expectMsg("c")
.expectOut("d\n")
.send("foo")
.expectOut("got: foo\n")
.closeRun()
}
}
}
Loading