From be5ed5a200f16b519313d72b3f62396fd5c1c511 Mon Sep 17 00:00:00 2001 From: Domantas Petrauskas Date: Fri, 3 Nov 2023 17:14:58 +0200 Subject: [PATCH] Implement proper node project test --- .../basic-node-project/esbuild/package.json | 6 ++---- .../src/main/scala/example/Main.scala | 11 ++++++++--- .../src/main/scala/example/facade/Fs.scala | 15 +++++++++++++++ .../src/main/scala/example/facade/Os.scala | 10 ++++++++++ .../src/main/scala/example/facade/Path.scala | 12 ++++++++++++ .../src/test/scala/example/MainSpec.scala | 2 +- 6 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/main/scala/example/facade/Fs.scala create mode 100644 sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/main/scala/example/facade/Os.scala create mode 100644 sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/main/scala/example/facade/Path.scala diff --git a/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/esbuild/package.json b/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/esbuild/package.json index ed296a9f..3958966b 100644 --- a/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/esbuild/package.json +++ b/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/esbuild/package.json @@ -2,10 +2,8 @@ "name": "basic-project", "private": true, "version": "0.0.0", - "dependencies": { - "lodash": "4.17.21" - }, "devDependencies": { - "esbuild": "0.19.5" + "esbuild": "0.19.5", + "lodash": "4.17.21" } } \ No newline at end of file diff --git a/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/main/scala/example/Main.scala b/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/main/scala/example/Main.scala index 157b164d..85f8fcf8 100644 --- a/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/main/scala/example/Main.scala +++ b/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/main/scala/example/Main.scala @@ -1,13 +1,18 @@ package example +import example.facade.Fs import example.facade.Lodash +import example.facade.Os +import example.facade.Path object Main { def main(args: Array[String]): Unit = { - println(testString()) + println(test()) } - def testString(): String = { - Lodash.toUpper("basic-node-project works!") + def test(): String = { + val file = Path.join(Fs.mkdtempSync(s"${Os.tmpdir()}${Path.sep}"), "test") + Fs.writeFileSync(file, Lodash.toUpper("basic-node-project works!"), "utf8") + Fs.readFileSync(file, "utf8") } } diff --git a/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/main/scala/example/facade/Fs.scala b/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/main/scala/example/facade/Fs.scala new file mode 100644 index 00000000..ea44fb97 --- /dev/null +++ b/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/main/scala/example/facade/Fs.scala @@ -0,0 +1,15 @@ +package example.facade + +import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport + +@js.native +@JSImport("node:fs", JSImport.Default) +object Fs extends js.Object { + def mkdtempSync(paths: String): String = js.native + + def writeFileSync(file: String, data: String, encoding: String): Unit = + js.native + + def readFileSync(path: String, encoding: String): String = js.native +} diff --git a/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/main/scala/example/facade/Os.scala b/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/main/scala/example/facade/Os.scala new file mode 100644 index 00000000..bba62fd0 --- /dev/null +++ b/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/main/scala/example/facade/Os.scala @@ -0,0 +1,10 @@ +package example.facade + +import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport + +@js.native +@JSImport("node:os", JSImport.Default) +object Os extends js.Object { + def tmpdir(): String = js.native +} diff --git a/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/main/scala/example/facade/Path.scala b/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/main/scala/example/facade/Path.scala new file mode 100644 index 00000000..fd2eb649 --- /dev/null +++ b/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/main/scala/example/facade/Path.scala @@ -0,0 +1,12 @@ +package example.facade + +import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport + +@js.native +@JSImport("node:path", JSImport.Default) +object Path extends js.Object { + def join(paths: String*): String = js.native + + val sep: String = js.native +} diff --git a/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/test/scala/example/MainSpec.scala b/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/test/scala/example/MainSpec.scala index 430173a5..8c27fed3 100644 --- a/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/test/scala/example/MainSpec.scala +++ b/sbt-scalajs-esbuild/src/sbt-test/sbt-scalajs-esbuild/basic-node-project/src/test/scala/example/MainSpec.scala @@ -7,7 +7,7 @@ class MainSpec extends AnyWordSpec with Matchers { "Main" should { "work" in { - Main.testString() shouldEqual "BASIC-NODE-PROJECT WORKS!" + Main.test() shouldEqual "BASIC-NODE-PROJECT WORKS!" } } }