org.scalajs.testing.adapter.JSEnvRPC$RunTerminatedException 尝试将 scalatest 与 scalajs 一起使用

Posted

技术标签:

【中文标题】org.scalajs.testing.adapter.JSEnvRPC$RunTerminatedException 尝试将 scalatest 与 scalajs 一起使用【英文标题】:org.scalajs.testing.adapter.JSEnvRPC$RunTerminatedException when trying to use scalatest with scalajs 【发布时间】:2021-03-08 19:43:30 【问题描述】:

我正在尝试使用 scalatest 来测试 scalajs,但它会引发异常。不知道可能是什么问题。请问有什么建议吗? TIA。

我要提到的另一件事是,即使没有任何测试文件,也会引发以下异常。

Build.sbt

ThisBuild / scalaVersion := "2.12.10"

lazy val root = project.in(file(".")).aggregate(parser.js, parser.jvm).
  settings(
    publish := ,
    publishLocal := ,
  )

lazy val parser = crossProject(JSPlatform, JVMPlatform).in(file(".")).
  settings(
    name := "rules-parser",
    version := "0.1",
    libraryDependencies ++= Seq(
      "com.lihaoyi" %%% "fastparse" % "2.2.4",
      "com.chuusai" %%% "shapeless" % "2.4.0-M1",
      "org.scalactic" %%% "scalactic" % "3.2.2",
      "org.scalatest" %%% "scalatest" % "3.3.0-SNAP2" % Test
    )
  ).
  jsSettings(
//    scalaJSUseMainModuleInitializer := true,
    libraryDependencies ++= Seq(
      "org.scala-js" %%% "scalajs-dom" % "1.1.0",
      "com.lihaoyi" %%% "scalatags" % "0.9.2"
    )
  ).
  jvmSettings(
    libraryDependencies ++= Seq(
      "org.scala-js" %% "scalajs-stubs" % "1.0.0" % "provided"
    )
  )

js/test/scala/example/ExampleSpec.scala

package example

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.must.Matchers

object ExampleSpec extends AnyFlatSpec with Matchers 
  "Simple test" should "pass" in 
    assert(1 == 1)
  

例外

