Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

[fs] BigIntStats should use js.BigInt & Remove ~Ns fron nodejs-v10 #350

Merged
merged 3 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/nodejs-v10/src/test/scala/io/scalajs/nodejs/fs/FsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,17 @@ class FsTest extends AsyncFunSpec {
succeed
}
}

it("support double stats") {
Fs.statFuture("./package.json").map { stats =>
assert(stats.birthtimeMs.toLong > 0L)
}
}

it("support bigint stats") {
Fs.statFuture("./package.json", StatOptions(bigint = true)).map { stats =>
assert(stats.asInstanceOf[BigIntStats].birthtimeMs.toString.toLong > 0L)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ class FsClassesTest extends AnyFunSpec {
assert(ex.getMessage().contains("ERR_DIR_CLOSED"))
}
}

it("adds new members on bigint stats") {
val stats = Fs.statSync("./package.json", StatOptions(bigint = true)).asInstanceOf[BigIntStats]
assert(stats.asInstanceOf[BigIntStats].birthtimeNs.toString.toLong > 0L)
assert(stats.asInstanceOf[BigIntStats].ctimeNs.toString.toLong > 0L)
assert(stats.asInstanceOf[BigIntStats].atimeNs.toString.toLong > 0L)
assert(stats.asInstanceOf[BigIntStats].mtimeNs.toString.toLong > 0L)
}
}
19 changes: 14 additions & 5 deletions app/nodejs-v14/src/main/scala/io/scalajs/nodejs/fs/Stats.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.scalajs.nodejs
package fs

import com.thoughtworks.enableIf

import scala.scalajs.js

@js.native
Expand Down Expand Up @@ -142,9 +144,16 @@ trait Stats extends IStats[Int, Double]
* @since 0.1.21
*/
@js.native
trait BigIntStats extends IStats[BigInt, BigInt] {
def atimeNs: BigInt = js.native
def mtimeNs: BigInt = js.native
def ctimeNs: BigInt = js.native
def birthtimeNs: BigInt = js.native
trait BigIntStats extends IStats[js.BigInt, js.BigInt] {
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
def atimeNs: js.BigInt = js.native

@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
def mtimeNs: js.BigInt = js.native

@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
def ctimeNs: js.BigInt = js.native

@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
def birthtimeNs: js.BigInt = js.native
}