opfs-mock 1.0.0 → 1.0.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.
- package/LICENSE.md +21 -21
- package/README.md +38 -8
- package/dist/index.d.ts +3 -4
- package/dist/index.js +6 -6
- package/package.json +6 -6
package/LICENSE.md
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright © 2024 Jure Rotar
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2024 Jure Rotar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE
|
package/README.md
CHANGED
|
@@ -18,12 +18,27 @@ The easiest way to use it is to import `opfs-mock`, which will polyfill OPFS API
|
|
|
18
18
|
import "opfs-mock";
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
Alternatively, you can explicitly import `
|
|
21
|
+
Alternatively, you can explicitly import `storageFactory`:
|
|
22
22
|
|
|
23
23
|
```ts
|
|
24
|
-
import {
|
|
24
|
+
import { storageFactory } from "opfs-mock";
|
|
25
25
|
|
|
26
26
|
test('Your test', async () => {
|
|
27
|
+
const storage = await storageFactory();
|
|
28
|
+
const root = await storage.getDirectory();
|
|
29
|
+
const directoryHandle = await root.getFileHandle('test-file.txt', { create: true });
|
|
30
|
+
// rest of your test
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`storageFactory` has predefined `quota` and `estimate` values set to `0`, which is fine if you're not using these properties.
|
|
35
|
+
In case you need specific values, you can pass both as arguments to `storageFactory`.
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { storageFactory } from "opfs-mock";
|
|
39
|
+
|
|
40
|
+
test('Your test', async () => {
|
|
41
|
+
const storage = await storageFactory({ quota: 1_000_000, estimate: 1_000 });
|
|
27
42
|
const root = await storage.getDirectory();
|
|
28
43
|
const directoryHandle = await root.getFileHandle('test-file.txt', { create: true });
|
|
29
44
|
// rest of your test
|
|
@@ -37,14 +52,22 @@ To use `opfs-mock` in a single Vitest test suite, require `opfs-mock` at the beg
|
|
|
37
52
|
To use it on all Vitest tests without having to include it in each file, add the auto setup script to the `test.setupFiles` in your Vite config:
|
|
38
53
|
|
|
39
54
|
```ts
|
|
40
|
-
// vite.config.
|
|
55
|
+
// vite.config.ts
|
|
41
56
|
|
|
42
|
-
{
|
|
57
|
+
import { defineConfig as defineViteConfig, mergeConfig } from 'vite';
|
|
58
|
+
import { defineConfig as defineVitestConfig } from 'vitest/config';
|
|
59
|
+
|
|
60
|
+
const viteConfig = defineViteConfig({
|
|
43
61
|
...
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const vitestConfig = defineVitestConfig({
|
|
44
65
|
test: {
|
|
45
66
|
setupFiles: ['opfs-mock'],
|
|
46
67
|
},
|
|
47
|
-
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export default mergeConfig(viteConfig, vitestConfig);
|
|
48
71
|
```
|
|
49
72
|
|
|
50
73
|
Alternatively you can create a new setup file which then imports this module.
|
|
@@ -60,13 +83,20 @@ Add that file to your `test.setupFiles` array:
|
|
|
60
83
|
```ts
|
|
61
84
|
// vite.config.ts
|
|
62
85
|
|
|
63
|
-
import { defineConfig } from 'vite'
|
|
86
|
+
import { defineConfig as defineViteConfig, mergeConfig } from 'vite';
|
|
87
|
+
import { defineConfig as defineVitestConfig } from 'vitest/config';
|
|
64
88
|
|
|
65
|
-
|
|
89
|
+
const viteConfig = defineViteConfig({
|
|
90
|
+
...
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const vitestConfig = defineVitestConfig({
|
|
66
94
|
test: {
|
|
67
95
|
setupFiles: ['vitest-setup.ts'],
|
|
68
|
-
}
|
|
96
|
+
},
|
|
69
97
|
});
|
|
98
|
+
|
|
99
|
+
export default mergeConfig(viteConfig, vitestConfig);
|
|
70
100
|
```
|
|
71
101
|
|
|
72
102
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
declare const mockOPFS: () => void;
|
|
3
|
-
declare const resetMockOPFS: () => void;
|
|
4
|
-
export { mockOPFS, resetMockOPFS, storage };
|
|
1
|
+
export declare const storageFactory: ({ usage, quota }?: StorageEstimate) => StorageManager;
|
|
2
|
+
export declare const mockOPFS: () => void;
|
|
3
|
+
export declare const resetMockOPFS: () => void;
|
package/dist/index.js
CHANGED
|
@@ -89,14 +89,14 @@ const g = (o, n) => ({
|
|
|
89
89
|
return r(void 0, e);
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
|
-
}, w = () => {
|
|
93
|
-
const
|
|
92
|
+
}, w = ({ usage: o = 0, quota: n = 0 } = {}) => {
|
|
93
|
+
const t = y("root");
|
|
94
94
|
return {
|
|
95
95
|
estimate: async () => ({
|
|
96
|
-
usage:
|
|
97
|
-
quota:
|
|
96
|
+
usage: o,
|
|
97
|
+
quota: n
|
|
98
98
|
}),
|
|
99
|
-
getDirectory: async () =>
|
|
99
|
+
getDirectory: async () => t,
|
|
100
100
|
persist: async () => !0,
|
|
101
101
|
persisted: async () => !0
|
|
102
102
|
};
|
|
@@ -124,5 +124,5 @@ typeof globalThis < "u" && b();
|
|
|
124
124
|
export {
|
|
125
125
|
b as mockOPFS,
|
|
126
126
|
h as resetMockOPFS,
|
|
127
|
-
w as
|
|
127
|
+
w as storageFactory
|
|
128
128
|
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opfs-mock",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Mock all origin private file system APIs for your Jest or Vitest tests",
|
|
6
|
-
"author": "
|
|
6
|
+
"author": "Jure Rotar <hello@jurerotar.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://github.com/jurerotar/opfs-mock#README",
|
|
9
9
|
"repository": {
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"release": "npm publish --access public"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@biomejs/biome": "1.9.
|
|
43
|
-
"typescript": "5.
|
|
44
|
-
"vite": "
|
|
45
|
-
"vitest": "2.1.
|
|
42
|
+
"@biomejs/biome": "1.9.4",
|
|
43
|
+
"typescript": "5.7.3",
|
|
44
|
+
"vite": "6.0.7",
|
|
45
|
+
"vitest": "2.1.8"
|
|
46
46
|
}
|
|
47
47
|
}
|