aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/fs.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/bun.js/fs.test.js')
-rw-r--r--test/bun.js/fs.test.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/bun.js/fs.test.js b/test/bun.js/fs.test.js
index 94e6843f5..f2f3e6519 100644
--- a/test/bun.js/fs.test.js
+++ b/test/bun.js/fs.test.js
@@ -14,7 +14,9 @@ import {
statSync,
lstatSync,
copyFileSync,
+ rmSync,
} from "node:fs";
+import { join } from "node:path";
const Buffer = globalThis.Buffer || Uint8Array;
@@ -387,3 +389,33 @@ describe("stat", () => {
expect(fileStats.isDirectory()).toBe(true);
});
});
+
+describe("rm", () => {
+ it("removes a file", () => {
+ const path = `/tmp/${Date.now()}.rm.txt`;
+ writeFileSync(path, "File written successfully", "utf8");
+ expect(existsSync(path)).toBe(true);
+ rmSync(path);
+ expect(existsSync(path)).toBe(false);
+ });
+
+ it("removes a dir", () => {
+ const path = `/tmp/${Date.now()}.rm.dir`;
+ try {
+ mkdirSync(path);
+ } catch (e) {}
+ expect(existsSync(path)).toBe(true);
+ rmSync(path);
+ expect(existsSync(path)).toBe(false);
+ });
+
+ it("removes a dir recursively", () => {
+ const path = `/tmp/${Date.now()}.rm.dir/foo/bar`;
+ try {
+ mkdirSync(path, { recursive: true });
+ } catch (e) {}
+ expect(existsSync(path)).toBe(true);
+ rmSync(join(path, "../../"), { recursive: true });
+ expect(existsSync(path)).toBe(false);
+ });
+});