您可以完全覆盖test
任务的行为,只需执行您的主类。从https://github.com/scala-js/scala-js/blob/v0.6.5/sbt-plugin/src/main/scala/scala/scalajs/sbtplugin/ScalaJSPluginInternal.scala#L547-L549获得灵感
/** Run a class in a given environment using a given launcher */
def jsRun(env: JSEnv, cp: CompleteClasspath, mainCl: String,
launcher: VirtualJSFile, jsConsole: JSConsole, log: Logger) = {
log.info("Running " + mainCl)
log.debug(s"with JSEnv of type ${env.getClass()}")
log.debug(s"with classpath of type ${cp.getClass}")
// Actually run code
env.jsRunner(cp, launcher, log, jsConsole).run()
}
def launcherContent(mainCl: String) = {
val parts = mainCl.split('.').map(s => s"""["${escapeJS(s)}"]""").mkString
s"${CoreJSLibs.jsGlobalExpr}$parts().main();\n"
}
def memLauncher(mainCl: String) = {
new MemVirtualJSFile("Generated launcher file")
.withContent(launcherContent(mainCl))
}
test in Test := {
val mainClass = "path.to.AnotherClassWithTests"
jsRun((jsEnv in Test).value, (scalaJSExecClasspath in Test).value, mainClass,
memLauncher(mainClass), (scalaJSConsole in Test).value, streams.value.log)
}
要获取已检测到的测试列表,您可以使用 sbt 任务(definedTests in Test).value
,或者可能使用(definedTestNames in Test).value
.