-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { describe, beforeAll, afterAll, it, expect } from "bun:test"; | ||
import fs from "node:fs"; | ||
import os from "node:os"; | ||
import path from "node:path"; | ||
|
||
describe("given a directory that exists", () => { | ||
let dirname: string; | ||
|
||
beforeAll(() => { | ||
const name = "dir-sync.test." + String(Math.random() * 100).substring(0, 6); | ||
dirname = path.join(os.tmpdir(), name); | ||
fs.mkdirSync(dirname); | ||
}); | ||
|
||
afterAll(() => { | ||
fs.rmdirSync(dirname, { recursive: true }); | ||
}); | ||
|
||
it("can be opened/closed synchronously", () => { | ||
const dir = fs.opendirSync(dirname); | ||
expect(dir).toBeDefined(); | ||
expect(dir).toBeInstanceOf(fs.Dir); | ||
expect(dir.closeSync()).toBeUndefined(); | ||
expect(() => dir.readSync()).toThrow("Directory handle was closed"); | ||
}); | ||
|
||
it("can be opened/closed asynchronously", async () => { | ||
const dir = await fs.promises.opendir(dirname); | ||
expect(dir).toBeDefined(); | ||
expect(dir).toBeInstanceOf(fs.Dir); | ||
expect(await dir.close()).toBeUndefined(); | ||
expect(() => dir.read()).toThrow("Directory handle was closed"); | ||
}); | ||
}); |