// 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((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((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); } }, });