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 be5ed5a
Show file tree
Hide file tree
Showing 6 changed files with 48 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,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
}
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

@js.native
@JSImport("node:os", JSImport.Default)
object Os extends js.Object {
def tmpdir(): String = js.native
}
Original file line number Diff line number Diff line change
@@ -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
}
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 be5ed5a

Please sign in to comment.