-
Notifications
You must be signed in to change notification settings - Fork 37
/
runtime.js
50 lines (50 loc) · 1.21 KB
/
runtime.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
export let onMessageListeners = [];
export const runtime = {
connect: jest.fn(function ({ name }) {
return {
name,
postMessage: jest.fn(),
onDisconnect: {
addListener: jest.fn(),
},
onMessage: {
addListener: jest.fn((listener) => {
onMessageListeners.push(listener);
}),
},
disconnect: jest.fn(),
};
}),
sendMessage: jest.fn((message, cb) => {
onMessageListeners.forEach((listener) => listener(message));
if (cb !== undefined) {
return cb();
}
return Promise.resolve();
}),
onMessage: {
addListener: jest.fn((listener) => {
onMessageListeners.push(listener);
}),
removeListener: jest.fn((listener) => {
onMessageListeners = onMessageListeners.filter(
(lstn) => lstn !== listener
);
}),
hasListener: jest.fn((listener) => onMessageListeners.includes(listener)),
},
onConnect: {
addListener: jest.fn(),
removeListener: jest.fn(),
hasListener: jest.fn(),
},
onInstalled: {
addListener: jest.fn(),
removeListener: jest.fn(),
hasListener: jest.fn(),
},
getURL: jest.fn(function (path) {
return path;
}),
openOptionsPage: jest.fn(),
};