-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.vitest.ts
39 lines (36 loc) · 936 Bytes
/
setup.vitest.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
28
29
30
31
32
33
34
35
36
37
38
39
import "fake-indexeddb/auto"
export async function cleanupFS() {
const { files } = await Filesystem.readdir({
path: "",
directory: Directory.External,
}).catch(() => ({ files: [] }))
for (const file of files) {
if (file.type === "file")
await Filesystem.deleteFile({
path: file.name,
directory: Directory.External,
})
else
await Filesystem.rmdir({
path: file.name,
directory: Directory.External,
recursive: true,
}).catch(() => false)
}
}
export async function writeFile(path: string, content: string) {
await Filesystem.writeFile({
path,
directory: Directory.External,
encoding: Encoding.UTF8,
data: content,
recursive: true,
})
}
export async function readFile(path: string) {
return await Filesystem.readFile({
path,
directory: Directory.External,
encoding: Encoding.UTF8,
}).then((res) => res.data)
}