Skip to content

Commit 5f5dfd6

Browse files
committed
feat: enhance fs mock with writeFile and mkdir implementations; update index.ts types
1 parent 85b18b6 commit 5f5dfd6

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

__mocks__/fs.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ fs.promises.readFile = vi.fn((...args) => {
4242
}
4343
});
4444

45+
fs.promises.writeFile = vi.fn((...args) => {
46+
const [file, data] = args;
47+
const fullPath = Path.resolve(process.cwd(), file);
48+
fs.virtualFiles[fullPath] = data;
49+
return new Promise((resolve) => resolve());
50+
});
51+
4552
fs.promises.readdir = vi.fn((...args) => {
4653
const [path] = args;
4754
const fullPath = Path.resolve(process.cwd(), path);
@@ -105,5 +112,13 @@ fs.writeFile = vi.fn((file, data, ...rest) => {
105112
callback(null);
106113
});
107114

115+
fs.mkdir = vi.fn((...args) => {
116+
const [path, options, callback] = args;
117+
118+
// no-op
119+
120+
callback(null);
121+
});
122+
108123
fs.default = fs;
109124
module.exports = fs;

achievements/__mocks__/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export const isUnlocked = () => false;
77
export const increment = (user: string, name: string, value: number = 1) => {
88
console.log(`[achievements stub] ${user} increased ${name} by ${value}`);
99
};
10-
export const get = (): any => null;
11-
export const set = (user: string, name: string, value: any) => {
10+
export const get = (): unknown => null;
11+
export const set = (user: string, name: string, value: unknown) => {
1212
console.log(`[achievements stub] ${user} set ${name} = ${value}`);
1313
};
1414
export const lock = () => {};

0 commit comments

Comments
 (0)