opfs-mock 2.1.0 → 2.1.1

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.
Files changed (3) hide show
  1. package/README.md +10 -1
  2. package/dist/index.js +2 -2
  3. package/package.json +13 -4
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # opfs-mock
2
2
 
3
- This is a pure JS 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.
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-23.
4
5
 
5
6
  ## Installation
6
7
 
@@ -8,6 +9,14 @@ This is a pure JS in-memory implementation of the [origin private file system](h
8
9
  npm install -save-dev opfs-mock
9
10
  ```
10
11
 
12
+ ## Limitations
13
+
14
+ - `opfs-mock` requires **Node.js v20.0.0** or higher. It can work on Node v18.0.0 with either `--experimental-fetch` flag enabled or a global
15
+ `File` polyfill.
16
+
17
+ - `jsdom` testing environment is missing `File.prototype.text()` method, which is required for reading opfs files. Ensure your opfs-dependant tests are ran
18
+ in `node` or `happy-dom` environment.
19
+
11
20
  ## Usage
12
21
 
13
22
  It replicates the behavior of origin private file system, except data is not persisted to disk.
package/dist/index.js CHANGED
@@ -194,7 +194,7 @@ var fileSystemDirectoryHandleFactory = (name) => {
194
194
  }
195
195
  const fileHandle = files.get(fileName);
196
196
  if (!fileHandle) {
197
- throw new Error(`File not found: ${fileName}`);
197
+ throw new DOMException(`File not found: ${fileName}`, "NotFoundError");
198
198
  }
199
199
  return fileHandle;
200
200
  },
@@ -204,7 +204,7 @@ var fileSystemDirectoryHandleFactory = (name) => {
204
204
  }
205
205
  const directoryHandle = directories.get(dirName);
206
206
  if (!directoryHandle) {
207
- throw new Error(`Directory not found: ${dirName}`);
207
+ throw new DOMException(`Directory not found: ${dirName}`, "NotFoundError");
208
208
  }
209
209
  return directoryHandle;
210
210
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opfs-mock",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
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>",
@@ -26,6 +26,9 @@
26
26
  "main": "dist/index.js",
27
27
  "module": "dist/index.js",
28
28
  "files": ["dist"],
29
+ "engines": {
30
+ "node": ">=20.0.0"
31
+ },
29
32
  "scripts": {
30
33
  "dev": "tsup --watch",
31
34
  "build": "tsup",
@@ -34,14 +37,20 @@
34
37
  "format:check": "npx @biomejs/biome format",
35
38
  "format": "npx @biomejs/biome format --write",
36
39
  "type-check": "tsc --noEmit",
37
- "test": "vitest",
40
+ "test": "npm run test:node && npm run test:happy-dom",
41
+ "test:node": "vitest --environment=node",
42
+ "test:jsdom": "vitest --environment=jsdom",
43
+ "test:happy-dom": "vitest --environment=happy-dom",
38
44
  "prepublishOnly": "npm run build",
39
45
  "release": "npm publish --access public"
40
46
  },
41
47
  "devDependencies": {
42
48
  "@biomejs/biome": "1.9.4",
49
+ "@web-std/file": "3.0.3",
50
+ "happy-dom": "17.4.4",
51
+ "jsdom": "26.0.0",
43
52
  "tsup": "8.4.0",
44
- "typescript": "5.7.3",
45
- "vitest": "3.0.7"
53
+ "typescript": "5.8.2",
54
+ "vitest": "3.0.9"
46
55
  }
47
56
  }