@@ -4,6 +4,7 @@ import coursier.jvm.Execve
4
4
import org .scalajs .jsenv .jsdomnodejs .JSDOMNodeJSEnv
5
5
import org .scalajs .jsenv .nodejs .NodeJSEnv
6
6
import org .scalajs .jsenv .{Input , RunConfig }
7
+ import org .scalajs .testing .adapter .TestAdapter as ScalaJsTestAdapter
7
8
import sbt .testing .{Framework , Status }
8
9
9
10
import java .io .File
@@ -16,6 +17,7 @@ import scala.build.errors.*
16
17
import scala .build .internals .EnvVar
17
18
import scala .build .testrunner .FrameworkUtils .*
18
19
import scala .build .testrunner .{AsmTestRunner , TestRunner }
20
+ import scala .scalanative .testinterface .adapter .TestAdapter as ScalaNativeTestAdapter
19
21
import scala .util .{Failure , Properties , Success }
20
22
21
23
object Runner {
@@ -240,22 +242,20 @@ object Runner {
240
242
sourceMap : Boolean = false ,
241
243
esModule : Boolean = false
242
244
): 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 {
250
250
val command = Seq (nodePath, entrypoint.getAbsolutePath) ++ args
251
251
252
- log(
252
+ logger. log(
253
253
s " Running ${command.mkString(" " )}" ,
254
254
" Running" + System .lineSeparator() +
255
255
command.iterator.map(_ + System .lineSeparator()).mkString
256
256
)
257
257
258
- debug(" execve available" )
258
+ logger. debug(" execve available" )
259
259
Execve .execve(
260
260
command.head,
261
261
" node" +: command.tail.toArray,
@@ -264,40 +264,36 @@ object Runner {
264
264
sys.error(" should not happen" )
265
265
}
266
266
else {
267
-
268
267
val nodeArgs =
269
268
// Scala.js runs apps by piping JS to node.
270
269
// If we need to pass arguments, we must first make the piped input explicit
271
270
// 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
274
272
val envJs =
275
- if ( jsDom)
273
+ if jsDom then
276
274
new JSDOMNodeJSEnv (
277
275
JSDOMNodeJSEnv .Config ()
278
276
.withExecutable(nodePath)
279
277
.withArgs(nodeArgs)
280
278
.withEnv(Map .empty)
281
279
)
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
+ )
289
288
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))
294
291
295
292
val config = RunConfig ().withLogger(logger.scalaJsLogger)
296
293
val processJs = envJs.start(inputs, config)
297
294
298
295
processJs.future.value.foreach {
299
- case Failure (t) =>
300
- throw new Exception (t)
296
+ case Failure (t) => throw new Exception (t)
301
297
case Success (_) =>
302
298
}
303
299
@@ -405,57 +401,65 @@ object Runner {
405
401
): Either [TestError , Int ] = either {
406
402
import org .scalajs .jsenv .Input
407
403
import org .scalajs .jsenv .nodejs .NodeJSEnv
408
- import org .scalajs .testing .adapter .TestAdapter
409
404
val nodePath = findInPath(" node" ).fold(" node" )(_.toString)
410
405
val jsEnv =
411
- if ( jsDom)
406
+ if jsDom then
412
407
new JSDOMNodeJSEnv (
413
408
JSDOMNodeJSEnv .Config ()
414
409
.withExecutable(nodePath)
415
410
.withArgs(Nil )
416
411
.withEnv(Map .empty)
417
412
)
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
431
425
432
426
logger.debug(s " JS tests class path: $classPath" )
433
427
434
428
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
438
432
}
439
433
440
434
val res =
441
435
try {
442
- adapter = new TestAdapter (jsEnv, inputs, adapterConfig)
436
+ adapter = new ScalaJsTestAdapter (jsEnv, inputs, adapterConfig)
443
437
444
- val frameworks = adapter.loadFrameworks(List (List (frameworkName0))).flatten
438
+ val loadedFrameworks =
439
+ adapter
440
+ .loadFrameworks(foundFrameworkNames.map(List (_)))
441
+ .flatten
442
+ .distinctBy(_.name())
445
443
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)
454
459
}
455
- finally if ( adapter != null ) adapter.close()
460
+ finally if adapter != null then adapter.close()
456
461
457
- if (value(res)) 0
458
- else 1
462
+ if value(res) then 0 else 1
459
463
}
460
464
461
465
def testNative (
@@ -466,9 +470,6 @@ object Runner {
466
470
args : Seq [String ],
467
471
logger : Logger
468
472
): Either [TestError , Int ] = either {
469
-
470
- import scala .scalanative .testinterface .adapter .TestAdapter
471
-
472
473
logger.debug(s " Native tests class path: $classPath" )
473
474
474
475
val parentInspector = new AsmTestRunner .ParentInspector (classPath)
@@ -477,16 +478,16 @@ object Runner {
477
478
case None => value(frameworkNames(classPath, parentInspector)).toList
478
479
}
479
480
480
- val config = TestAdapter .Config ()
481
+ val config = ScalaNativeTestAdapter .Config ()
481
482
.withBinaryFile(launcher)
482
- .withEnvVars(sys.env.toMap )
483
+ .withEnvVars(sys.env)
483
484
.withLogger(logger.scalaNativeTestLogger)
484
485
485
- var adapter : TestAdapter = null
486
+ var adapter : ScalaNativeTestAdapter = null
486
487
487
488
val res =
488
489
try {
489
- adapter = new TestAdapter (config)
490
+ adapter = new ScalaNativeTestAdapter (config)
490
491
491
492
val loadedFrameworks =
492
493
adapter
0 commit comments