Skip to content

Commit 43025e0

Browse files
authored
test-kit-upgrade (#9)
* scalajs-js-envs-test-kit upgraded 1.4.0 * formatting * formatting and scalafixAll * formatting and scalafixAll * formatting and scalafixAll
1 parent c286eb4 commit 43025e0

18 files changed

+507
-364
lines changed

.scalafix.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rules = [OrganizeImports]
2+
3+
OrganizeImports.removeUnused = false

.scalafmt.conf

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,63 @@
1-
version = "3.7.15"
2-
runner.dialect = scala3
1+
version = 3.7.17
2+
3+
runner.dialect = scala3
4+
5+
maxColumn = 96
6+
7+
includeCurlyBraceInSelectChains = true
8+
includeNoParensInSelectChains = true
9+
10+
optIn {
11+
breakChainOnFirstMethodDot = false
12+
forceBlankLineBeforeDocstring = true
13+
}
14+
15+
binPack {
16+
literalArgumentLists = true
17+
parentConstructors = Never
18+
}
19+
20+
danglingParentheses {
21+
defnSite = false
22+
callSite = false
23+
ctrlSite = false
24+
25+
exclude = []
26+
}
27+
28+
newlines {
29+
beforeCurlyLambdaParams = multilineWithCaseOnly
30+
afterCurlyLambda = squash
31+
implicitParamListModifierPrefer = before
32+
sometimesBeforeColonInMethodReturnType = true
33+
}
34+
35+
align.preset = none
36+
align.stripMargin = true
37+
38+
assumeStandardLibraryStripMargin = true
39+
40+
docstrings {
41+
style = Asterisk
42+
oneline = unfold
43+
}
44+
45+
project.git = true
46+
47+
trailingCommas = never
48+
49+
rewrite {
50+
// RedundantBraces honestly just doesn't work, otherwise I'd love to use it
51+
rules = [PreferCurlyFors, RedundantParens, SortImports]
52+
53+
redundantBraces {
54+
maxLines = 1
55+
stringInterpolation = true
56+
}
57+
}
58+
59+
rewriteTokens {
60+
"⇒": "=>"
61+
"→": "->"
62+
"←": "<-"
63+
}

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ lazy val root = (project in file("."))
4141
"com.google.jimfs" % "jimfs" % "1.2",
4242
"com.outr" %% "scribe" % "3.13.0",
4343
"org.typelevel" %% "cats-effect" % "3.5.2",
44-
"org.scala-js" %% "scalajs-js-envs-test-kit" % "1.1.1" % Test,
44+
"org.scala-js" %% "scalajs-js-envs-test-kit" % "1.4.0" % Test,
4545
"com.novocode" % "junit-interface" % "0.11" % Test
4646
),
4747
releaseProcess := Seq[ReleaseStep](
@@ -65,7 +65,7 @@ lazy val root = (project in file("."))
6565
},
6666
// For all Sonatype accounts created on or after February 2021
6767
sonatypeCredentialHost := "s01.oss.sonatype.org",
68-
Test / parallelExecution := false,
68+
Test / parallelExecution := true,
6969
Test / publishArtifact := false,
7070
usePgpKeyHex("F7E440260BAE93EB4AD2723D6613CA76E011F638")
7171
)

project/plugins.sbt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
val sbtTypelevelVersion = "0.6.4"
12
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.1")
23
addSbtPlugin("com.github.sbt" % "sbt-release" % "1.3.0")
34
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1")
45
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.10.0")
56
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9")
7+
addSbtPlugin("org.typelevel" % "sbt-typelevel" % sbtTypelevelVersion)
8+
addSbtPlugin("org.typelevel" % "sbt-typelevel-scalafix" % sbtTypelevelVersion)
9+
addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % sbtTypelevelVersion)

src/main/java/jsenv/DriverJar.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void extractDriverToTempDir() throws URISyntaxException, IOException {
129129
URI uri = maybeExtractNestedJar(originalUri);
130130

131131
// Create zip filesystem if loading from jar.
132-
try (FileSystem fileSystem = "jar".equals(uri.getScheme()) ? initFileSystem(uri) : null) {
132+
FileSystem fileSystem = "jar".equals(uri.getScheme()) ? initFileSystem(uri) : null;
133133
Path srcRoot = Paths.get(uri);
134134
// jar file system's .relativize gives wrong results when used with
135135
// spring-boot-maven-plugin, convert to the default filesystem to
@@ -159,6 +159,8 @@ void extractDriverToTempDir() throws URISyntaxException, IOException {
159159
throw new RuntimeException("Failed to extract driver from " + uri + ", full uri: " + originalUri, e);
160160
}
161161
});
162+
if (fileSystem != null) {
163+
fileSystem.close();
162164
}
163165
}
164166

