forked from cschiller/zhongwen
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmock-extension-apis.js
78 lines (71 loc) · 2 KB
/
mock-extension-apis.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* global global */
import * as fs from "node:fs/promises";
let _storage = {};
global.chrome = {
tabs: {
onClicked: {
addListener: () => { throw Error("Not Implemented"); },
onUpdated: () => { throw Error("Not Implemented"); }
},
sendMessage: () => { throw Error("Not Implemented"); },
query: () => { throw Error("Not Implemented"); }
},
runtime: {
getURL(path) {
return path;
},
onMessage: {
addListener: () => { throw Error("Not Implemented"); }
}
},
action: {
onClicked: {
addListener: () => { throw Error("Not Implemented"); }
},
setBadgeBackgroundColor: () => {
throw Error("Not Implemented");
},
setBadgeText: () => {
throw Error("Not Implemented");
},
setIcon: () => {
throw Error("Not Implemented");
}
},
storage: {
local: {
clear: async () => { _storage = {}; },
set: async (obj) => { _storage = { ..._storage, ...obj, }; },
get: async (keys) => {
return keys.reduce(function (map, key) {
map[key] = _storage[key];
return map;
}, {});
}
}
},
windows: {
getAll: () => { throw Error("Not implemented") }
},
contextMenus: {
create: () => { throw Error("Not implemented") },
removeAll: () => { throw Error("Not implemented") },
onClicked: {
addListener: () => { throw Error("Not implemented") }
}
},
scripting: {
insertCSS: () => { throw Error("Not implemented") },
executeScript: () => { throw Error("Not implemented") },
}
};
global.fetch = async (input, init) => {
const data = await fs.readFile(input);
return new Response(
data.toString(), {
status: 200,
statusText: 'success',
headers: {},
}
);
};