我的一个Scala.js项目在尝试运行sbt test
(在构建服务器上)时总是抛出以下异常:
[info] Fast optimizing /opt/buildagent/work/4d5c5801308f9701/com.xxxx.cc.b/target/scala-2.12/yyyyy-zzzzzzzzz-test-fastopt.js
[11:42:23][Step 8/9] Fast optimizing /opt/buildagent/work/4d5c5801308f9701/com.xxxx.cc.b/target/scala-2.12/yyyyy-zzzzzzzzz-test-fastopt.js
[11:42:38][Step 8/9] java.lang.NumberFormatException: For input string: ""
[11:42:38][Step 8/9] Error
[11:42:38][Step 8/9] at $c_jl_NumberFormatException.$c_jl_Throwable.fillInStackTrace__jl_Throwable (file:///opt/buildagent/work/4d5c5801308f9701/com.xxxx.cc.b/target/scala-2.12/yyyyy-zzzzzzzzz-test-fastopt.js:47356:14)
[11:42:38][Step 8/9] at $c_jl_NumberFormatException.$c_jl_Throwable.init___T__jl_Throwable__Z__Z (file:///opt/buildagent/work/4d5c5801308f9701/com.xxxx.cc.b/target/scala-2.12/yyyyy-zzzzzzzzz-test-fastopt.js:47474:10)
[11:42:38][Step 8/9] at $c_jl_NumberFormatException.init___T (file:///opt/buildagent/work/4d5c5801308f9701/com.xxxx.cc.b/target/scala-2.12/yyyyy-zzzzzzzzz-test-fastopt.js:154387:58)
[11:42:38][Step 8/9] at $c_jl_Integer$.fail$1__p1__T__sr_Nothing$ (file:///opt/buildagent/work/4d5c5801308f9701/com.xxxx.cc.b/target/scala-2.12/yyyyy-zzzzzzzzz-test-fastopt.js:75485:43)
[11:42:38][Step 8/9] at $c_jl_Integer$.parseInt__T__I__I (file:///opt/buildagent/work/4d5c5801308f9701/com.xxxx.cc.b/target/scala-2.12/yyyyy-zzzzzzzzz-test-fastopt.js:75490:10)
[11:42:38][Step 8/9] at $c_Lcom_xxxx_cc_b_base_Bor$.$c_Lcom_xxxx_cc_b_core_base_BorBase.init___Lcom_xxxx_cc_b_core_pages_fleetViewPageBase_FleetViewPageBase__Lcom_xxxx_cc_b_core_guiElements_navbar_NavBarBase (file:///opt/buildagent/work/4d5c5801308f9701/com.xxxx.cc.b/target/scala-2.12/yyyyy-zzzzzzzzz-test-fastopt.js:4112:24)
[11:42:38][Step 8/9] at $c_Lcom_xxxx_cc_b_base_Bor$.init___ (file:///opt/buildagent/work/4d5c5801308f9701/com.xxxx.cc.b/target/scala-2.12/yyyyy-zzzzzzzzz-test-fastopt.js:33487:169)
[11:42:38][Step 8/9] at $m_Lcom_xxxx_cc_b_base_Bor$ (file:///opt/buildagent/work/4d5c5801308f9701/com.xxxx.cc.b/target/scala-2.12/yyyyy-zzzzzzzzz-test-fastopt.js:33811:69)
[11:42:38][Step 8/9] at file:///opt/buildagent/work/4d5c5801308f9701/com.xxxx.cc.b/target/scala-2.12/yyyyy-zzzzzzzzz-test-fastopt.js:207467:10
[11:42:38][Step 8/9] at file:///opt/buildagent/work/4d5c5801308f9701/com.xxxx.cc.b/target/scala-2.12/yyyyy-zzzzzzzzz-test-fastopt.js:207535:4
[11:42:38][Step 8/9] [error] org.scalajs.jsenv.ExternalJSEnv$NonZeroExitException: Node.js with JSDOM exited with code 1
[11:42:38][Step 8/9] [error] at org.scalajs.jsenv.ExternalJSEnv$AbstractExtRunner.waitForVM(ExternalJSEnv.scala:126)
[11:42:38][Step 8/9] [error] at org.scalajs.jsenv.ExternalJSEnv$AsyncExtRunner$$anon$1.$anonfun$run$2(ExternalJSEnv.scala:191)
[11:42:38][Step 8/9] [error] at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[11:42:38][Step 8/9] [error] at scala.util.Try$.apply(Try.scala:209)
[11:42:38][Step 8/9] [error] at org.scalajs.jsenv.ExternalJSEnv$AsyncExtRunner$$anon$1.run(ExternalJSEnv.scala:191)
[11:42:38][Step 8/9] ObjectEvent(error, TraceEvent(Error, org.scalajs.jsenv.ExternalJSEnv$NonZeroExitException: Node.js with JSDOM exited with code 1, None, None), None, None, sbt.internal.util.TraceEvent, JObject([Lsjsonnew.shaded.scalajson.ast.unsafe.JField;@72a33316))
[11:42:38][Step 8/9] [error] (Test / loadedTestFrameworks) org.scalajs.jsenv.ExternalJSEnv$NonZeroExitException: Node.js with JSDOM exited with code 1
[11:42:38][Step 8/9] (Test / loadedTestFrameworks) org.scalajs.jsenv.ExternalJSEnv$NonZeroExitException: Node.js with JSDOM exited with code 1
[11:42:38][Step 8/9] [error] Total time: 22 s, completed Jun 26, 2019 11:42:38 AM
[11:42:38][Step 8/9] Process exited with code 1
[11:42:38][Step 8/9] Process exited with code 1 (Step: run scala unit tests (Simple Build Tool (Scala)))
[11:42:38][Step 8/9] Step run scala unit tests (Simple Build Tool (Scala)) failed
奇怪的是,这个项目甚至没有指定任何测试。构建服务器以相同的方式构建所有项目,因此我不能仅停用sbt test
构建步骤。知道是什么原因造成的吗?
答案 0 :(得分:2)
看起来对象com.xxxx.cc.b.base.Bor
是用@JSExportTopLevel
导出的,它在BorBase
中的父构造函数会引发异常(通过用空字符串调用Integer.parseInt
)。在Scala.js应用程序中发生任何其他事情之前(包括在检测是否存在测试之前),都会实例化顶级导出的对象。