@@ -173,7 +175,8 @@ private URI maybeExtractNestedJar(final URI uri) throws URISyntaxException {
173175
}
174176
String innerJar = String.join(JAR_URL_SEPARATOR, parts[0], parts[1]);
175177
URI jarUri = new URI(innerJar);
176-
try (FileSystem fs = FileSystems.newFileSystem(jarUri, Collections.emptyMap())) {
178+
try {
179+
FileSystem fs = FileSystems.newFileSystem(jarUri, Collections.emptyMap());
177180
Path fromPath = Paths.get(jarUri);
178181
Path toPath = driverTempDir.resolve(fromPath.getFileName().toString());
179182
Files.copy(fromPath, toPath);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package jsenv.playwright
2+
3+
import cats.effect.IO
4+
import cats.effect.unsafe.implicits.global
5+
import jsenv.playwright.PWEnv.Config
6+
import org.scalajs.jsenv.Input
7+
import org.scalajs.jsenv.JSComRun
8+
import org.scalajs.jsenv.RunConfig
9+
10+
import scala.concurrent._
11+
12+
// browserName, headless, pwConfig, runConfig, input, onMessage
13+
class CEComRun(
14+
override val browserName: String,
15+
override val headless: Boolean,
16+
override val pwConfig: Config,
17+
override val runConfig: RunConfig,
18+
override val input: Seq[Input],
19+
onMessage: String => Unit
20+
) extends JSComRun
21+
with Runner {
22+
scribe.debug(s"Creating CEComRun for $browserName")
23+
// enableCom is false for CERun and true for CEComRun
24+
// send is called only from JSComRun
25+
override def send(msg: String): Unit = sendQueue.offer(msg)
26+
// receivedMessage is called only from JSComRun. Hence its implementation is empty in CERun
27+
override protected def receivedMessage(msg: String): Unit = onMessage(msg)
28+
29+
lazy val future: Future[Unit] =
30+
jsRunPrg(browserName, headless, isComEnabled = true, None)
31+
.use(_ => IO.unit)
32+
.unsafeToFuture()
33+
34+
}
35+
36+
private class WindowOnErrorException(errs: List[String]) extends Exception(s"JS error: $errs")
Lines changed: 14 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,152 +1,27 @@
11
package jsenv.playwright
22

3+
import cats.effect.IO
34
import cats.effect.unsafe.implicits.global
4-
import cats.effect.{IO, Resource}
5-
import com.microsoft.playwright.BrowserType.LaunchOptions
65
import jsenv.playwright.PWEnv.Config
7-
import jsenv.playwright.PageFactory._
8-
import jsenv.playwright.ResourcesFactory._
9-
import org.scalajs.jsenv.{Input, JSComRun, JSRun, RunConfig}
6+
import org.scalajs.jsenv.Input
7+
import org.scalajs.jsenv.JSRun
8+
import org.scalajs.jsenv.RunConfig
109

11-
import java.util.concurrent.ConcurrentLinkedQueue
12-
import java.util.concurrent.atomic.AtomicBoolean
1310
import scala.concurrent._
14-
import scala.concurrent.duration.DurationInt
1511

1612
class CERun(
17-
browserName: String,
18-
headless: Boolean,
19-
pwConfig: Config,
20-
runConfig: RunConfig,
21-
input: Seq[Input]
22-
) extends JSRun {
23-
24-
implicit val ec: scala.concurrent.ExecutionContext =
25-
scala.concurrent.ExecutionContext.global
26-
27-
// enableCom is false for CERun and true for CEComRun
28-
protected val enableCom = false
29-
protected val intf = "this.scalajsPlayWrightInternalInterface"
30-
protected val sendQueue = new ConcurrentLinkedQueue[String]
31-
// receivedMessage is called only from JSComRun. Hence its implementation is empty in CERun
32-
protected def receivedMessage(msg: String): Unit = ()
33-
34-
/** A Future that completes if the run completes.
35-
*
36-
* The future is failed if the run fails.
37-
*
38-
* Note that a JSRun is not required to ever terminate on it's own. That
39-
* means even if all code is executed and the event loop is empty, the run
40-
* may continue to run. As a consequence, it is *not* correct to rely on
41-
* termination of a JSRun without any external means of stopping it (i.e.
42-
* calling [[close]]).
43-
*/
44-
var wantToClose = new AtomicBoolean(false)
45-
// List of programs
46-
// 1. isInterfaceUp()
47-
// Create PW resource if not created. Create browser,context and page
48-
// 2. Sleep
49-
// 3. wantClose
50-
// 4. sendAll()
51-
// 5. fetchAndProcess()
52-
// 6. Close diver
53-
// 7. Close streams
54-
// 8. Close materializer
55-
// Flow
56-
// if interface is down and dont want to close wait for 100 milliseconds
57-
// interface is up and dont want to close sendAll(), fetchAndProcess() Sleep for 100 milliseconds
58-
// If want to close then close driver, streams, materializer
59-
// After future is completed close driver, streams, materializer
60-
61-
def jsRunPrg(
62-
browserName: String,
63-
headless: Boolean,
64-
isComEnabled: Boolean,
65-
launchOptions: Option[LaunchOptions]
66-
): Resource[IO, Unit] = for {
67-
_ <- Resource.pure(
68-
scribe.info(
69-
s"Begin Main with isComEnabled $isComEnabled " +
70-
s"and browserName $browserName " +
71-
s"and headless is $headless "
72-
)
73-
)
74-
pageInstance <- createPage(
75-
browserName,
76-
headless,
77-
launchOptions
78-
)
79-
_ <- preparePageForJsRun(
80-
pageInstance,
81-
materializer(pwConfig),
82-
input,
83-
isComEnabled
84-
)
85-
connectionReady <- isConnectionUp(pageInstance, intf)
86-
_ <-
87-
if (!connectionReady) Resource.pure[IO, Unit](IO.sleep(100.milliseconds))
88-
else Resource.pure[IO, Unit](IO.unit)
89-
_ <- isConnectionUp(pageInstance, intf)
90-
out <- outputStream(runConfig)
91-
_ <- processUntilStop(
92-
wantToClose,
93-
pageInstance,
94-
intf,
95-
sendQueue,
96-
out,
97-
receivedMessage,
98-
isComEnabled
99-
)
100-
} yield ()
101-
13+
override val browserName: String,
14+
override val headless: Boolean,
15+
override val pwConfig: Config,
16+
override val runConfig: RunConfig,
17+
override val input: Seq[Input]
18+
) extends JSRun
19+
with Runner {
20+
scribe.debug(s"Creating CERun for $browserName")
10221
lazy val future: Future[Unit] =
103-
jsRunPrg(browserName, headless, enableCom, None)
22+
jsRunPrg(browserName, headless, isComEnabled = false, None)
10423
.use(_ => IO.unit)
10524
.unsafeToFuture()
10625

107-
/** Stops the run and releases all the resources.
108-
*
109-
* This <strong>must</strong> be called to ensure the run's resources are
110-
* released.
111-
*
112-
* Whether or not this makes the run fail or not is up to the implementation.
113-
* However, in the following cases, calling [[close]] may not fail the run:
114-
* <ul> <li>[[future]] is already completed when [[close]] is called.
115-
* <li>This is a [[CERun]] and the event loop inside the VM is empty.
116-
* </ul>
117-
*
118-
* Idempotent, async, nothrow.
119-
*/
120-
121-
override def close(): Unit = {
122-
wantToClose.set(true)
123-
scribe.info(s"StopSignal is ${wantToClose.get()}")
124-
}
125-
26+
override protected def receivedMessage(msg: String): Unit = ()
12627
}
127-
// browserName, headless, pwConfig, runConfig, input, onMessage
128-
class CEComRun(
129-
browserName: String,
130-
headless: Boolean,
131-
pwConfig: Config,
132-
runConfig: RunConfig,
133-
input: Seq[Input],
134-
onMessage: String => Unit
135-
) extends CERun(
136-
browserName,
137-
headless,
138-
pwConfig,
139-
runConfig,
140-
input
141-
)
142-
with JSComRun {
143-
// enableCom is false for CERun and true for CEComRun
144-
override protected val enableCom = true
145-
// send is called only from JSComRun
146-
override def send(msg: String): Unit = sendQueue.offer(msg)
147-
// receivedMessage is called only from JSComRun. Hence its implementation is empty in CERun
148-
override protected def receivedMessage(msg: String): Unit = onMessage(msg)
149-
}
150-
151-
private class WindowOnErrorException(errs: List[String])
152-
extends Exception(s"JS error: $errs")

src/main/scala/jsenv/playwright/CEUtils.scala

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
package jsenv.playwright
22

3-
import org.scalajs.jsenv.{Input, UnsupportedInputException}
4-
import scribe.format.{FormatterInterpolator, dateFull, level, mdc, messages, methodName, threadName}
3+
import org.scalajs.jsenv.Input
4+
import org.scalajs.jsenv.UnsupportedInputException
5+
import scribe.format.FormatterInterpolator
6+
import scribe.format.classNameSimple
7+
import scribe.format.dateFull
8+
import scribe.format.level
9+
import scribe.format.mdc
10+
import scribe.format.messages
11+
import scribe.format.methodName
12+
import scribe.format.threadName
513

614
import java.nio.file.Path
715

@@ -12,6 +20,8 @@ object CEUtils {
1220
): String = {
1321
val tags = fullInput.map {
1422
case Input.Script(path) => makeTag(path, "text/javascript", materializer)
23+
case Input.CommonJSModule(path) =>
24+
makeTag(path, "text/javascript", materializer)
1525
case Input.ESModule(path) => makeTag(path, "module", materializer)
1626
case _ => throw new UnsupportedInputException(fullInput)
1727
}
@@ -36,8 +46,10 @@ object CEUtils {
3646

3747
def setupLogger(showLogs: Boolean, debug: Boolean): Unit = {
3848
val formatter =
39-
formatter"$dateFull [$threadName] $level $methodName - $messages$mdc"
40-
scribe.Logger.root
49+
formatter"$dateFull [$threadName] $classNameSimple $level $methodName - $messages$mdc"
50+
scribe
51+
.Logger
52+
.root
4153
.clearHandlers()
4254
.withHandler(
4355
formatter = formatter

0 commit comments

Comments
 (0)