summaryrefslogtreecommitdiff
path: root/cli/tests/unit_node/_fs/_fs_fstat_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/unit_node/_fs/_fs_fstat_test.ts')
-rw-r--r--cli/tests/unit_node/_fs/_fs_fstat_test.ts83
1 files changed, 83 insertions, 0 deletions
diff --git a/cli/tests/unit_node/_fs/_fs_fstat_test.ts b/cli/tests/unit_node/_fs/_fs_fstat_test.ts
new file mode 100644
index 000000000..70c3db254
--- /dev/null
+++ b/cli/tests/unit_node/_fs/_fs_fstat_test.ts
@@ -0,0 +1,83 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+import { fstat, fstatSync } from "node:fs";
+import { fail } from "../../../../test_util/std/testing/asserts.ts";
+import { assertStats, assertStatsBigInt } from "./_fs_stat_test.ts";
+import type { BigIntStats, Stats } from "node:fs";
+
+Deno.test({
+ name: "ASYNC: get a file Stats",
+ async fn() {
+ const file = await Deno.makeTempFile();
+ const { rid } = await Deno.open(file);
+
+ await new Promise<Stats>((resolve, reject) => {
+ fstat(rid, (err: Error | null, stat: Stats) => {
+ if (err) reject(err);
+ resolve(stat);
+ });
+ })
+ .then(
+ (stat) => {
+ assertStats(stat, Deno.fstatSync(rid));
+ },
+ () => fail(),
+ )
+ .finally(() => {
+ Deno.removeSync(file);
+ Deno.close(rid);
+ });
+ },
+});
+
+Deno.test({
+ name: "ASYNC: get a file BigInt Stats",
+ async fn() {
+ const file = await Deno.makeTempFile();
+ const { rid } = await Deno.open(file);
+
+ await new Promise<BigIntStats>((resolve, reject) => {
+ fstat(rid, { bigint: true }, (err: Error | null, stat: BigIntStats) => {
+ if (err) reject(err);
+ resolve(stat);
+ });
+ })
+ .then(
+ (stat) => assertStatsBigInt(stat, Deno.fstatSync(rid)),
+ () => fail(),
+ )
+ .finally(() => {
+ Deno.removeSync(file);
+ Deno.close(rid);
+ });
+ },
+});
+
+Deno.test({
+ name: "SYNC: get a file Stats",
+ fn() {
+ const file = Deno.makeTempFileSync();
+ const { rid } = Deno.openSync(file);
+
+ try {
+ assertStats(fstatSync(rid), Deno.fstatSync(rid));
+ } finally {
+ Deno.removeSync(file);
+ Deno.close(rid);
+ }
+ },
+});
+
+Deno.test({
+ name: "SYNC: get a file BigInt Stats",
+ fn() {
+ const file = Deno.makeTempFileSync();
+ const { rid } = Deno.openSync(file);
+
+ try {
+ assertStatsBigInt(fstatSync(rid, { bigint: true }), Deno.fstatSync(rid));
+ } finally {
+ Deno.removeSync(file);
+ Deno.close(rid);
+ }
+ },
+});