@@ -23,14 +23,11 @@ import org.scalajs.sbtplugin._
23
23
import org .scalajs .jsenv .JSEnv
24
24
import org .scalajs .jsenv .nodejs .{NodeJSEnv , JSDOMNodeJSEnv }
25
25
26
- import org .scalajs .jsdependencies .sbtplugin .JSDependenciesPlugin
27
- import org .scalajs .jsdependencies .sbtplugin .JSDependenciesPlugin .autoImport ._
28
-
29
26
import ScalaJSPlugin .autoImport ._
30
27
import ExternalCompile .scalaJSExternalCompileSettings
31
28
import Loggers ._
32
29
33
- import org .scalajs .core .tools .io .MemVirtualJSFile
30
+ import org .scalajs .core .tools .io .{ FileVirtualJSFile , MemVirtualJSFile }
34
31
import org .scalajs .core .tools .sem ._
35
32
import org .scalajs .core .tools .json ._
36
33
import org .scalajs .core .tools .linker .ModuleInitializer
@@ -619,41 +616,52 @@ object Build {
619
616
).dependsOn(irProject)
620
617
621
618
lazy val toolsJS : Project = (project in file(" tools/js" )).enablePlugins(
622
- MyScalaJSPlugin ,
623
- JSDependenciesPlugin
619
+ MyScalaJSPlugin
624
620
).settings(
625
621
commonToolsSettings,
626
622
crossVersion := ScalaJSCrossVersion .binary,
627
- resourceGenerators in Test += Def .task {
628
- val base = (resourceManaged in Compile ).value
629
- IO .createDirectory(base)
630
- val outFile = base / " js-test-definitions.js"
631
623
624
+ scalaJSModuleKind in Test :=
625
+ org.scalajs.core.tools.linker.backend.ModuleKind .CommonJSModule ,
626
+
627
+ jsExecutionFiles in Test := {
632
628
val testDefinitions = {
633
629
org.scalajs.build.HTMLRunnerTemplateAccess .renderTestDefinitions(
634
630
(loadedTestFrameworks in testSuite in Test ).value,
635
631
(definedTests in testSuite in Test ).value)
636
632
}
637
633
638
- IO .write(outFile, testDefinitions)
639
- Seq (outFile)
640
- }.taskValue,
634
+ val testDefinitionsFile = {
635
+ new MemVirtualJSFile (" js-test-definitions.js" )
636
+ .withContent(testDefinitions)
637
+ }
638
+
639
+ testDefinitionsFile +: (jsExecutionFiles in Test ).value
640
+ },
641
641
642
- jsDependencies += ProvidedJS / " js-test-definitions.js" % " test" ,
643
- jsDependencies +=
644
- " org.webjars" % " jszip" % " 2.4.0" % " test" / " jszip.min.js" commonJSName " JSZip" ,
642
+ testSuiteJSExecutionFilesSetting,
643
+
644
+ // Give more memory to Node.js, and deactivate source maps
645
+ jsEnv := new NodeJSEnv (args = Seq (" --max_old_space_size=3072" )).withSourceMap(false ),
645
646
646
647
inConfig(Test ) {
647
- // Redefine test to run Node.js and link HelloWorld
648
+ // Redefine test to perform the bootstrap test
648
649
test := {
649
650
if (! jsEnv.value.isInstanceOf [NodeJSEnv ])
650
651
throw new MessageOnlyException (" toolsJS/test must be run with Node.js" )
651
652
652
- /* Collect IR relevant files from the classpath
653
+ /* We'll explicitly `require` our linked file. Find its module, and
654
+ * remove it from the `jsExecutionFiles` to give to the runner.
655
+ */
656
+ val toolsTestModule = scalaJSLinkedFile.value
657
+ val executionFiles =
658
+ jsExecutionFiles.value.filter(_ ne toolsTestModule)
659
+
660
+ /* Collect relevant IR files from the classpath of the test suite.
653
661
* We assume here that the classpath is valid. This is checked by the
654
662
* the scalaJSIR task.
655
663
*/
656
- val cp = Attributed .data(fullClasspath.value)
664
+ val cp = Attributed .data(( fullClasspath in (testSuite, Test )) .value)
657
665
658
666
// Files must be Jars, non-files must be dirs
659
667
val (jars, dirs) = cp.filter(_.exists).partition(_.isFile)
@@ -681,38 +689,43 @@ object Build {
681
689
seqOfStringsToJSArrayCode(unescapedMainMethods)
682
690
}
683
691
684
- val scalaJSEnv = {
692
+ val scalaJSEnvForTestSuite = {
685
693
s """
686
694
{"javaSystemProperties": {
687
- "scalajs.scalaVersion": " ${scalaVersion.value}"
695
+ "scalajs.scalaVersion": " ${scalaVersion.value}",
696
+ "scalajs.testsuite.testtag": "testtag.value",
697
+ "scalajs.nodejs": "true",
698
+ "scalajs.typedarray": "true",
699
+ "scalajs.fastopt-stage": "true",
700
+ "scalajs.modulekind-nomodule": "true"
688
701
}}
689
702
"""
690
703
}
691
704
692
705
val code = {
693
706
s """
694
- var linker = scalajs.QuickLinker;
707
+ var toolsTestModule = require(" ${escapeJS(toolsTestModule.path)}");
708
+ var linker = toolsTestModule.scalajs.QuickLinker;
695
709
var lib = linker.linkTestSuiteNode( $irPaths, $mainMethods);
696
710
697
- var __ScalaJSEnv = $scalaJSEnv;
698
-
711
+ var __ScalaJSEnv = $scalaJSEnvForTestSuite;
699
712
eval("(function() { 'use strict'; " +
700
713
lib + ";" +
701
- "scalajs.TestRunner .runTests();" +
714
+ "scalajs.ConsoleTestRunner .runTests();" +
702
715
"}).call(this);");
703
716
"""
704
717
}
705
718
706
719
val launcher = new MemVirtualJSFile (" Generated launcher file" )
707
720
.withContent(code)
708
721
709
- val runner = jsEnv.value.jsRunner(jsExecutionFiles.value :+ launcher)
722
+ val runner = jsEnv.value.jsRunner(executionFiles :+ launcher)
710
723
711
724
runner.run(sbtLogger2ToolsLogger(streams.value.log), scalaJSConsole.value)
712
725
}
713
726
}
714
727
).withScalaJSCompiler.dependsOn(
715
- library, irProjectJS, testSuite % " test-> test"
728
+ library, irProjectJS, jUnitRuntime % " test"
716
729
)
717
730
718
731
lazy val jsEnvs : Project = (project in file(" js-envs" )).settings(
@@ -1435,9 +1448,17 @@ object Build {
1435
1448
}).value
1436
1449
)
1437
1450
1451
+ def testSuiteJSExecutionFilesSetting : Setting [_] = {
1452
+ jsExecutionFiles in Test := {
1453
+ val resourceDir =
1454
+ (resourceDirectory in (LocalProject (" testSuite" ), Test )).value
1455
+ val f = FileVirtualJSFile (resourceDir / " ScalaJSDefinedTestNatives.js" )
1456
+ f +: (jsExecutionFiles in Test ).value
1457
+ }
1458
+ }
1459
+
1438
1460
lazy val testSuite : Project = (project in file(" test-suite/js" )).enablePlugins(
1439
- MyScalaJSPlugin ,
1440
- JSDependenciesPlugin
1461
+ MyScalaJSPlugin
1441
1462
).settings(
1442
1463
commonSettings,
1443
1464
testTagSettings,
@@ -1453,8 +1474,7 @@ object Build {
1453
1474
scalaJSModuleKind.value != ModuleKind .NoModule )
1454
1475
},
1455
1476
1456
- jsDependencies += ProvidedJS / " ScalaJSDefinedTestNatives.js" % " test" ,
1457
- skip in packageJSDependencies in Test := false ,
1477
+ testSuiteJSExecutionFilesSetting,
1458
1478
1459
1479
scalaJSSemantics ~= (_.withRuntimeClassName(_.fullName match {
1460
1480
case " org.scalajs.testsuite.compiler.ReflectionTest$RenamedTestClass" =>
0 commit comments