空 Scala.js 测试出现 NumberFormatException

NumberFormatException on empty Scala.js tests

我的一个 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__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.$anonfun$run(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.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 构建步骤。知道是什么原因造成的吗?

看起来对象 com.xxxx.cc.b.base.Bor 是用 @JSExportTopLevel 导出的,并且它在 BorBase 中的父构造函数抛出异常(通过使用空字符串调用 Integer.parseInt) . Top-level 导出的对象在 Scala.js 应用中发生任何其他事情之前实例化,包括在 检测 是否存在测试之前。