summaryrefslogtreecommitdiff
path: root/scalajslib/test/src/ScalaJsUtils.scala
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-12-12 16:56:02 -0800
committerGitHub <noreply@github.com>2018-12-12 16:56:02 -0800
commit9ba4cb69331386dfde9bac69dc2d5b22401face3 (patch)
tree120349e8015ae5717d36bd44209cde6ff9543518 /scalajslib/test/src/ScalaJsUtils.scala
parentea7fceb6e56f53bde3517586dfc57e10a605a524 (diff)
downloadmill-9ba4cb69331386dfde9bac69dc2d5b22401face3.tar.gz
mill-9ba4cb69331386dfde9bac69dc2d5b22401face3.tar.bz2
mill-9ba4cb69331386dfde9bac69dc2d5b22401face3.zip
collapse boilerplate folder structure within src/ folders (#505)
* collapse boilerplate folder structure within src/ folders * .
Diffstat (limited to 'scalajslib/test/src/ScalaJsUtils.scala')
-rw-r--r--scalajslib/test/src/ScalaJsUtils.scala21
1 files changed, 21 insertions, 0 deletions
diff --git a/scalajslib/test/src/ScalaJsUtils.scala b/scalajslib/test/src/ScalaJsUtils.scala
new file mode 100644
index 00000000..68f2f7ee
--- /dev/null
+++ b/scalajslib/test/src/ScalaJsUtils.scala
@@ -0,0 +1,21 @@
+package mill.scalajslib
+
+import java.io.{FileReader, StringWriter}
+import javax.script.{ScriptContext, ScriptEngineManager}
+
+object ScalaJsUtils {
+ def runJS(path: os.Path): String = {
+ val engineManager = new ScriptEngineManager(null)
+ val engine = engineManager.getEngineByName("nashorn")
+ val console = new Console
+ val bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE)
+ bindings.put("console", console)
+ engine.eval(new FileReader(path.toIO))
+ console.out.toString
+ }
+}
+
+class Console {
+ val out = new StringWriter()
+ def log(s: String): Unit = out.append(s)
+}