diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/node_unit_tests.rs | 1 | ||||
-rw-r--r-- | tests/unit_node/_fs/_fs_statfs_test.ts | 77 |
2 files changed, 78 insertions, 0 deletions
diff --git a/tests/integration/node_unit_tests.rs b/tests/integration/node_unit_tests.rs index 2fd7e78f6..fc636e807 100644 --- a/tests/integration/node_unit_tests.rs +++ b/tests/integration/node_unit_tests.rs @@ -44,6 +44,7 @@ util::unit_test_factory!( _fs_rm_test = _fs / _fs_rm_test, _fs_rmdir_test = _fs / _fs_rmdir_test, _fs_stat_test = _fs / _fs_stat_test, + _fs_statfs_test = _fs / _fs_statfs_test, _fs_symlink_test = _fs / _fs_symlink_test, _fs_truncate_test = _fs / _fs_truncate_test, _fs_unlink_test = _fs / _fs_unlink_test, diff --git a/tests/unit_node/_fs/_fs_statfs_test.ts b/tests/unit_node/_fs/_fs_statfs_test.ts new file mode 100644 index 000000000..fde1c8fed --- /dev/null +++ b/tests/unit_node/_fs/_fs_statfs_test.ts @@ -0,0 +1,77 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +import * as fs from "node:fs"; +import { assertEquals, assertRejects } from "@std/assert/mod.ts"; +import * as path from "@std/path/mod.ts"; + +function assertStatFs( + statFs: fs.StatsFsBase<unknown>, + { bigint = false } = {}, +) { + assertEquals(statFs.constructor.name, "StatFs"); + const expectedType = bigint ? "bigint" : "number"; + assertEquals(typeof statFs.type, expectedType); + assertEquals(typeof statFs.bsize, expectedType); + assertEquals(typeof statFs.blocks, expectedType); + assertEquals(typeof statFs.bfree, expectedType); + assertEquals(typeof statFs.bavail, expectedType); + assertEquals(typeof statFs.files, expectedType); + assertEquals(typeof statFs.ffree, expectedType); + if (Deno.build.os == "windows") { + assertEquals(statFs.type, bigint ? 0n : 0); + assertEquals(statFs.files, bigint ? 0n : 0); + assertEquals(statFs.ffree, bigint ? 0n : 0); + } +} + +const filePath = path.fromFileUrl(import.meta.url); + +Deno.test({ + name: "fs.statfs()", + async fn() { + await new Promise<fs.StatsFsBase<unknown>>((resolve, reject) => { + fs.statfs(filePath, (err, statFs) => { + if (err) reject(err); + resolve(statFs); + }); + }).then((statFs) => assertStatFs(statFs)); + }, +}); + +Deno.test({ + name: "fs.statfs() bigint", + async fn() { + await new Promise<fs.StatsFsBase<unknown>>((resolve, reject) => { + fs.statfs(filePath, { bigint: true }, (err, statFs) => { + if (err) reject(err); + resolve(statFs); + }); + }).then((statFs) => assertStatFs(statFs, { bigint: true })); + }, +}); + +Deno.test({ + name: "fs.statfsSync()", + fn() { + const statFs = fs.statfsSync(filePath); + assertStatFs(statFs); + }, +}); + +Deno.test({ + name: "fs.statfsSync() bigint", + fn() { + const statFs = fs.statfsSync(filePath, { bigint: true }); + assertStatFs(statFs, { bigint: true }); + }, +}); + +Deno.test({ + name: "fs.statfs() non-existent path", + async fn() { + const nonExistentPath = path.join(filePath, "../non-existent"); + await assertRejects(async () => { + await fs.promises.statfs(nonExistentPath); + }, "NotFound"); + }, +}); |