Skip to content

Commit

Permalink
Merge pull request #103 from xuwei-k/playwright-test
Browse files Browse the repository at this point in the history
add playwright test
  • Loading branch information
xuwei-k authored Mar 10, 2024
2 parents e0e46b8 + de7d04a commit 84c62fb
Show file tree
Hide file tree
Showing 9 changed files with 486 additions and 61 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ on:
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
runs-on: "${{ matrix.os }}"
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
os:
- "ubuntu-latest"
- "macos-latest"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand All @@ -29,7 +33,7 @@ jobs:
updateClassifiers
test
copyFilesFull
- if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' && github.repository_owner == 'xuwei-k' }}
- if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' && github.repository_owner == 'xuwei-k' && matrix.os == 'ubuntu-latest' }}
uses: JamesIves/[email protected]
with:
branch: gh-pages
Expand Down
37 changes: 29 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ lazy val commonSettings = Def.settings(

commonSettings

run / fork := true

libraryDependencies += "org.slf4j" % "slf4j-simple" % "2.0.12" % Runtime

lazy val `scalameta-ast` = projectMatrix
.in(file("core"))
.settings(
Expand Down Expand Up @@ -150,9 +146,32 @@ lazy val jsProjectSettings: Def.SettingsDefinition = Def.settings(

val genBuildInfo = taskKey[String]("")

libraryDependencies ++= Seq(
"ws.unfiltered" %% "unfiltered-filter" % "0.12.0",
"ws.unfiltered" %% "unfiltered-jetty" % "0.12.0",
lazy val localServer = project.settings(
commonSettings,
run / fork := true,
run / baseDirectory := (LocalRootProject / baseDirectory).value,
Test / testOptions += Tests.Argument("-oD"),
Test / test := (Test / test).dependsOn(LocalRootProject / copyFilesFull).value,
Test / testOptions ++= {
if (scala.util.Properties.isMac) {
Nil
} else {
Seq(
Tests.Exclude(
Seq(
"scalameta_ast.IntegrationTestWebkit",
)
)
)
}
},
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-simple" % "2.0.12" % Runtime,
"ws.unfiltered" %% "unfiltered-filter" % "0.12.0",
"ws.unfiltered" %% "unfiltered-jetty" % "0.12.0",
"org.scalatest" %%% "scalatest-freespec" % "3.2.18" % Test,
"com.microsoft.playwright" % "playwright" % "1.41.2" % Test,
)
)

val srcDir = (LocalRootProject / baseDirectory).apply(_ / "sources")
Expand Down Expand Up @@ -181,12 +200,14 @@ def cp(
}
}

val copyFilesFull = taskKey[Unit]("")

TaskKey[Unit]("copyFilesFast") := {
cp(metaScalafixCompat, scalafixCompatOutJSDir, fastLinkJS, fastLinkJSOutput).value
cp(metaLatest, latestOutJSDir, fastLinkJS, fastLinkJSOutput).value
}

TaskKey[Unit]("copyFilesFull") := {
copyFilesFull := {
cp(metaScalafixCompat, scalafixCompatOutJSDir, fullLinkJS, fullLinkJSOutput).value
cp(metaLatest, latestOutJSDir, fullLinkJS, fullLinkJSOutput).value
}
Expand Down
57 changes: 57 additions & 0 deletions localServer/src/main/scala/scalameta_ast/LocalServer.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package scalameta_ast

import unfiltered.jetty.Server
import unfiltered.request.Path
import unfiltered.response.HtmlContent
import unfiltered.response.JsContent
import unfiltered.response.JsonContent
import unfiltered.response.NotFound
import unfiltered.response.Ok
import unfiltered.response.ResponseString
import java.io.File
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import scala.annotation.nowarn

@nowarn("msg=a type was inferred to be")
object LocalServer {

def server(log: Boolean): Server = {
unfiltered.jetty.Server.anylocal.plan(
unfiltered.filter.Planify { case Path(p) =>
if (log) {
println(s"${DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(LocalDateTime.now())} ${p}")
}
val f = new File("sources", if (p == "/") "index.html" else s".$p")
if (f.isFile) {
val path = f.toPath
val res = ResponseString(Files.readString(path, StandardCharsets.UTF_8))
p.split('.')
.lastOption
.collect {
case "html" =>
HtmlContent
case "js" =>
JsContent
case "json" =>
JsonContent
}
.map(_ ~> res)
.getOrElse(res)
} else if (p == "/favicon.ico") {
Ok
} else {
NotFound
}
}
)
}

def main(args: Array[String]): Unit = {
server(log = true).run { svr =>
unfiltered.util.Browser.open(svr.portBindings.head.url)
}
}
}
9 changes: 9 additions & 0 deletions localServer/src/test/resources/raw.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Defn.Def(
Nil,
Term.Name("a"),
Nil,
Nil,
None,
Term.Name("b")
)

36 changes: 36 additions & 0 deletions localServer/src/test/resources/semantic.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package fix

import scala.meta.Defn
import scala.meta.Term
import scalafix.Patch
import scalafix.lint.Diagnostic
import scalafix.lint.LintSeverity
import scalafix.v1.SemanticDocument
import scalafix.v1.SemanticRule

class Example extends SemanticRule("Example") {
override def fix(implicit
doc: SemanticDocument
): Patch = {
doc.tree.collect {
case t @ Defn.Def(
Nil,
Term.Name("a"),
Nil,
Nil,
None,
Term.Name("b")
) =>
Patch.lint(
Diagnostic(
id = "",
message = "",
position = t.pos,
explanation = "",
severity = LintSeverity.Warning
)
)
}.asPatch
}
}

36 changes: 36 additions & 0 deletions localServer/src/test/resources/syntactic.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package fix

import scala.meta.Defn
import scala.meta.Term
import scalafix.Patch
import scalafix.lint.Diagnostic
import scalafix.lint.LintSeverity
import scalafix.v1.SyntacticDocument
import scalafix.v1.SyntacticRule

class Example extends SyntacticRule("Example") {
override def fix(implicit
doc: SyntacticDocument
): Patch = {
doc.tree.collect {
case t @ Defn.Def(
Nil,
Term.Name("a"),
Nil,
Nil,
None,
Term.Name("b")
) =>
Patch.lint(
Diagnostic(
id = "",
message = "",
position = t.pos,
explanation = "",
severity = LintSeverity.Warning
)
)
}.asPatch
}
}

12 changes: 12 additions & 0 deletions localServer/src/test/resources/tokens.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Seq(
Token.BOF,
Token.KwDef,
Token.Space,
Token.Ident("a"),
Token.Space,
Token.Equals,
Token.Space,
Token.Ident("b"),
Token.EOF
)

Loading

0 comments on commit 84c62fb

Please sign in to comment.