-
Notifications
You must be signed in to change notification settings - Fork 632
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fs/unstable): add statSync and lstatSync (#6300)
- Loading branch information
Showing
8 changed files
with
162 additions
and
45 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 |
---|---|---|
@@ -1,30 +1,48 @@ | ||
// Copyright 2018-2025 the Deno authors. MIT license. | ||
|
||
import { assert, assertRejects } from "@std/assert"; | ||
import { lstat } from "./unstable_lstat.ts"; | ||
import { assert, assertRejects, assertThrows } from "@std/assert"; | ||
import { lstat, lstatSync } from "./unstable_lstat.ts"; | ||
import { NotFound } from "./unstable_errors.js"; | ||
|
||
Deno.test("lstat() returns FileInfo for a file", async () => { | ||
const fileInfo = await lstat("README.md"); | ||
|
||
assert(fileInfo.isFile); | ||
Deno.test("lstat() and lstatSync() return FileInfo for a file", async () => { | ||
{ | ||
const fileInfo = await lstat("README.md"); | ||
assert(fileInfo.isFile); | ||
} | ||
{ | ||
const fileInfo = lstatSync("README.md"); | ||
assert(fileInfo.isFile); | ||
} | ||
}); | ||
|
||
Deno.test("lstat() does not follow symlinks", async () => { | ||
const linkFile = `${import.meta.dirname}/testdata/0-link`; | ||
const fileInfo = await lstat(linkFile); | ||
|
||
assert(fileInfo.isSymlink); | ||
Deno.test("lstat() and lstatSync() do not follow symlinks", async () => { | ||
const linkFile = new URL("testdata/0-link", import.meta.url); | ||
{ | ||
const fileInfo = await lstat(linkFile); | ||
assert(fileInfo.isSymlink); | ||
} | ||
{ | ||
const fileInfo = lstatSync(linkFile); | ||
assert(fileInfo.isSymlink); | ||
} | ||
}); | ||
|
||
Deno.test("lstat() returns FileInfo for a directory", async () => { | ||
const fileInfo = await lstat("fs"); | ||
|
||
assert(fileInfo.isDirectory); | ||
Deno.test("lstat() and lstatSync() return FileInfo for a directory", async () => { | ||
{ | ||
const fileInfo = await lstat("fs"); | ||
assert(fileInfo.isDirectory); | ||
} | ||
{ | ||
const fileInfo = lstatSync("fs"); | ||
assert(fileInfo.isDirectory); | ||
} | ||
}); | ||
|
||
Deno.test("lstat() rejects with NotFound for a non-existent file", async () => { | ||
Deno.test("lstat() and lstatSync() throw with NotFound for a non-existent file", async () => { | ||
await assertRejects(async () => { | ||
await lstat("non_existent_file"); | ||
}, NotFound); | ||
assertThrows(() => { | ||
lstatSync("non_existent_file"); | ||
}, NotFound); | ||
}); |
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 |
---|---|---|
@@ -1,23 +1,37 @@ | ||
// Copyright 2018-2025 the Deno authors. MIT license. | ||
|
||
import { assert, assertRejects } from "@std/assert"; | ||
import { stat } from "./unstable_stat.ts"; | ||
import { assert, assertRejects, assertThrows } from "@std/assert"; | ||
import { stat, statSync } from "./unstable_stat.ts"; | ||
import { NotFound } from "./unstable_errors.js"; | ||
|
||
Deno.test("stat() returns FileInfo for a file", async () => { | ||
const fileInfo = await stat("README.md"); | ||
Deno.test("stat() and statSync() return FileInfo for a file", async () => { | ||
{ | ||
const fileInfo = await stat("README.md"); | ||
assert(fileInfo.isFile); | ||
} | ||
|
||
assert(fileInfo.isFile); | ||
{ | ||
const fileInfo = statSync("README.md"); | ||
assert(fileInfo.isFile); | ||
} | ||
}); | ||
|
||
Deno.test("stat() returns FileInfo for a directory", async () => { | ||
const fileInfo = await stat("fs"); | ||
|
||
assert(fileInfo.isDirectory); | ||
Deno.test("stat() and statSync() return FileInfo for a directory", async () => { | ||
{ | ||
const fileInfo = await stat("fs"); | ||
assert(fileInfo.isDirectory); | ||
} | ||
{ | ||
const fileInfo = statSync("fs"); | ||
assert(fileInfo.isDirectory); | ||
} | ||
}); | ||
|
||
Deno.test("stat() rejects with NotFound for a non-existent file", async () => { | ||
Deno.test("stat() and statSync() throw with NotFound for a non-existent file", async () => { | ||
await assertRejects(async () => { | ||
await stat("non_existent_file"); | ||
}, NotFound); | ||
assertThrows(() => { | ||
statSync("non_existent_file"); | ||
}, NotFound); | ||
}); |
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