mirror of
https://github.com/tale/headplane.git
synced 2026-08-18 09:03:14 +00:00
chore: format everything with oxfmt
This commit is contained in:
@@ -1,40 +1,40 @@
|
||||
import { vi } from 'vitest';
|
||||
import { vi } from "vitest";
|
||||
|
||||
const fakeFs = new Map<string, string>();
|
||||
export function createFakeFile(path: string, content: string) {
|
||||
fakeFs.set(path, content);
|
||||
fakeFs.set(path, content);
|
||||
}
|
||||
|
||||
export function clearFakeFiles() {
|
||||
fakeFs.clear();
|
||||
fakeFs.clear();
|
||||
}
|
||||
|
||||
// @ts-expect-error: I have no clue why vitest's types are wrong here
|
||||
vi.mock(import('node:fs/promises'), async (importOrig) => {
|
||||
const orig = await importOrig();
|
||||
return {
|
||||
...orig,
|
||||
readFile: (path, options) => {
|
||||
const p = path.toString();
|
||||
if (fakeFs.has(p)) {
|
||||
const content = fakeFs.get(p)!;
|
||||
if (typeof options === 'string' || options?.encoding) {
|
||||
return Promise.resolve(content);
|
||||
}
|
||||
vi.mock(import("node:fs/promises"), async (importOrig) => {
|
||||
const orig = await importOrig();
|
||||
return {
|
||||
...orig,
|
||||
readFile: (path, options) => {
|
||||
const p = path.toString();
|
||||
if (fakeFs.has(p)) {
|
||||
const content = fakeFs.get(p)!;
|
||||
if (typeof options === "string" || options?.encoding) {
|
||||
return Promise.resolve(content);
|
||||
}
|
||||
|
||||
return Promise.resolve(Buffer.from(content));
|
||||
}
|
||||
return Promise.resolve(Buffer.from(content));
|
||||
}
|
||||
|
||||
return orig.readFile.call(this, path, options);
|
||||
},
|
||||
return orig.readFile.call(this, path, options);
|
||||
},
|
||||
|
||||
access: (path, mode) => {
|
||||
const p = path.toString();
|
||||
if (fakeFs.has(p)) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
access: (path, mode) => {
|
||||
const p = path.toString();
|
||||
if (fakeFs.has(p)) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return orig.access.call(this, path, mode);
|
||||
},
|
||||
};
|
||||
return orig.access.call(this, path, mode);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user