aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets/fs.test.js
blob: 513132450a885756ae73a49a4ad1716ff0d2ed18 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { describe, it, expect } from "bun:test";
import { mkdirSync, existsSync, readFileSync, writeFileSync } from "node:fs";

describe("mkdirSync", () => {
  it("should create a directory", () => {
    const tempdir = `/tmp/fs.test.js/${Date.now()}/1234/hi`;
    expect(existsSync(tempdir)).toBe(false);
    expect(tempdir.includes(mkdirSync(tempdir, { recursive: true }))).toBe(
      true
    );
    expect(existsSync(tempdir)).toBe(true);
  });
});

describe("readFileSync", () => {
  it("works", () => {
    const text = readFileSync(import.meta.dir + "/readFileSync.txt", "utf8");
    expect(text).toBe("File read successfully");
  });
});

describe("writeFileSync", () => {
  it("works", () => {
    const path = `/tmp/${Date.now()}.writeFileSync.txt`;
    writeFileSync(path, "File written successfully", "utf8");

    expect(readFileSync(path, "utf8")).toBe("File written successfully");
  });
});