@@ -4,6 +4,7 @@ import coursier.jvm.Execve
44import org .scalajs .jsenv .jsdomnodejs .JSDOMNodeJSEnv
55import org .scalajs .jsenv .nodejs .NodeJSEnv
66import org .scalajs .jsenv .{Input , RunConfig }
7+ import org .scalajs .testing .adapter .TestAdapter as ScalaJsTestAdapter
78import sbt .testing .{Framework , Status }
89
910import java .io .File
@@ -16,6 +17,7 @@ import scala.build.errors.*
1617import scala .build .internals .EnvVar
1718import scala .build .testrunner .FrameworkUtils .*
1819import scala .build .testrunner .{AsmTestRunner , TestRunner }
20+ import scala .scalanative .testinterface .adapter .TestAdapter as ScalaNativeTestAdapter
1921import scala .util .{Failure , Properties , Success }
2022
2123object Runner {
@@ -240,22 +242,20 @@ object Runner {
240242 sourceMap : Boolean = false ,
241243 esModule : Boolean = false
242244 ): Either [BuildException , Process ] = either {
243-
244- import logger .{log , debug }
245-
246- val nodePath = value(findInPath(" node" ).map(_.toString).toRight(NodeNotFoundError ()))
247-
248- if (! jsDom && allowExecve && Execve .available()) {
249-
245+ val nodePath : String =
246+ value(findInPath(" node" )
247+ .map(_.toString)
248+ .toRight(NodeNotFoundError ()))
249+ if ! jsDom && allowExecve && Execve .available() then {
250250 val command = Seq (nodePath, entrypoint.getAbsolutePath) ++ args
251251
252- log(
252+ logger. log(
253253 s " Running ${command.mkString(" " )}" ,
254254 " Running" + System .lineSeparator() +
255255 command.iterator.map(_ + System .lineSeparator()).mkString
256256 )
257257
258- debug(" execve available" )
258+ logger. debug(" execve available" )
259259 Execve .execve(
260260 command.head,
261261 " node" +: command.tail.toArray,
@@ -264,40 +264,36 @@ object Runner {
264264 sys.error(" should not happen" )
265265 }
266266 else {
267-
268267 val nodeArgs =
269268 // Scala.js runs apps by piping JS to node.
270269 // If we need to pass arguments, we must first make the piped input explicit
271270 // with "-", and we pass the user's arguments after that.
272- if (args.isEmpty) Nil
273- else " -" :: args.toList
271+ if args.isEmpty then Nil else " -" :: args.toList
274272 val envJs =
275- if ( jsDom)
273+ if jsDom then
276274 new JSDOMNodeJSEnv (
277275 JSDOMNodeJSEnv .Config ()
278276 .withExecutable(nodePath)
279277 .withArgs(nodeArgs)
280278 .withEnv(Map .empty)
281279 )
282- else new NodeJSEnv (
283- NodeJSEnv .Config ()
284- .withExecutable(nodePath)
285- .withArgs(nodeArgs)
286- .withEnv(Map .empty)
287- .withSourceMap(sourceMap)
288- )
280+ else
281+ new NodeJSEnv (
282+ NodeJSEnv .Config ()
283+ .withExecutable(nodePath)
284+ .withArgs(nodeArgs)
285+ .withEnv(Map .empty)
286+ .withSourceMap(sourceMap)
287+ )
289288
290- val inputs = Seq (
291- if (esModule) Input .ESModule (entrypoint.toPath)
292- else Input .Script (entrypoint.toPath)
293- )
289+ val inputs =
290+ Seq (if esModule then Input .ESModule (entrypoint.toPath) else Input .Script (entrypoint.toPath))
294291
295292 val config = RunConfig ().withLogger(logger.scalaJsLogger)
296293 val processJs = envJs.start(inputs, config)
297294
298295 processJs.future.value.foreach {
299- case Failure (t) =>
300- throw new Exception (t)
296+ case Failure (t) => throw new Exception (t)
301297 case Success (_) =>
302298 }
303299
@@ -405,57 +401,65 @@ object Runner {
405401 ): Either [TestError , Int ] = either {
406402 import org .scalajs .jsenv .Input
407403 import org .scalajs .jsenv .nodejs .NodeJSEnv
408- import org .scalajs .testing .adapter .TestAdapter
409404 val nodePath = findInPath(" node" ).fold(" node" )(_.toString)
410405 val jsEnv =
411- if ( jsDom)
406+ if jsDom then
412407 new JSDOMNodeJSEnv (
413408 JSDOMNodeJSEnv .Config ()
414409 .withExecutable(nodePath)
415410 .withArgs(Nil )
416411 .withEnv(Map .empty)
417412 )
418- else new NodeJSEnv (
419- NodeJSEnv .Config ()
420- .withExecutable(nodePath)
421- .withArgs(Nil )
422- .withEnv(Map .empty)
423- .withSourceMap(NodeJSEnv .SourceMap .Disable )
424- )
425- val adapterConfig = TestAdapter .Config ().withLogger(logger.scalaJsLogger)
426- val inputs = Seq (
427- if (esModule) Input .ESModule (entrypoint.toPath)
428- else Input .Script (entrypoint.toPath)
429- )
430- var adapter : TestAdapter = null
413+ else
414+ new NodeJSEnv (
415+ NodeJSEnv .Config ()
416+ .withExecutable(nodePath)
417+ .withArgs(Nil )
418+ .withEnv(Map .empty)
419+ .withSourceMap(NodeJSEnv .SourceMap .Disable )
420+ )
421+ val adapterConfig = ScalaJsTestAdapter .Config ().withLogger(logger.scalaJsLogger)
422+ val inputs =
423+ Seq (if esModule then Input .ESModule (entrypoint.toPath) else Input .Script (entrypoint.toPath))
424+ var adapter : ScalaJsTestAdapter = null
431425
432426 logger.debug(s " JS tests class path: $classPath" )
433427
434428 val parentInspector = new AsmTestRunner .ParentInspector (classPath)
435- val frameworkName0 : String = testFrameworkOpt match {
436- case Some (fw ) => fw
437- case None => value(frameworkNames(classPath, parentInspector)).head
429+ val foundFrameworkNames : List [ String ] = testFrameworkOpt match {
430+ case some @ Some (_ ) => some.toList
431+ case None => value(frameworkNames(classPath, parentInspector)).toList
438432 }
439433
440434 val res =
441435 try {
442- adapter = new TestAdapter (jsEnv, inputs, adapterConfig)
436+ adapter = new ScalaJsTestAdapter (jsEnv, inputs, adapterConfig)
443437
444- val frameworks = adapter.loadFrameworks(List (List (frameworkName0))).flatten
438+ val loadedFrameworks =
439+ adapter
440+ .loadFrameworks(foundFrameworkNames.map(List (_)))
441+ .flatten
442+ .distinctBy(_.name())
445443
446- if (frameworks.isEmpty)
447- Left (new NoFrameworkFoundByBridgeError )
448- else if (frameworks.length > 1 )
449- Left (new TooManyFrameworksFoundByBridgeError )
450- else {
451- val framework = frameworks.head
452- runTests(classPath, Seq (framework), requireTests, args, parentInspector)
453- }
444+ val finalTestFrameworks =
445+ loadedFrameworks
446+ .filter(
447+ ! _.name().toLowerCase.contains(" junit" ) ||
448+ ! loadedFrameworks.exists(_.name().toLowerCase.contains(" munit" ))
449+ )
450+ if finalTestFrameworks.nonEmpty then
451+ logger.log(
452+ s """ Final list of test frameworks found:
453+ | - ${finalTestFrameworks.map(_.description).mkString(" \n - " )}
454+ | """ .stripMargin
455+ )
456+
457+ if finalTestFrameworks.isEmpty then Left (new NoFrameworkFoundByBridgeError )
458+ else runTests(classPath, finalTestFrameworks, requireTests, args, parentInspector)
454459 }
455- finally if ( adapter != null ) adapter.close()
460+ finally if adapter != null then adapter.close()
456461
457- if (value(res)) 0
458- else 1
462+ if value(res) then 0 else 1
459463 }
460464
461465 def testNative (
@@ -466,9 +470,6 @@ object Runner {
466470 args : Seq [String ],
467471 logger : Logger
468472 ): Either [TestError , Int ] = either {
469-
470- import scala .scalanative .testinterface .adapter .TestAdapter
471-
472473 logger.debug(s " Native tests class path: $classPath" )
473474
474475 val parentInspector = new AsmTestRunner .ParentInspector (classPath)
@@ -477,16 +478,16 @@ object Runner {
477478 case None => value(frameworkNames(classPath, parentInspector)).toList
478479 }
479480
480- val config = TestAdapter .Config ()
481+ val config = ScalaNativeTestAdapter .Config ()
481482 .withBinaryFile(launcher)
482- .withEnvVars(sys.env.toMap )
483+ .withEnvVars(sys.env)
483484 .withLogger(logger.scalaNativeTestLogger)
484485
485- var adapter : TestAdapter = null
486+ var adapter : ScalaNativeTestAdapter = null
486487
487488 val res =
488489 try {
489- adapter = new TestAdapter (config)
490+ adapter = new ScalaNativeTestAdapter (config)
490491
491492 val loadedFrameworks =
492493 adapter
0 commit comments