Skip to content

Commit 87e72ae

Browse files
committed
bugfix: Don't try to discover test frameworks if none exist
Previously, even if node_modules wouldn't exist we would run test discovery, which requires the node_modules and the scripts it contains. Now, we show an error in such a case. This seems to have hanged the node process causing no tests to be discovered. I am not sure how to properly test it yet, but I need to dig into the JS part at some point since from earlier discussions with Sebastien the bridges might be problematic.
1 parent fbd869c commit 87e72ae

2 files changed

Lines changed: 31 additions & 20 deletions

File tree

bridges/scalajs-1/src/main/scala/bloop/scalajs/JsBridge.scala

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,25 +147,32 @@ object JsBridge {
147147
env: Map[String, String]
148148
): (List[sbt.testing.Framework], () => Unit) = {
149149
implicit val debugFilter: DebugFilter = DebugFilter.Test
150-
val nodeModules = baseDirectory.resolve("node_modules").toString
151-
logger.debug("Node.js module path: " + nodeModules)
152-
val fullEnv = Map("NODE_PATH" -> nodeModules) ++ env
153-
val config =
154-
NodeJSConfig().withExecutable(nodePath).withCwd(Some(baseDirectory)).withEnv(fullEnv)
155-
val nodeEnv =
156-
if (!jsConfig.jsdom.contains(true)) new NodeJSEnv(logger, config)
157-
else new JsDomNodeJsEnv(logger, config)
158-
159-
// The order of the scripts mandates the load order in the JavaScript runtime
160-
val input = jsConfig.kind match {
161-
case ModuleKindJS.NoModule => Input.Script(jsPath)
162-
case ModuleKindJS.CommonJSModule => Input.CommonJSModule(jsPath)
163-
case ModuleKindJS.ESModule => Input.ESModule(jsPath)
164-
}
150+
val nodeModules = baseDirectory.resolve("node_modules")
151+
if (nodeModules.toFile().exists()) {
152+
logger.debug("Node.js module path: " + nodeModules.toString())
153+
val fullEnv = Map("NODE_PATH" -> nodeModules.toString()) ++ env
154+
val config =
155+
NodeJSConfig().withExecutable(nodePath).withCwd(Some(baseDirectory)).withEnv(fullEnv)
156+
val nodeEnv =
157+
if (!jsConfig.jsdom.contains(true)) new NodeJSEnv(logger, config)
158+
else new JsDomNodeJsEnv(logger, config)
159+
160+
// The order of the scripts mandates the load order in the JavaScript runtime
161+
val input = jsConfig.kind match {
162+
case ModuleKindJS.NoModule => Input.Script(jsPath)
163+
case ModuleKindJS.CommonJSModule => Input.CommonJSModule(jsPath)
164+
case ModuleKindJS.ESModule => Input.ESModule(jsPath)
165+
}
165166

166-
val testConfig = TestAdapter.Config().withLogger(new Logger(logger))
167-
val adapter = new TestAdapter(nodeEnv, Seq(input), testConfig)
168-
val result = adapter.loadFrameworks(frameworkNames).flatMap(_.toList)
169-
(result, () => adapter.close())
167+
val testConfig = TestAdapter.Config().withLogger(new Logger(logger))
168+
val adapter = new TestAdapter(nodeEnv, Seq(input), testConfig)
169+
val result = adapter.loadFrameworks(frameworkNames).flatMap(_.toList)
170+
(result, () => adapter.close())
171+
} else {
172+
logger.error(
173+
s"Cannot discover test frameworks, missing node_modules in test project, expected them at $nodeModules"
174+
)
175+
(Nil, () => ())
176+
}
170177
}
171178
}

bridges/scalajs-1/src/main/scala/bloop/scalajs/jsenv/NodeJsEnv.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ final class NodeJSEnv(logger: Logger, config: NodeJSConfig) extends JSEnv {
124124
}
125125

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

@@ -290,7 +291,10 @@ object NodeJSEnv {
290291
import scala.concurrent.ExecutionContext.Implicits.global
291292

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

0 commit comments

Comments
 (0)