org.scalajs.тестирование.адаптер.Исключение JSEnvRPC$RunTerminatedException при попытке использовать scalatest с scalajs

#scala #sbt #scalatest #scala.js

#скала #sbt #самый масштабируемый #scala.js

Вопрос:

Я пытаюсь использовать 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 . Если он уже установлен, убедитесь, что он находится на вашем пути.