diff --git a/src/js/node/fs.ts b/src/js/node/fs.ts index f480b390a20b7c..37ecf55d0279fb 100644 --- a/src/js/node/fs.ts +++ b/src/js/node/fs.ts @@ -1021,6 +1021,10 @@ function _toUnixTimestamp(time: any, name = "time") { function opendirSync(path, options) { // TODO: validatePath // validateString(path, "path"); + if (!fs.existsSync(path)) { + throw new Error("ENOENT"); + } + return new Dir(1, path, options); } diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts index 7445d32eda4a01..4656999aa931c8 100644 --- a/test/js/node/fs/fs.test.ts +++ b/test/js/node/fs/fs.test.ts @@ -19,6 +19,7 @@ import fs, { mkdtempSync, openAsBlob, openSync, + opendirSync, promises, statfsSync, statfs, @@ -572,6 +573,13 @@ describe("copyFileSync", () => { } }); +describe("opendirSync", () => { + it("should throw ENOENT on a nonexistent directory", () => { + const dirName = Math.random().toString(8); + expect(() => opendirSync(dirName)).toThrow("ENOENT"); + }) +}); + describe("mkdirSync", () => { it("should create a directory", () => { const now = Date.now().toString();