diff options
author | 2022-10-11 00:03:32 -0700 | |
---|---|---|
committer | 2022-10-11 00:03:32 -0700 | |
commit | 40623cf967b6e776281b1f79cc4cd02e5d87f7d9 (patch) | |
tree | dda4d53456121a8f673bd191503df048b987448f /test/bun.js/fs.test.js | |
parent | d07e4f8bd178b4e7450a6990c51ca3bfa0201127 (diff) | |
download | bun-40623cf967b6e776281b1f79cc4cd02e5d87f7d9.tar.gz bun-40623cf967b6e776281b1f79cc4cd02e5d87f7d9.tar.zst bun-40623cf967b6e776281b1f79cc4cd02e5d87f7d9.zip |
Implement `fs.rm` cross-platformly
Diffstat (limited to 'test/bun.js/fs.test.js')
-rw-r--r-- | test/bun.js/fs.test.js | 32 |
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); + }); +}); |