@@ -89,36 +89,36 @@ trait PlaywrightTest extends CatsEffectSuite:
8989 }
9090 .toResource
9191
92- val externalHtmlStyles = IO {
93- val tempDir = os.temp.dir()
94- val staticDir = tempDir / " assets"
95- os.makeDir(staticDir)
96- os.write.over(tempDir / " hello.scala" , helloWorldCode(" Hello" ))
97- os.write.over(staticDir / " index.less" , " h1{color:red}" )
98- os.write.over(staticDir / " index.html" , vanillaTemplate(true ).render)
99- (tempDir, staticDir)
100- }.flatTap{
92+ val externalHtmlStyles = IO {
93+ val tempDir = os.temp.dir()
94+ val staticDir = tempDir / " assets"
95+ os.makeDir(staticDir)
96+ os.write.over(tempDir / " hello.scala" , helloWorldCode(" Hello" ))
97+ os.write.over(staticDir / " index.less" , " h1{color:red}" )
98+ os.write.over(staticDir / " index.html" , vanillaTemplate(true ).render)
99+ (tempDir, staticDir)
100+ }.flatTap {
101101 tempDir =>
102- IO .blocking(os.proc(" scala-cli" , " compile" , tempDir._1.toString).call(cwd = tempDir._1))
103- }.toResource
104-
102+ IO .blocking(os.proc(" scala-cli" , " compile" , tempDir._1.toString).call(cwd = tempDir._1))
103+ }
104+ .toResource
105105
106106 val client = EmberClientBuilder .default[IO ].build
107107
108108 val backendPort = 8999
109109
110110 val simpleBackend = EmberServerBuilder
111- .default[IO ]
112- .withHttpApp(
113- HttpRoutes
114- .of[IO ] {
115- case GET -> Root / " api" / " hello" =>
116- Ok (" hello world" )
117- }
118- .orNotFound
119- )
120- .withPort(Port .fromInt(backendPort).get)
121- .build
111+ .default[IO ]
112+ .withHttpApp(
113+ HttpRoutes
114+ .of[IO ] {
115+ case GET -> Root / " api" / " hello" =>
116+ Ok (" hello world" )
117+ }
118+ .orNotFound
119+ )
120+ .withPort(Port .fromInt(backendPort).get)
121+ .build
122122
123123 ResourceFunFixture {
124124 files.flatMap {
@@ -138,7 +138,7 @@ trait PlaywrightTest extends CatsEffectSuite:
138138 increaseTimeout.setTimeout(15000 )
139139 IO .sleep(3 .seconds) >>
140140 IO (page.navigate(s " http://localhost: $port" )) >>
141- IO (assertThat(page.locator(" h1" )).containsText(" HelloWorld" , increaseTimeout)) >>
141+ IO (assertThat(page.locator(" h1" )).containsText(" HelloWorld" , increaseTimeout)) >>
142142 IO .blocking(os.write.over(testDir / " hello.scala" , helloWorldCode(" Bye" ))) >>
143143 IO (assertThat(page.locator(" h1" )).containsText(" ByeWorld" , increaseTimeout)) >>
144144 IO .blocking(os.write.append(styleDir(testDir) / " index.less" , " h1 { color: red; }" )) >>
@@ -183,78 +183,81 @@ trait PlaywrightTest extends CatsEffectSuite:
183183 proxyPortTarget = Port .fromInt(backendPort),
184184 proxyPathMatchPrefix = Some (" /api" )
185185 )
186-
187- simpleBackend.flatMap{ _ =>
188- LiveServer .main(lsc).map(_ => (lsc.port, client))
186+
187+ simpleBackend.flatMap {
188+ _ =>
189+ LiveServer .main(lsc).map(_ => (lsc.port, client))
189190 }
190191 }
191192 }.test(" proxy server forwards to a backend server" ) {
192- (port, client) =>
193-
193+ (port, client) =>
194194 assertIO(
195195 client.status(org.http4s.Request [IO ](Method .GET , Uri .unsafeFromString(s " http://localhost: $port/api/hello " ))),
196196 Ok
197- ) >>
198- assertIO(
199- client.expect[String ](s " http://localhost: $port/api/hello " ),
200- " hello world"
201197 ) >>
202- assertIO(
203- client.status(org.http4s.Request [IO ](Method .GET , Uri .unsafeFromString(s " http://localhost: $port/api/nope " ))),
204- NotFound
205- )
198+ assertIO(
199+ client.expect[String ](s " http://localhost: $port/api/hello " ),
200+ " hello world"
201+ ) >>
202+ assertIO(
203+ client.status(org.http4s.Request [IO ](Method .GET , Uri .unsafeFromString(s " http://localhost: $port/api/nope " ))),
204+ NotFound
205+ )
206206 }
207207
208- ResourceFunFixture {externalHtmlStyles.both(client).flatMap{
209- case ((dir, extHtmlDir), client) =>
210- println(dir)
211- println(extHtmlDir)
212- val lsc = LiveServerConfig (
213- baseDir = Some (dir.toString),
214- indexHtmlTemplate = Some (extHtmlDir.toString),
215- port = Port .fromInt(basePort).get,
216- openBrowserAt = " " ,
217- preventBrowserOpen = true ,
218- proxyPortTarget = Port .fromInt(backendPort),
219- proxyPathMatchPrefix = Some (" /api" ),
220- clientRoutingPrefix = Some (" /app" ),
221- logLevel = " info"
222- )
208+ ResourceFunFixture {
209+ externalHtmlStyles
210+ .both(client)
211+ .flatMap {
212+ case ((dir, extHtmlDir), client) =>
213+ println(dir)
214+ println(extHtmlDir)
215+ val lsc = LiveServerConfig (
216+ baseDir = Some (dir.toString),
217+ indexHtmlTemplate = Some (extHtmlDir.toString),
218+ port = Port .fromInt(basePort).get,
219+ openBrowserAt = " " ,
220+ preventBrowserOpen = true ,
221+ proxyPortTarget = Port .fromInt(backendPort),
222+ proxyPathMatchPrefix = Some (" /api" ),
223+ clientRoutingPrefix = Some (" /app" ),
224+ logLevel = " info"
225+ )
223226
224- simpleBackend.flatMap{ _ =>
225- LiveServer .main(lsc).map(_ => (lsc.port, client))
226- }
227- }
227+ simpleBackend.flatMap {
228+ _ =>
229+ LiveServer .main(lsc).map(_ => (lsc.port, client))
230+ }
231+ }
228232 }.test(" proxy server and SPA client apps" ) {
229233 (port, client) =>
230234 assertIO(
231235 client.status(org.http4s.Request [IO ](Method .GET , Uri .unsafeFromString(s " http://localhost: $port/api/hello " ))),
232236 Ok
233- ) >>
234- assertIO(
235- client.expect[String ](s " http://localhost: $port/api/hello " ),
236- " hello world"
237- ) >>
238- assertIO(
239- client.status(org.http4s.Request [IO ](Method .GET , Uri .unsafeFromString(s " http://localhost: $port/api/nope " ))),
240- NotFound
241- ) >>
242- assertIO(
243- client.status(org.http4s.Request [IO ](Method .GET , Uri .unsafeFromString(s " http://localhost: $port" ))),
244- Ok
245237 ) >>
246- assertIO(
247- client.expect[String ](s " http://localhost: $port" ),
248- vanillaTemplate(true ).render
249- ) >>
250- assertIO(
251- client.expect[String ](s " http://localhost: $port/app/spaRoute " ),
252- vanillaTemplate(true ).render
253- )
238+ assertIO(
239+ client.expect[String ](s " http://localhost: $port/api/hello " ),
240+ " hello world"
241+ ) >>
242+ assertIO(
243+ client.status(org.http4s.Request [IO ](Method .GET , Uri .unsafeFromString(s " http://localhost: $port/api/nope " ))),
244+ NotFound
245+ ) >>
246+ assertIO(
247+ client.status(org.http4s.Request [IO ](Method .GET , Uri .unsafeFromString(s " http://localhost: $port" ))),
248+ Ok
249+ ) >>
250+ assertIO(
251+ client.expect[String ](s " http://localhost: $port" ),
252+ vanillaTemplate(true ).render
253+ ) >>
254+ assertIO(
255+ client.expect[String ](s " http://localhost: $port/app/spaRoute " ),
256+ vanillaTemplate(true ).render
257+ )
254258
255259 }
256260
257-
258261 ResourceFunFixture {
259262 files.flatMap {
260263 dir =>
@@ -268,12 +271,15 @@ trait PlaywrightTest extends CatsEffectSuite:
268271 }
269272 }.test(" no styles" ) {
270273 client =>
271- assertIO(client.status(org.http4s.Request [IO ](Method .GET , Uri .unsafeFromString(s " http://localhost: $basePort" ))), Ok ) >>
272- assertIOBoolean(client.expect[String ](s " http://localhost: $basePort" ).map(out => ! out.contains(" less" )))
274+ assertIO(
275+ client.status(org.http4s.Request [IO ](Method .GET , Uri .unsafeFromString(s " http://localhost: $basePort" ))),
276+ Ok
277+ ) >>
278+ assertIOBoolean(client.expect[String ](s " http://localhost: $basePort" ).map(out => ! out.contains(" less" )))
273279 }
274280
275281 ResourceFunFixture {
276- files.flatMap {
282+ files.flatMap {
277283 dir =>
278284 val lsc = LiveServerConfig (
279285 baseDir = Some (dir.toString),
@@ -283,13 +289,26 @@ trait PlaywrightTest extends CatsEffectSuite:
283289 preventBrowserOpen = true
284290 )
285291 LiveServer .main(lsc).flatMap(_ => client)
286- }
292+ }
287293 }.test(" with styles" ) {
288294 client =>
289- assertIO(client.status(org.http4s.Request [IO ](Method .GET , Uri .unsafeFromString(s " http://localhost: $basePort" ))), Ok ) >>
290- assertIOBoolean(client.expect[String ](s " http://localhost: $basePort" ).map(out => out.contains(" src=\" https://cdn.jsdelivr.net/npm/less" ))) >>
291- assertIOBoolean(client.expect[String ](s " http://localhost: $basePort" ).map(out => out.contains(" less.watch()" ))) >>
292- assertIO(client.status(org.http4s.Request [IO ](Method .GET , Uri .unsafeFromString(s " http://localhost: $basePort/index.less " ))), Ok )
295+ assertIO(
296+ client.status(org.http4s.Request [IO ](Method .GET , Uri .unsafeFromString(s " http://localhost: $basePort" ))),
297+ Ok
298+ ) >>
299+ assertIOBoolean(
300+ client
301+ .expect[String ](s " http://localhost: $basePort" )
302+ .map(out => out.contains(" src=\" https://cdn.jsdelivr.net/npm/less" ))
303+ ) >>
304+ assertIOBoolean(
305+ client.expect[String ](s " http://localhost: $basePort" ).map(out => out.contains(" less.watch()" ))
306+ ) >>
307+ assertIO(
308+ client
309+ .status(org.http4s.Request [IO ](Method .GET , Uri .unsafeFromString(s " http://localhost: $basePort/index.less " ))),
310+ Ok
311+ )
293312 }
294313
295314 override def afterAll (): Unit =
0 commit comments