opfs-mock 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +12 -14
- package/package.json +20 -9
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# opfs-mock
|
|
2
2
|
|
|
3
3
|
In-memory implementation of the [origin private file system](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system). Its main utility is for testing OPFS-dependent code in Node.js. It's tested
|
|
4
|
-
on Node.js versions 20-
|
|
4
|
+
on Node.js versions 20-25.
|
|
5
5
|
|
|
6
6
|
## Installation
|
|
7
7
|
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,14 +16,17 @@ const getSizeOfDirectory = async (directory) => {
|
|
|
16
16
|
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region src/opfs.ts
|
|
19
|
-
const fileSystemFileHandleFactory = (name, fileData) => {
|
|
19
|
+
const fileSystemFileHandleFactory = (name, fileData, exists) => {
|
|
20
20
|
return {
|
|
21
21
|
kind: "file",
|
|
22
22
|
name,
|
|
23
23
|
isSameEntry: async (other) => {
|
|
24
24
|
return other.name === name && other.kind === "file";
|
|
25
25
|
},
|
|
26
|
-
getFile: async () =>
|
|
26
|
+
getFile: async () => {
|
|
27
|
+
if (!exists()) throw new DOMException("A requested file or directory could not be found at the time an operation was processed.", "NotFoundError");
|
|
28
|
+
return new File([fileData.content], name);
|
|
29
|
+
},
|
|
27
30
|
createWritable: async (options) => {
|
|
28
31
|
const keepExistingData = options?.keepExistingData;
|
|
29
32
|
let abortReason = "";
|
|
@@ -163,8 +166,8 @@ const fileSystemFileHandleFactory = (name, fileData) => {
|
|
|
163
166
|
};
|
|
164
167
|
};
|
|
165
168
|
const fileSystemDirectoryHandleFactory = (name) => {
|
|
166
|
-
const files = new Map();
|
|
167
|
-
const directories = new Map();
|
|
169
|
+
const files = /* @__PURE__ */ new Map();
|
|
170
|
+
const directories = /* @__PURE__ */ new Map();
|
|
168
171
|
const getJoinedMaps = () => {
|
|
169
172
|
return new Map([...files, ...directories]);
|
|
170
173
|
};
|
|
@@ -175,7 +178,7 @@ const fileSystemDirectoryHandleFactory = (name) => {
|
|
|
175
178
|
return other.name === name && other.kind === "directory";
|
|
176
179
|
},
|
|
177
180
|
getFileHandle: async (fileName, options) => {
|
|
178
|
-
if (!files.has(fileName) && options?.create) files.set(fileName, fileSystemFileHandleFactory(fileName, { content: new Uint8Array() }));
|
|
181
|
+
if (!files.has(fileName) && options?.create) files.set(fileName, fileSystemFileHandleFactory(fileName, { content: new Uint8Array() }, () => files.has(fileName)));
|
|
179
182
|
const fileHandle = files.get(fileName);
|
|
180
183
|
if (!fileHandle) throw new DOMException(`File not found: ${fileName}`, "NotFoundError");
|
|
181
184
|
return fileHandle;
|
|
@@ -198,16 +201,13 @@ const fileSystemDirectoryHandleFactory = (name) => {
|
|
|
198
201
|
return void 0;
|
|
199
202
|
},
|
|
200
203
|
entries: async function* () {
|
|
201
|
-
|
|
202
|
-
yield* joinedMaps.entries();
|
|
204
|
+
yield* getJoinedMaps().entries();
|
|
203
205
|
},
|
|
204
206
|
keys: async function* () {
|
|
205
|
-
|
|
206
|
-
yield* joinedMaps.keys();
|
|
207
|
+
yield* getJoinedMaps().keys();
|
|
207
208
|
},
|
|
208
209
|
values: async function* () {
|
|
209
|
-
|
|
210
|
-
yield* joinedMaps.values();
|
|
210
|
+
yield* getJoinedMaps().values();
|
|
211
211
|
},
|
|
212
212
|
resolve: async function(possibleDescendant) {
|
|
213
213
|
const traverseDirectory = async (directory, target, path = []) => {
|
|
@@ -231,10 +231,8 @@ const storageFactory = ({ usage = 0, quota = 1024 ** 3 } = {}) => {
|
|
|
231
231
|
const root = fileSystemDirectoryHandleFactory("root");
|
|
232
232
|
return {
|
|
233
233
|
estimate: async () => {
|
|
234
|
-
const defaultUsage = usage;
|
|
235
|
-
const calculatedUsage = await getSizeOfDirectory(root);
|
|
236
234
|
return {
|
|
237
|
-
usage:
|
|
235
|
+
usage: usage + await getSizeOfDirectory(root),
|
|
238
236
|
quota
|
|
239
237
|
};
|
|
240
238
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opfs-mock",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Mock all origin private file system APIs for your Jest or Vitest tests",
|
|
6
6
|
"author": "Jure Rotar <hello@jurerotar.com>",
|
|
@@ -13,7 +13,16 @@
|
|
|
13
13
|
"bugs": {
|
|
14
14
|
"url": "https://github.com/jurerotar/opfs-mock/issues"
|
|
15
15
|
},
|
|
16
|
-
"keywords": [
|
|
16
|
+
"keywords": [
|
|
17
|
+
"vitest",
|
|
18
|
+
"jest",
|
|
19
|
+
"test",
|
|
20
|
+
"mock",
|
|
21
|
+
"opfs",
|
|
22
|
+
"storage",
|
|
23
|
+
"node",
|
|
24
|
+
"browser"
|
|
25
|
+
],
|
|
17
26
|
"publishConfig": {
|
|
18
27
|
"access": "public"
|
|
19
28
|
},
|
|
@@ -25,7 +34,9 @@
|
|
|
25
34
|
},
|
|
26
35
|
"main": "dist/index.js",
|
|
27
36
|
"module": "dist/index.js",
|
|
28
|
-
"files": [
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
29
40
|
"engines": {
|
|
30
41
|
"node": ">=20.0.0"
|
|
31
42
|
},
|
|
@@ -45,12 +56,12 @@
|
|
|
45
56
|
"release": "npm publish --access public"
|
|
46
57
|
},
|
|
47
58
|
"devDependencies": {
|
|
48
|
-
"@biomejs/biome": "
|
|
59
|
+
"@biomejs/biome": "2.2.6",
|
|
49
60
|
"@web-std/file": "3.0.3",
|
|
50
|
-
"happy-dom": "
|
|
51
|
-
"jsdom": "
|
|
52
|
-
"tsdown": "0.
|
|
53
|
-
"typescript": "5.
|
|
54
|
-
"vitest": "3.
|
|
61
|
+
"happy-dom": "20.0.5",
|
|
62
|
+
"jsdom": "27.0.1",
|
|
63
|
+
"tsdown": "0.15.7",
|
|
64
|
+
"typescript": "5.9.3",
|
|
65
|
+
"vitest": "3.2.4"
|
|
55
66
|
}
|
|
56
67
|
}
|