-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
217 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
.metals | ||
.bsp | ||
.vscode | ||
native | ||
native | ||
testDir |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import scala.compiletime.uninitialized | ||
import com.microsoft.playwright.* | ||
import com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat | ||
import com.sun.net.httpserver.*; | ||
import java.net.InetSocketAddress; | ||
import com.microsoft.playwright.Page.InputValueOptions | ||
import com.sun.net.httpserver.SimpleFileServer | ||
import java.nio.file.Paths | ||
import com.microsoft.playwright.impl.driver.Driver | ||
import scala.concurrent.Future | ||
|
||
import cats.effect.unsafe.implicits.global | ||
|
||
/* | ||
Run | ||
cs launch com.microsoft.playwright:playwright:1.41.1 -M "com.microsoft.playwright.CLI" -- install --with-deps | ||
before this test, to make sure that the driver bundles are downloaded. | ||
*/ | ||
class PlaywrightTest extends munit.FunSuite: | ||
|
||
val port = 8080 | ||
var pw: Playwright = uninitialized | ||
var browser: Browser = uninitialized | ||
var page: Page = uninitialized | ||
|
||
val testDir = os.pwd / "testDir" | ||
val outDir = testDir / ".out" | ||
|
||
override def beforeAll(): Unit = | ||
|
||
pw = Playwright.create() | ||
browser = pw.chromium().launch(); | ||
page = browser.newPage(); | ||
end beforeAll | ||
|
||
test("incremental") { | ||
|
||
if os.exists(testDir) then os.remove.all(os.pwd / "testDir") | ||
os.makeDir.all(outDir) | ||
|
||
os.write.over(testDir / "hello.scala", helloWorldCode("Hello")) | ||
os.write.over(testDir / ".out" / "styles.less", "") | ||
|
||
LiveServer | ||
.run( | ||
List( | ||
testDir.toString, | ||
outDir.toString | ||
) | ||
) | ||
.unsafeToFuture() | ||
|
||
Thread.sleep(500) // give the thing time to start. | ||
|
||
page.navigate(s"http://localhost:8085/index.html") | ||
assertThat(page.locator("h1")).containsText("HelloWorld"); | ||
|
||
os.write.over(testDir / "hello.scala", helloWorldCode("Bye")) | ||
assertThat(page.locator("h1")).containsText("ByeWorld"); | ||
|
||
os.write.append(testDir / ".out" / "styles.less", "h1 { color: red; }") | ||
assertThat(page.locator("h1")).hasCSS("color", "rgb(255, 0, 0)") | ||
|
||
} | ||
|
||
override def afterAll(): Unit = | ||
super.afterAll() | ||
pw.close() | ||
// os.remove.all(testDir) | ||
|
||
end afterAll | ||
|
||
end PlaywrightTest | ||
|
||
def helloWorldCode(greet: String) = s""" | ||
//> using scala 3.3.3 | ||
//> using platform js | ||
|
||
//> using dep org.scala-js::scalajs-dom::2.8.0 | ||
//> using dep com.raquo::laminar::17.0.0-M6 | ||
|
||
//> using jsModuleKind es | ||
//> using jsModuleSplitStyleStr smallmodulesfor | ||
//> using jsSmallModuleForPackage webapp | ||
|
||
package webapp | ||
|
||
import org.scalajs.dom | ||
import org.scalajs.dom.document | ||
import com.raquo.laminar.api.L.{*, given} | ||
|
||
@main | ||
def main: Unit = | ||
renderOnDomContentLoaded( | ||
dom.document.getElementById("app"), | ||
interactiveApp | ||
) | ||
|
||
def interactiveApp = | ||
val hiVar = Var("World") | ||
div( | ||
h1( | ||
"$greet", | ||
child.text <-- hiVar.signal | ||
), | ||
p("This is a simple example of a Laminar app."), | ||
// https://demo.laminar.dev/app/form/controlled-inputs | ||
input( | ||
typ := "text", | ||
controlled( | ||
value <-- hiVar.signal, | ||
onInput.mapToValue --> hiVar.writer | ||
) | ||
) | ||
) | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# An experiment in a dev server for scala JS | ||
|
||
Try and break the dependance on node / npm completely whilst retaining a sane developer experience for browser based scala-js development. | ||
|
||
## Goals | ||
- Live reload / link on change | ||
- Hot application of style (no page reload) | ||
- Proxy server (TODO) | ||
|
||
## Contraints | ||
|
||
- Scala cli to build frontend | ||
- ESModule output (only) | ||
- Third party ESModules via import map rather than npm | ||
- Styles through LESS | ||
|
||
## Quickstart | ||
|
||
```sh | ||
|
||
``` |