@@ -30,6 +30,7 @@ class RoutesSuite extends CatsEffectSuite:
3030
3131 val md = MessageDigest .getInstance(" MD5" )
3232 val testStr = " const hi = 'Hello, world'"
33+ val simpleCss = " h1 {color: red;}"
3334 val testHash = md.digest(testStr.getBytes()).map(" %02x" .format(_)).mkString
3435 given filesInstance : Files [IO ] = Files .forAsync[IO ]
3536
@@ -67,14 +68,23 @@ class RoutesSuite extends CatsEffectSuite:
6768 val externalSyles = FunFixture [os.Path ](
6869 setup = test =>
6970 val tempDir = os.temp.dir()
70- os.write(tempDir / " index.less" , testStr )
71+ os.write(tempDir / " index.less" , " h1 {color: red;} " )
7172 tempDir
7273 ,
7374 teardown = tempDir =>
7475 // Always gets called, even if test failed.
7576 os.remove.all(tempDir)
7677 )
7778
79+ override def beforeAll (): Unit =
80+ scribe
81+ .Logger
82+ .root
83+ .clearHandlers()
84+ .clearModifiers()
85+ .withHandler(minimumLevel = Some (Level .get(" trace" ).get))
86+ .replace()
87+
7888 files.test(" seed map puts files in the map on start" ) {
7989 tempDir =>
8090 for
@@ -144,7 +154,7 @@ class RoutesSuite extends CatsEffectSuite:
144154
145155 val app : Resource [IO , HttpApp [IO ]] = for
146156 logger <- IO (
147- aLogger
157+ scribe.cats[ IO ]
148158 ).toResource
149159 fileToHashRef <- Ref [IO ].of(Map .empty[String , String ]).toResource
150160 _ <- updateMapRef(tempDir.toFs2, fileToHashRef)(logger).toResource
@@ -195,7 +205,7 @@ class RoutesSuite extends CatsEffectSuite:
195205 .use {
196206 resp3 =>
197207 assertEquals(resp3.status.code, 200 )
198- assertIOBoolean(resp3.bodyText.compile.string.map(_.contains(" src=\" main.js" ))) >>
208+ assertIOBoolean(resp3.bodyText.compile.string.map(_.contains(" src=\" / main.js" ))) >>
199209 IO .unit
200210 }
201211
@@ -211,17 +221,17 @@ class RoutesSuite extends CatsEffectSuite:
211221 IO .unit
212222 }
213223
214- val requestHtml2 = Request [IO ](uri = uri " / " ).withHeaders(Header .Raw (ci " If-None-Match " , etag))
224+ // val requestHtml2 = Request[IO](uri = uri"/").withHeaders(Header.Raw(ci"If-None-Match", etag))
215225
216- val checkRespHtml2 = client
217- .run(requestHtml2)
218- .use {
219- respH =>
220- assertEquals(respH.status.code, 304 )
221- IO .unit
222- }
226+ // val checkRespHtml2 = client
227+ // .run(requestHtml2)
228+ // .use {
229+ // respH =>
230+ // assertEquals(respH.status.code, 304)
231+ // IO.unit
232+ // }
223233
224- checkResp1 >> checkResp2 >> checkRespSpa >> checkRespHtml >> checkRespHtml2
234+ checkResp1 >> checkResp2 >> checkRespSpa >> checkRespHtml
225235
226236 }
227237 }
@@ -315,7 +325,36 @@ class RoutesSuite extends CatsEffectSuite:
315325 val responseLess = served(requestLess)
316326
317327 assertIO(responseHtml.map(_.status.code), 200 ) >>
318- assertIO(responseLess.map(_.status.code), 200 )
328+ assertIO(responseLess.map(_.status.code), 200 ) >>
329+ assertIO(responseLess.flatMap(_.bodyText.compile.string), simpleCss)
330+ }
331+ }
332+
333+ FunFixture
334+ .map2(files, externalSyles)
335+ .test(" That styles and SPA play nicely together" ) {
336+ (appDir, styleDir) =>
337+ val app = for
338+ logger <- IO (scribe.cats[IO ]).toResource
339+ fileToHashRef <- Ref [IO ].of(Map .empty[String , String ]).toResource
340+ fileToHashMapRef = MapRef .fromSingleImmutableMapRef[IO , String , String ](fileToHashRef)
341+ refreshPub <- Topic [IO , Unit ].toResource
342+ theseRoutes <- routes(
343+ appDir.toString,
344+ refreshPub,
345+ Some (IndexHtmlConfig .StylesOnly (styleDir.toFs2)),
346+ HttpRoutes .empty[IO ],
347+ fileToHashRef,
348+ Some (" app" )
349+ )(logger)
350+ yield theseRoutes.orNotFound
351+
352+ app.use {
353+ served =>
354+ val requestLess = org.http4s.Request [IO ](uri = org.http4s.Uri .unsafeFromString(" /index.less" ))
355+ val responseLess = served(requestLess)
356+ assertIO(responseLess.map(_.status.code), 200 ) >>
357+ assertIO(responseLess.flatMap(_.bodyText.compile.string), simpleCss)
319358 }
320359 }
321360
0 commit comments