-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.setup.ts
40 lines (38 loc) · 1.5 KB
/
jest.setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/// <reference path="./node_modules/@types/chrome/index.d.ts" />
declare var global: typeof globalThis;
Object.assign(global, {
chrome: {
storage: {
local: {
__dict__: {
},
async clear() {
delete this.__dict__;
this.__dict__ = new Object();
return Promise.resolve();
},
async set(ensemble): Promise<void> {
const encoded = {};
Object.keys(ensemble).map(namespace => {
encoded[namespace] = JSON.stringify(ensemble[namespace]);
});
this.__dict__ = { ...this.__dict__, ...encoded };
return new Promise(resolve => setTimeout(() => resolve(), 0));
},
async remove(key) {
const keys = (key instanceof Array) ? key : [key];
keys.map(k => this.__dict___[k] = undefined);
return;
},
async get(namespace) {
const nss = (namespace instanceof Array) ? namespace : [namespace];
const result = nss.reduce((ctx, ns) => {
ctx[ns] = JSON.parse(this.__dict__[ns] || `{}`);
return ctx;
}, {});
return new Promise(resolve => setTimeout(() => resolve(result), 0));
}
},
}
}
});