1- package io .github .quafadas .millSite
1+ package io .github .quafadas .sjsls
22
33import mill .api .Discover
44import mill .api .Task .Simple
@@ -13,7 +13,7 @@ import utest.*
1313object MemJsTests extends TestSuite :
1414 def tests : Tests = Tests {
1515 test(" Hashed JS files have correct cross-module references" ) {
16- object build extends TestRootModule with io.github.quafadas. InMemoryHashScalaJSModule :
16+ object build extends TestRootModule with InMemoryFastLinkHashScalaJSModule :
1717 override def scalaVersion : Simple [String ] = " 3.8.2"
1818 override def moduleSplitStyle : Simple [ModuleSplitStyle ] =
1919 ModuleSplitStyle .SmallModulesFor (" webapp" )
@@ -32,8 +32,10 @@ object MemJsTests extends TestSuite:
3232
3333 val Right (result) = eval(build.fastLinkJS).runtimeChecked
3434 val report = result.value
35- val outputDir = report.dest.path
36- val files = os.list(outputDir).map(_.last).toSet
35+
36+ // Read from the in-memory map rather than disk.
37+ import scala .jdk .CollectionConverters .*
38+ val files = build.hashedOutputFiles.keySet().asScala.toSet
3739 val jsFiles = files.filter(f => f.endsWith(" .js" ) && ! f.endsWith(" .js.map" ))
3840
3941 // No original (unhashed) JS filename should exist.
@@ -42,10 +44,10 @@ object MemJsTests extends TestSuite:
4244 // No hashed JS filename should contain a hyphen (all "-" must be replaced with "_").
4345 jsFiles.foreach(filename => assert(! filename.contains(" -" )))
4446
45- // Every cross-module import must reference a file that actually exists in the output directory .
47+ // Every cross-module import must reference a file that actually exists in the in-memory map .
4648 jsFiles.foreach {
4749 filename =>
48- val content = os.read(outputDir / filename)
50+ val content = new String (build.hashedOutputFiles.get( filename), " UTF-8 " )
4951 val imports = ContentHashScalaJSModule .parseJsImports(content)
5052 imports.foreach {
5153 importedName =>
@@ -73,7 +75,7 @@ object MemJsTests extends TestSuite:
7375 }
7476
7577 test(" InMemoryHashScalaJSModule fullLinkJS with scalaJSMinify=true produces smaller JS than fastLinkJS" ) {
76- object build extends TestRootModule with io.github.quafadas. InMemoryHashScalaJSModule :
78+ object build extends TestRootModule with InMemoryFastLinkHashScalaJSModule :
7779 override def scalaVersion : Simple [String ] = " 3.8.2"
7880 override def moduleSplitStyle : Simple [ModuleSplitStyle ] =
7981 ModuleSplitStyle .SmallModulesFor (" webapp" )
@@ -90,8 +92,15 @@ object MemJsTests extends TestSuite:
9092 UnitTester (build, resourceFolder / " simple" ).scoped {
9193 eval =>
9294 val Right (fastResult) = eval(build.fastLinkJS).runtimeChecked
93- val fastDir = fastResult.value.dest.path
94- val fastTotalSize = os.list(fastDir).filter(p => os.isFile(p) && p.ext == " js" ).map(os.size).sum
95+ // fastLinkJS stores output in-memory; compute total JS size from hashedOutputFiles.
96+ import scala .jdk .CollectionConverters .*
97+ val fastTotalSize = build
98+ .hashedOutputFiles
99+ .entrySet()
100+ .asScala
101+ .filter(e => e.getKey.endsWith(" .js" ) && ! e.getKey.endsWith(" .js.map" ))
102+ .map(_.getValue.length.toLong)
103+ .sum
95104
96105 val Right (fullResult) = eval(build.fullLinkJS).runtimeChecked
97106 val fullDir = fullResult.value.dest.path
@@ -120,7 +129,7 @@ object MemJsTests extends TestSuite:
120129 }
121130
122131 test(" InMemoryHashScalaJSModule fullLinkJS with scalaJSMinify=false writes hashed files without terser" ) {
123- object build extends TestRootModule with io.github.quafadas. InMemoryHashScalaJSModule :
132+ object build extends TestRootModule with InMemoryFastLinkHashScalaJSModule :
124133 override def scalaVersion : Simple [String ] = " 3.8.2"
125134 override def moduleSplitStyle : Simple [ModuleSplitStyle ] =
126135 ModuleSplitStyle .SmallModulesFor (" webapp" )
0 commit comments