Skip to content

Commit

Permalink
Try testing without a bundler, by setting NODE_PATH (#2)
Browse files Browse the repository at this point in the history
Tests can be run without a bundler, by setting NODE_PATH
  • Loading branch information
nafg authored Nov 29, 2022
1 parent 7068e5d commit 73d9f80
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ jobs:
apps: mill

- name: Test
run: mill --no-server --jobs 0 test
run: |
mill --no-server --jobs 1 __.downloadMillTestVersion
mill --no-server --jobs 0 _.test
publish:
runs-on: ubuntu-latest
Expand Down
15 changes: 10 additions & 5 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,22 @@ trait CommonModule extends ScalaModule with CiReleaseModule with ScalafmtModule
)
}

object jsdeps extends CommonModule
object jsdeps extends CommonModule {
object test extends MillIntegrationTestModule {
override def millTestVersion = millVersion()
override def pluginsUnderTest = Seq(jsdeps)
}
}

//noinspection ScalaUnusedSymbol
object millbundler extends CommonModule {
override def moduleDeps = Seq(jsdeps)
override def ivyDeps = Agg(
ivy"com.lihaoyi::geny:1.0.0"
)
}

object test extends MillIntegrationTestModule {
override def millTestVersion = millVersion()
override def pluginsUnderTest = Seq(millbundler)
object test extends MillIntegrationTestModule {
override def millTestVersion = millVersion()
override def pluginsUnderTest = Seq(millbundler)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package io.github.nafg.millbundler.jsdeps

import mill._
import mill.modules.Jvm
import mill.scalajslib.TestScalaJSModule
import mill.scalajslib.api.JsEnvConfig

//noinspection ScalaUnusedSymbol,ScalaWeakerAccess
trait ScalaJSNpmModule extends ScalaJSDepsModule {
Expand Down Expand Up @@ -40,3 +42,16 @@ trait ScalaJSNpmModule extends ScalaJSDepsModule {
PathRef(dir)
}
}
//noinspection ScalaWeakerAccess
object ScalaJSNpmModule {
trait Test extends TestScalaJSModule with ScalaJSNpmModule {
override def jsEnvConfig = T {
val path = npmInstall().path / "node_modules"
println("path: " + path)
os.proc("ls", "react-phone-number-input")
.call(cwd = path, stdout = os.Inherit)
JsEnvConfig.NodeJs(env = Map("NODE_PATH" -> path.toString))
}
}

}
34 changes: 34 additions & 0 deletions jsdeps/test/src/simple/build.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import $exec.plugins

import io.github.nafg.millbundler.jsdeps.ScalaJSNpmModule
import mill.scalajslib.api.ModuleKind
import mill.scalalib.{DepSyntax, TestModule}
import mill.scalajslib.api.JsEnvConfig


object main extends ScalaJSNpmModule {
override def scalaVersion = "2.13.10"
override def scalaJSVersion = "1.10.1"

override def ivyDeps =
Agg(
ivy"io.github.nafg.scalajs-facades::react-phone-number-input_3::0.16.0"
)

object test
extends Tests
with ScalaJSNpmModule.Test
with TestModule.Munit {

override def moduleKind = ModuleKind.CommonJSModule

override def ivyDeps =
super.ivyDeps() ++ Agg(ivy"org.scalameta::munit::0.7.29")
}
}

def verify = T {
val logger = T.ctx().log
val (_, testResults) = main.test.test()()
assert(testResults.nonEmpty, "No tests found")
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions millbundler/test/src/webpack-simple/main/test/src/Tests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import io.github.nafg.scalajs.facades.reactphonenumberinput._
import munit.Assertions._
import scala.scalajs.js
import scala.scalajs.js.annotation._


class Tests extends munit.FunSuite {
test("ReactPhoneNumberInput") {
assert(!js.isUndefined(ReactPhoneNumberInput.raw))
}
}

0 comments on commit 73d9f80

Please sign in to comment.