jest-webextension-mock 3.8.13 → 3.8.14
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/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/storage.js +17 -14
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/storage.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
let store = {};
|
|
2
1
|
import { createEventListeners } from './createEventListeners';
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
let syncStore = {};
|
|
4
|
+
let localStore = {};
|
|
5
|
+
let managedStore = {};
|
|
6
|
+
|
|
7
|
+
function resolveKey(key, store) {
|
|
5
8
|
if (typeof key === 'string') {
|
|
6
9
|
const result = {};
|
|
7
10
|
result[key] = store[key];
|
|
@@ -23,7 +26,7 @@ function resolveKey(key) {
|
|
|
23
26
|
export const storage = {
|
|
24
27
|
sync: {
|
|
25
28
|
get: jest.fn((id, cb) => {
|
|
26
|
-
const result = id === null ?
|
|
29
|
+
const result = id === null ? syncStore : resolveKey(id, syncStore);
|
|
27
30
|
if (cb !== undefined) {
|
|
28
31
|
return cb(result);
|
|
29
32
|
}
|
|
@@ -36,7 +39,7 @@ export const storage = {
|
|
|
36
39
|
return Promise.resolve(0);
|
|
37
40
|
}),
|
|
38
41
|
set: jest.fn((payload, cb) => {
|
|
39
|
-
Object.keys(payload).forEach((key) => (
|
|
42
|
+
Object.keys(payload).forEach((key) => (syncStore[key] = payload[key]));
|
|
40
43
|
if (cb !== undefined) {
|
|
41
44
|
return cb();
|
|
42
45
|
}
|
|
@@ -44,14 +47,14 @@ export const storage = {
|
|
|
44
47
|
}),
|
|
45
48
|
remove: jest.fn((id, cb) => {
|
|
46
49
|
const keys = typeof id === 'string' ? [id] : id;
|
|
47
|
-
keys.forEach((key) => delete
|
|
50
|
+
keys.forEach((key) => delete syncStore[key]);
|
|
48
51
|
if (cb !== undefined) {
|
|
49
52
|
return cb();
|
|
50
53
|
}
|
|
51
54
|
return Promise.resolve();
|
|
52
55
|
}),
|
|
53
56
|
clear: jest.fn((cb) => {
|
|
54
|
-
|
|
57
|
+
syncStore = {};
|
|
55
58
|
if (cb !== undefined) {
|
|
56
59
|
return cb();
|
|
57
60
|
}
|
|
@@ -61,7 +64,7 @@ export const storage = {
|
|
|
61
64
|
},
|
|
62
65
|
local: {
|
|
63
66
|
get: jest.fn((id, cb) => {
|
|
64
|
-
const result = id === null ?
|
|
67
|
+
const result = id === null ? localStore : resolveKey(id, localStore);
|
|
65
68
|
if (cb !== undefined) {
|
|
66
69
|
return cb(result);
|
|
67
70
|
}
|
|
@@ -74,7 +77,7 @@ export const storage = {
|
|
|
74
77
|
return Promise.resolve(0);
|
|
75
78
|
}),
|
|
76
79
|
set: jest.fn((payload, cb) => {
|
|
77
|
-
Object.keys(payload).forEach((key) => (
|
|
80
|
+
Object.keys(payload).forEach((key) => (localStore[key] = payload[key]));
|
|
78
81
|
if (cb !== undefined) {
|
|
79
82
|
return cb();
|
|
80
83
|
}
|
|
@@ -82,14 +85,14 @@ export const storage = {
|
|
|
82
85
|
}),
|
|
83
86
|
remove: jest.fn((id, cb) => {
|
|
84
87
|
const keys = typeof id === 'string' ? [id] : id;
|
|
85
|
-
keys.forEach((key) => delete
|
|
88
|
+
keys.forEach((key) => delete localStore[key]);
|
|
86
89
|
if (cb !== undefined) {
|
|
87
90
|
return cb();
|
|
88
91
|
}
|
|
89
92
|
return Promise.resolve();
|
|
90
93
|
}),
|
|
91
94
|
clear: jest.fn((cb) => {
|
|
92
|
-
|
|
95
|
+
localStore = {};
|
|
93
96
|
if (cb !== undefined) {
|
|
94
97
|
return cb();
|
|
95
98
|
}
|
|
@@ -99,7 +102,7 @@ export const storage = {
|
|
|
99
102
|
},
|
|
100
103
|
managed: {
|
|
101
104
|
get: jest.fn((id, cb) => {
|
|
102
|
-
const result = id === null ?
|
|
105
|
+
const result = id === null ? managedStore : resolveKey(id, managedStore);
|
|
103
106
|
if (cb !== undefined) {
|
|
104
107
|
return cb(result);
|
|
105
108
|
}
|
|
@@ -112,7 +115,7 @@ export const storage = {
|
|
|
112
115
|
return Promise.resolve(0);
|
|
113
116
|
}),
|
|
114
117
|
set: jest.fn((payload, cb) => {
|
|
115
|
-
Object.keys(payload).forEach((key) => (
|
|
118
|
+
Object.keys(payload).forEach((key) => (managedStore[key] = payload[key]));
|
|
116
119
|
if (cb !== undefined) {
|
|
117
120
|
return cb();
|
|
118
121
|
}
|
|
@@ -120,14 +123,14 @@ export const storage = {
|
|
|
120
123
|
}),
|
|
121
124
|
remove: jest.fn((id, cb) => {
|
|
122
125
|
const keys = typeof id === 'string' ? [id] : id;
|
|
123
|
-
keys.forEach((key) => delete
|
|
126
|
+
keys.forEach((key) => delete managedStore[key]);
|
|
124
127
|
if (cb !== undefined) {
|
|
125
128
|
return cb();
|
|
126
129
|
}
|
|
127
130
|
return Promise.resolve();
|
|
128
131
|
}),
|
|
129
132
|
clear: jest.fn((cb) => {
|
|
130
|
-
|
|
133
|
+
managedStore = {};
|
|
131
134
|
if (cb !== undefined) {
|
|
132
135
|
return cb();
|
|
133
136
|
}
|