sbt:root> last parserJS / Test / loadedTestFrameworks
[debug] Starting process: node
[error] org.scalajs.testing.common.RPCCore$ClosedException: org.scalajs.testing.adapter.JSEnvRPC$RunTerminatedException
[error]     at org.scalajs.testing.common.RPCCore.helpClose(RPCCore.scala:223)
[error]     at org.scalajs.testing.common.RPCCore.call(RPCCore.scala:164)
[error]     at org.scalajs.testing.adapter.TestAdapter.loadFrameworks(TestAdapter.scala:57)
[error]     at org.scalajs.sbtplugin.ScalaJSPluginInternal$.$anonfun$scalaJSTestSettings$4(ScalaJSPluginInternal.scala:597)
[error]     at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]     at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error]     at sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error]     at sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error]     at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error]     at sbt.Execute.work(Execute.scala:291)
[error]     at sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error]     at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error]     at sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error]     at java.lang.Thread.run(Thread.java:748)
[error] Caused by: org.scalajs.testing.adapter.JSEnvRPC$RunTerminatedException
[error]     at org.scalajs.testing.adapter.JSEnvRPC.$anonfun$new$1(JSEnvRPC.scala:38)
[error]     at org.scalajs.testing.adapter.JSEnvRPC.$anonfun$new$1$adapted(JSEnvRPC.scala:38)
[error]     at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:64)
[error]     at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
[error]     at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
[error]     at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
[error]     at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
[error]     at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
[error] Caused by: java.io.IOException: Cannot run program "node": error=2, No such file or directory
[error]     at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
[error]     at org.scalajs.jsenv.ExternalJSRun$.startProcess(ExternalJSRun.scala:143)
[error]     at org.scalajs.jsenv.ExternalJSRun$.start(ExternalJSRun.scala:40)
[error]     at org.scalajs.jsenv.nodejs.NodeJSEnv.internalStart(NodeJSEnv.scala:63)
[error]     at org.scalajs.jsenv.nodejs.NodeJSEnv.$anonfun$startWithCom$1(NodeJSEnv.scala:47)
[error]     at org.scalajs.jsenv.nodejs.ComRun$.start(ComSupport.scala:214)
[error]     at org.scalajs.jsenv.nodejs.NodeJSEnv.startWithCom(NodeJSEnv.scala:46)
[error]     at org.scalajs.testing.adapter.JSEnvRPC.<init>(JSEnvRPC.scala:25)
[error]     at org.scalajs.testing.adapter.TestAdapter.startManagedRunner(TestAdapter.scala:129)
[error]     at org.scalajs.testing.adapter.TestAdapter.$anonfun$getRunnerForThread$1(TestAdapter.scala:120)
[error]     at scala.collection.concurrent.TrieMap.getOrElseUpdate(TrieMap.scala:897)
[error]     at org.scalajs.testing.adapter.TestAdapter.getRunnerForThread(TestAdapter.scala:120)
[error]     at org.scalajs.testing.adapter.TestAdapter.loadFrameworks(TestAdapter.scala:56)
[error]     at org.scalajs.sbtplugin.ScalaJSPluginInternal$.$anonfun$scalaJSTestSettings$4(ScalaJSPluginInternal.scala:597)
[error]     at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]     at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error]     at sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error]     at sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error]     at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error]     at sbt.Execute.work(Execute.scala:291)
[error]     at sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error]     at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error]     at sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error]     at java.lang.Thread.run(Thread.java:748)
[error] Caused by: java.io.IOException: error=2, No such file or directory
[error]     at java.lang.UNIXProcess.forkAndExec(Native Method)
[error]     at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
[error]     at java.lang.ProcessImpl.start(ProcessImpl.java:134)
[error]     at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
[error]     at org.scalajs.jsenv.ExternalJSRun$.startProcess(ExternalJSRun.scala:143)
[error]     at org.scalajs.jsenv.ExternalJSRun$.start(ExternalJSRun.scala:40)
[error]     at org.scalajs.jsenv.nodejs.NodeJSEnv.internalStart(NodeJSEnv.scala:63)
[error]     at org.scalajs.jsenv.nodejs.NodeJSEnv.$anonfun$startWithCom$1(NodeJSEnv.scala:47)
[error]     at org.scalajs.jsenv.nodejs.ComRun$.start(ComSupport.scala:214)
[error]     at org.scalajs.jsenv.nodejs.NodeJSEnv.startWithCom(NodeJSEnv.scala:46)
[error]     at org.scalajs.testing.adapter.JSEnvRPC.<init>(JSEnvRPC.scala:25)
[error]     at org.scalajs.testing.adapter.TestAdapter.startManagedRunner(TestAdapter.scala:129)
[error]     at org.scalajs.testing.adapter.TestAdapter.$anonfun$getRunnerForThread$1(TestAdapter.scala:120)
[error]     at scala.collection.concurrent.TrieMap.getOrElseUpdate(TrieMap.scala:897)
[error]     at org.scalajs.testing.adapter.TestAdapter.getRunnerForThread(TestAdapter.scala:120)
[error]     at org.scalajs.testing.adapter.TestAdapter.loadFrameworks(TestAdapter.scala:56)
[error]     at org.scalajs.sbtplugin.ScalaJSPluginInternal$.$anonfun$scalaJSTestSettings$4(ScalaJSPluginInternal.scala:597)
[error]     at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]     at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error]     at sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error]     at sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error]     at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error]     at sbt.Execute.work(Execute.scala:291)
[error]     at sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error]     at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error]     at sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error]     at java.lang.Thread.run(Thread.java:748)
[error] (parserJS / Test / loadedTestFrameworks) org.scalajs.testing.common.RPCCore$ClosedException: org.scalajs.testing.adapter.JSEnvRPC$RunTerminatedException

【问题讨论】:

【参考方案1】:

由此:无法运行程序“节点”:错误=2,没有这样的文件

看来您需要安装 node.js。如果它已经安装,请确保它在您的路径上。

【讨论】:

以上是关于org.scalajs.testing.adapter.JSEnvRPC$RunTerminatedException 尝试将 scalatest 与 scalajs 一起使用的主要内容,如果未能解决你的问题,请参考以下文章