Skip to content

Commit

Permalink
fs.exists deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnywong committed Oct 6, 2023
1 parent 6c69a10 commit 3524077
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/nodefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ function promisify(fs: any, funcs: string[]) {

promisify(fs, ["stat", "access", "mkdir", "readdir", "close", "open", "realpath", "write"]);

async function fsExists(path: string) {
return new Promise((resolve) => fs.exists(path, (exists: boolean) => resolve(exists)));
async function fsExists(path: string): Promise<boolean> {
return new Promise((resolve) => fs.access(path, (err: Error) => resolve(!err)));
}

async function fsRead(
Expand Down
6 changes: 3 additions & 3 deletions test/nodefs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ test("open save file success", async () => {
tfr.closeFile();
expect(fs.readFileSync(path.join(tmpDir, "save.txt")).toString()).toBe("test file content");

const exists = fs.exists;
fs.exists = (_path: string, callback: Function) => callback(true);
const access = fs.access;
fs.access = (_path: string, mode: Function, callback: Function) => (callback ? callback(null) : mode(null));
await expect(openSaveFile(saveParam, "save.txt", false, false)).rejects.toThrowError("Fail to assign new file name");
fs.exists = exists;
fs.access = access;
});

test("open save file error", async () => {
Expand Down

0 comments on commit 3524077

Please sign in to comment.