Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Don't try to discover test frameworks if none exist #2107

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions bridges/scalajs-1/src/main/scala/bloop/scalajs/JsBridge.scala
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,32 @@ object JsBridge {
env: Map[String, String]
): (List[sbt.testing.Framework], () => Unit) = {
implicit val debugFilter: DebugFilter = DebugFilter.Test
val nodeModules = baseDirectory.resolve("node_modules").toString
logger.debug("Node.js module path: " + nodeModules)
val fullEnv = Map("NODE_PATH" -> nodeModules) ++ env
val config =
NodeJSConfig().withExecutable(nodePath).withCwd(Some(baseDirectory)).withEnv(fullEnv)
val nodeEnv =
if (!jsConfig.jsdom.contains(true)) new NodeJSEnv(logger, config)
else new JsDomNodeJsEnv(logger, config)

// The order of the scripts mandates the load order in the JavaScript runtime
val input = jsConfig.kind match {
case ModuleKindJS.NoModule => Input.Script(jsPath)
case ModuleKindJS.CommonJSModule => Input.CommonJSModule(jsPath)
case ModuleKindJS.ESModule => Input.ESModule(jsPath)
}
val nodeModules = baseDirectory.resolve("node_modules")
if (nodeModules.toFile().exists()) {
logger.debug("Node.js module path: " + nodeModules.toString())
val fullEnv = Map("NODE_PATH" -> nodeModules.toString()) ++ env
val config =
NodeJSConfig().withExecutable(nodePath).withCwd(Some(baseDirectory)).withEnv(fullEnv)
val nodeEnv =
if (!jsConfig.jsdom.contains(true)) new NodeJSEnv(logger, config)
else new JsDomNodeJsEnv(logger, config)

// The order of the scripts mandates the load order in the JavaScript runtime
val input = jsConfig.kind match {
case ModuleKindJS.NoModule => Input.Script(jsPath)
case ModuleKindJS.CommonJSModule => Input.CommonJSModule(jsPath)
case ModuleKindJS.ESModule => Input.ESModule(jsPath)
}

val testConfig = TestAdapter.Config().withLogger(new Logger(logger))
val adapter = new TestAdapter(nodeEnv, Seq(input), testConfig)
val result = adapter.loadFrameworks(frameworkNames).flatMap(_.toList)
(result, () => adapter.close())
val testConfig = TestAdapter.Config().withLogger(new Logger(logger))
val adapter = new TestAdapter(nodeEnv, Seq(input), testConfig)
val result = adapter.loadFrameworks(frameworkNames).flatMap(_.toList)
(result, () => adapter.close())
} else {
logger.error(
s"Cannot discover test frameworks, missing node_modules in test project, expected them at $nodeModules"
ckipp01 marked this conversation as resolved.
Show resolved Hide resolved
)
(Nil, () => ())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ final class NodeJSEnv(logger: Logger, config: NodeJSConfig) extends JSEnv {
}

private def internalStart(input: Seq[Input], runConfig: RunConfig): JSRun = {
runConfig.logger.debug("Using input file: " + (input.mkString(",")))
NodeJSEnv.internalStart(logger, config, env)(NodeJSEnv.write(input), runConfig)
}

Expand Down Expand Up @@ -290,7 +291,10 @@ object NodeJSEnv {
import scala.concurrent.ExecutionContext.Implicits.global

private val isClosed = AtomicBoolean(false)
override def future: Future[Unit] = cancellable.map(_ => ())
override def future: Future[Unit] = cancellable.map { results =>
logger.debug(s"Finished with results: ${results}")
()
}
override def close(): Unit = {
// Make sure we only destroy the process once, the test adapter can call this several times!
if (!isClosed.getAndSet(true)) {
Expand Down