Skip to content

Commit

Permalink
Merge pull request #529 from armanbilge/feature/jsdom
Browse files Browse the repository at this point in the history
Add support for JSDOM to JSIO
  • Loading branch information
valencik authored Jun 7, 2022
2 parents fbacb92 + 49f2baf commit 64fee65
Show file tree
Hide file tree
Showing 8 changed files with 1,603 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ updates:
directory: "/"
schedule:
interval: "monthly"

- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "monthly"
14 changes: 12 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ jobs:
GOOGLE_APPLICATION_CREDENTIALS_JSON:
${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}
js:
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -35,6 +33,18 @@ jobs:
${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
GOOGLE_APPLICATION_CREDENTIALS_JSON:
${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}
jsdom:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: olafurpg/setup-scala@v13
- run: npm install
- run: sbt +testsJS/test
env:
GOOGLE_APPLICATION_CREDENTIALS:
${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
GOOGLE_APPLICATION_CREDENTIALS_JSON:
${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}
native:
runs-on: ubuntu-latest
steps:
Expand Down
14 changes: 13 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,19 @@ lazy val tests = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.nativeConfigure(sharedNativeConfigure)
.nativeSettings(sharedNativeSettings)
.jsConfigure(sharedJSConfigure)
.jsSettings(sharedJSSettings)
.jsSettings(
sharedJSSettings,
jsEnv := {
val log = sLog.value
if (Option(System.getenv("GITHUB_JOB")).contains("jsdom")) {
log.info("Testing in JSDOMNodeJSEnv")
new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv
} else {
log.info("Testing in NodeJSEnv")
new org.scalajs.jsenv.nodejs.NodeJSEnv
}
}
)
.jvmSettings(
sharedJVMSettings,
fork := true,
Expand Down
6 changes: 5 additions & 1 deletion munit/js/src/main/scala/munit/internal/io/JSIO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import scala.util.Try
object JSIO {

private def require(module: String): Option[js.Dynamic] = {
Try(js.Dynamic.global.require(module)).toOption
Try(js.Dynamic.global.require(module)) // Node.js
.orElse( // JSDOM
Try(js.Dynamic.global.Node.constructor("return require")()(module))
)
.toOption
}
val process: Option[js.Dynamic] = require("process")
val path: Option[js.Dynamic] = require("path")
Expand Down
Loading

0 comments on commit 64fee65

Please sign in to comment.