Skip to content

Commit

Permalink
Implement proper node project test
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrdom committed Nov 3, 2023
1 parent d44726c commit 14cb5b1
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package example.facade

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

object Fs {
@js.native
@JSImport("node:fs", "mkdtempSync")
def mkdtempSync(paths: String): String = js.native

@js.native
@JSImport("node:fs", "writeFileSync")
def writeFileSync(file: String, data: String, encoding: String): Unit = js.native

@js.native
@JSImport("node:fs", "readFileSync")
def readFileSync(path: String, encoding: String): String = js.native
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package example.facade

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

object Os {
@js.native
@JSImport("node:os", "tmpdir")
def tmpdir(): String = js.native
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package example.facade

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

object Path {
@js.native
@JSImport("node:path", "join")
def join(paths: String*): String = js.native

@js.native
@JSImport("node:path", "sep")
val sep: String = js.native
}
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
}
}
}

0 comments on commit 14cb5b1

Please sign in to comment.