-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathtauri-mock.ts
27 lines (25 loc) · 1.31 KB
/
tauri-mock.ts
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
/* eslint-disable @typescript-eslint/no-unused-vars */
import { makeVirtualFileSystem } from "../src/index.js";
import { FileEntry, FsDirOptions } from "@tauri-apps/api/fs";
const vfs = makeVirtualFileSystem();
(globalThis as any).__TAURI__ = {
fs: {
exists: (path: string, options: FsDirOptions) => Promise.resolve(vfs.getType(path) !== null),
createDir: (path: string, options: FsDirOptions) => (vfs.mkdir(path), Promise.resolve()),
readdir: (path: string, options: FsDirOptions) =>
vfs.getType(path) === "dir"
? Promise.resolve(vfs.readdir(path).map(name => ({ name }) as unknown as FileEntry))
: Promise.reject(new Error("not a directory")),
readTextFile: (path: string, options: FsDirOptions) => Promise.resolve(vfs.readFile(path)),
renameFile: (prev: string, next: string) => Promise.resolve(vfs.rename(prev, next)),
writeFile: (path: string, data: string) => Promise.resolve(vfs.writeFile(path, data)),
removeDir: (path: string, options: FsDirOptions) =>
vfs.getType(path) === "dir"
? Promise.resolve(vfs.rm(path))
: Promise.reject(new Error("not a directory")),
removeFile: (path: string, options: FsDirOptions) =>
vfs.getType(path) === "file"
? Promise.resolve(vfs.rm(path))
: Promise.reject(new Error("not a file")),
},
};