jest-webextension-mock 3.9.1 → 4.0.0
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/.github/workflows/push.yml +1 -1
- package/CHANGELOG.md +6 -0
- package/__tests__/browserAction.test.js +8 -8
- package/__tests__/commands.test.js +2 -2
- package/__tests__/downloads.test.js +46 -25
- package/__tests__/notifications.test.js +10 -10
- package/__tests__/runtime.test.js +30 -19
- package/__tests__/tabs.test.js +26 -24
- package/dist/setup.js +87 -76
- package/package.json +12 -13
package/CHANGELOG.md
CHANGED
|
@@ -5,8 +5,8 @@ describe('browser.browserAction', () => {
|
|
|
5
5
|
browser.browserAction.setTitle(title);
|
|
6
6
|
expect(browser.browserAction.setTitle).toHaveBeenCalledWith(title);
|
|
7
7
|
});
|
|
8
|
-
test('getTitle', (
|
|
9
|
-
const callback = jest.fn(
|
|
8
|
+
test('getTitle', () => {
|
|
9
|
+
const callback = jest.fn();
|
|
10
10
|
expect(jest.isMockFunction(browser.browserAction.getTitle)).toBe(true);
|
|
11
11
|
browser.browserAction.getTitle({}, callback);
|
|
12
12
|
expect(browser.browserAction.getTitle).toHaveBeenCalledTimes(1);
|
|
@@ -29,8 +29,8 @@ describe('browser.browserAction', () => {
|
|
|
29
29
|
browser.browserAction.setPopup(details);
|
|
30
30
|
expect(browser.browserAction.setPopup).toHaveBeenCalledWith(details);
|
|
31
31
|
});
|
|
32
|
-
test('getPopup', (
|
|
33
|
-
const callback = jest.fn(
|
|
32
|
+
test('getPopup', () => {
|
|
33
|
+
const callback = jest.fn();
|
|
34
34
|
expect(jest.isMockFunction(browser.browserAction.getPopup)).toBe(true);
|
|
35
35
|
browser.browserAction.getPopup({}, callback);
|
|
36
36
|
expect(browser.browserAction.getPopup).toHaveBeenCalledTimes(1);
|
|
@@ -46,8 +46,8 @@ describe('browser.browserAction', () => {
|
|
|
46
46
|
browser.browserAction.setBadgeText(text);
|
|
47
47
|
expect(browser.browserAction.setBadgeText).toHaveBeenCalledWith(text);
|
|
48
48
|
});
|
|
49
|
-
test('getBadgeText', (
|
|
50
|
-
const callback = jest.fn(
|
|
49
|
+
test('getBadgeText', () => {
|
|
50
|
+
const callback = jest.fn();
|
|
51
51
|
expect(jest.isMockFunction(browser.browserAction.getBadgeText)).toBe(true);
|
|
52
52
|
browser.browserAction.getBadgeText({}, callback);
|
|
53
53
|
expect(browser.browserAction.getBadgeText).toHaveBeenCalledTimes(1);
|
|
@@ -69,8 +69,8 @@ describe('browser.browserAction', () => {
|
|
|
69
69
|
details
|
|
70
70
|
);
|
|
71
71
|
});
|
|
72
|
-
test('getBadgeBackgroundColor', (
|
|
73
|
-
const callback = jest.fn(
|
|
72
|
+
test('getBadgeBackgroundColor', () => {
|
|
73
|
+
const callback = jest.fn();
|
|
74
74
|
expect(
|
|
75
75
|
jest.isMockFunction(browser.browserAction.getBadgeBackgroundColor)
|
|
76
76
|
).toBe(true);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
describe('browser.commands', () => {
|
|
2
|
-
test('getAll', (
|
|
3
|
-
const callback = jest.fn(
|
|
2
|
+
test('getAll', () => {
|
|
3
|
+
const callback = jest.fn();
|
|
4
4
|
expect(jest.isMockFunction(browser.commands.getAll)).toBe(true);
|
|
5
5
|
browser.commands.getAll(callback);
|
|
6
6
|
expect(browser.commands.getAll).toHaveBeenCalledTimes(1);
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
describe('browser.downloads', () => {
|
|
2
|
-
test('acceptDanger', (
|
|
2
|
+
test('acceptDanger', () => {
|
|
3
3
|
const downloadId = 1;
|
|
4
|
-
const callback = jest.fn(
|
|
4
|
+
const callback = jest.fn();
|
|
5
5
|
|
|
6
6
|
expect(jest.isMockFunction(chrome.downloads.acceptDanger)).toBe(true);
|
|
7
7
|
chrome.downloads.acceptDanger(downloadId, callback);
|
|
8
8
|
expect(chrome.downloads.acceptDanger).toHaveBeenCalledTimes(1);
|
|
9
|
-
expect(chrome.downloads.acceptDanger).toHaveBeenLastCalledWith(
|
|
9
|
+
expect(chrome.downloads.acceptDanger).toHaveBeenLastCalledWith(
|
|
10
|
+
downloadId,
|
|
11
|
+
callback
|
|
12
|
+
);
|
|
10
13
|
expect(callback).toHaveBeenCalled();
|
|
11
14
|
});
|
|
12
15
|
test('acceptDanger Promise', () => {
|
|
@@ -14,14 +17,17 @@ describe('browser.downloads', () => {
|
|
|
14
17
|
|
|
15
18
|
expect(chrome.downloads.acceptDanger(downloadId)).resolves.toBeUndefined();
|
|
16
19
|
});
|
|
17
|
-
test('cancel', (
|
|
20
|
+
test('cancel', () => {
|
|
18
21
|
const downloadId = 1;
|
|
19
|
-
const callback = jest.fn(
|
|
22
|
+
const callback = jest.fn();
|
|
20
23
|
|
|
21
24
|
expect(jest.isMockFunction(chrome.downloads.cancel)).toBe(true);
|
|
22
25
|
chrome.downloads.cancel(downloadId, callback);
|
|
23
26
|
expect(chrome.downloads.cancel).toHaveBeenCalledTimes(1);
|
|
24
|
-
expect(chrome.downloads.cancel).toHaveBeenLastCalledWith(
|
|
27
|
+
expect(chrome.downloads.cancel).toHaveBeenLastCalledWith(
|
|
28
|
+
downloadId,
|
|
29
|
+
callback
|
|
30
|
+
);
|
|
25
31
|
expect(callback).toHaveBeenCalled();
|
|
26
32
|
});
|
|
27
33
|
test('cancel Promise', () => {
|
|
@@ -29,14 +35,17 @@ describe('browser.downloads', () => {
|
|
|
29
35
|
|
|
30
36
|
expect(chrome.downloads.cancel(downloadId)).resolves.toBeUndefined();
|
|
31
37
|
});
|
|
32
|
-
test('download', (
|
|
38
|
+
test('download', () => {
|
|
33
39
|
const options = {};
|
|
34
|
-
const callback = jest.fn(
|
|
40
|
+
const callback = jest.fn();
|
|
35
41
|
|
|
36
42
|
expect(jest.isMockFunction(chrome.downloads.download)).toBe(true);
|
|
37
43
|
chrome.downloads.download(options, callback);
|
|
38
44
|
expect(chrome.downloads.download).toHaveBeenCalledTimes(1);
|
|
39
|
-
expect(chrome.downloads.download).toHaveBeenLastCalledWith(
|
|
45
|
+
expect(chrome.downloads.download).toHaveBeenLastCalledWith(
|
|
46
|
+
options,
|
|
47
|
+
callback
|
|
48
|
+
);
|
|
40
49
|
expect(callback).toHaveBeenCalled();
|
|
41
50
|
});
|
|
42
51
|
test('download Promise', () => {
|
|
@@ -44,9 +53,9 @@ describe('browser.downloads', () => {
|
|
|
44
53
|
|
|
45
54
|
expect(chrome.downloads.download(options)).resolves.toBeUndefined();
|
|
46
55
|
});
|
|
47
|
-
test('erase', (
|
|
56
|
+
test('erase', () => {
|
|
48
57
|
const query = {};
|
|
49
|
-
const callback = jest.fn(
|
|
58
|
+
const callback = jest.fn();
|
|
50
59
|
|
|
51
60
|
expect(jest.isMockFunction(chrome.downloads.erase)).toBe(true);
|
|
52
61
|
chrome.downloads.erase(query, callback);
|
|
@@ -59,14 +68,17 @@ describe('browser.downloads', () => {
|
|
|
59
68
|
|
|
60
69
|
expect(chrome.downloads.erase(query)).resolves.toBeUndefined();
|
|
61
70
|
});
|
|
62
|
-
test('getFileIcon', (
|
|
71
|
+
test('getFileIcon', () => {
|
|
63
72
|
const downloadId = 1;
|
|
64
|
-
const callback = jest.fn(
|
|
73
|
+
const callback = jest.fn();
|
|
65
74
|
|
|
66
75
|
expect(jest.isMockFunction(chrome.downloads.getFileIcon)).toBe(true);
|
|
67
76
|
chrome.downloads.getFileIcon(downloadId, callback);
|
|
68
77
|
expect(chrome.downloads.getFileIcon).toHaveBeenCalledTimes(1);
|
|
69
|
-
expect(chrome.downloads.getFileIcon).toHaveBeenLastCalledWith(
|
|
78
|
+
expect(chrome.downloads.getFileIcon).toHaveBeenLastCalledWith(
|
|
79
|
+
downloadId,
|
|
80
|
+
callback
|
|
81
|
+
);
|
|
70
82
|
expect(callback).toHaveBeenCalled();
|
|
71
83
|
});
|
|
72
84
|
test('getFileIcon Promise', () => {
|
|
@@ -82,14 +94,17 @@ describe('browser.downloads', () => {
|
|
|
82
94
|
expect(chrome.downloads.open).toHaveBeenCalledTimes(1);
|
|
83
95
|
expect(chrome.downloads.open).toHaveBeenLastCalledWith(downloadId);
|
|
84
96
|
});
|
|
85
|
-
test('pause', (
|
|
97
|
+
test('pause', () => {
|
|
86
98
|
const downloadId = 1;
|
|
87
|
-
const callback = jest.fn(
|
|
99
|
+
const callback = jest.fn();
|
|
88
100
|
|
|
89
101
|
expect(jest.isMockFunction(chrome.downloads.pause)).toBe(true);
|
|
90
102
|
chrome.downloads.pause(downloadId, callback);
|
|
91
103
|
expect(chrome.downloads.pause).toHaveBeenCalledTimes(1);
|
|
92
|
-
expect(chrome.downloads.pause).toHaveBeenLastCalledWith(
|
|
104
|
+
expect(chrome.downloads.pause).toHaveBeenLastCalledWith(
|
|
105
|
+
downloadId,
|
|
106
|
+
callback
|
|
107
|
+
);
|
|
93
108
|
expect(callback).toHaveBeenCalled();
|
|
94
109
|
});
|
|
95
110
|
test('pause Promise', () => {
|
|
@@ -97,14 +112,17 @@ describe('browser.downloads', () => {
|
|
|
97
112
|
|
|
98
113
|
expect(chrome.downloads.pause(downloadId)).resolves.toBeUndefined();
|
|
99
114
|
});
|
|
100
|
-
test('removeFile', (
|
|
115
|
+
test('removeFile', () => {
|
|
101
116
|
const downloadId = 1;
|
|
102
|
-
const callback = jest.fn(
|
|
117
|
+
const callback = jest.fn();
|
|
103
118
|
|
|
104
119
|
expect(jest.isMockFunction(chrome.downloads.removeFile)).toBe(true);
|
|
105
120
|
chrome.downloads.removeFile(downloadId, callback);
|
|
106
121
|
expect(chrome.downloads.removeFile).toHaveBeenCalledTimes(1);
|
|
107
|
-
expect(chrome.downloads.removeFile).toHaveBeenLastCalledWith(
|
|
122
|
+
expect(chrome.downloads.removeFile).toHaveBeenLastCalledWith(
|
|
123
|
+
downloadId,
|
|
124
|
+
callback
|
|
125
|
+
);
|
|
108
126
|
expect(callback).toHaveBeenCalled();
|
|
109
127
|
});
|
|
110
128
|
test('removeFile Promise', () => {
|
|
@@ -112,14 +130,17 @@ describe('browser.downloads', () => {
|
|
|
112
130
|
|
|
113
131
|
expect(chrome.downloads.removeFile(downloadId)).resolves.toBeUndefined();
|
|
114
132
|
});
|
|
115
|
-
test('resume', (
|
|
133
|
+
test('resume', () => {
|
|
116
134
|
const downloadId = 1;
|
|
117
|
-
const callback = jest.fn(
|
|
135
|
+
const callback = jest.fn();
|
|
118
136
|
|
|
119
137
|
expect(jest.isMockFunction(chrome.downloads.resume)).toBe(true);
|
|
120
138
|
chrome.downloads.resume(downloadId, callback);
|
|
121
139
|
expect(chrome.downloads.resume).toHaveBeenCalledTimes(1);
|
|
122
|
-
expect(chrome.downloads.resume).toHaveBeenLastCalledWith(
|
|
140
|
+
expect(chrome.downloads.resume).toHaveBeenLastCalledWith(
|
|
141
|
+
downloadId,
|
|
142
|
+
callback
|
|
143
|
+
);
|
|
123
144
|
expect(callback).toHaveBeenCalled();
|
|
124
145
|
});
|
|
125
146
|
test('resume Promise', () => {
|
|
@@ -127,9 +148,9 @@ describe('browser.downloads', () => {
|
|
|
127
148
|
|
|
128
149
|
expect(chrome.downloads.resume(downloadId)).resolves.toBeUndefined();
|
|
129
150
|
});
|
|
130
|
-
test('search', (
|
|
151
|
+
test('search', () => {
|
|
131
152
|
const query = {};
|
|
132
|
-
const callback = jest.fn(
|
|
153
|
+
const callback = jest.fn();
|
|
133
154
|
|
|
134
155
|
expect(jest.isMockFunction(chrome.downloads.search)).toBe(true);
|
|
135
156
|
chrome.downloads.search(query, callback);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
describe('chrome.notifications', () => {
|
|
2
|
-
test('create', (
|
|
2
|
+
test('create', () => {
|
|
3
3
|
const options = { type: 'basic' };
|
|
4
|
-
const callback = jest.fn(
|
|
4
|
+
const callback = jest.fn();
|
|
5
5
|
|
|
6
6
|
expect(jest.isMockFunction(chrome.notifications.create)).toBe(true);
|
|
7
7
|
|
|
@@ -31,9 +31,9 @@ describe('chrome.notifications', () => {
|
|
|
31
31
|
);
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
test('update', (
|
|
34
|
+
test('update', () => {
|
|
35
35
|
const options = { type: 'basic' };
|
|
36
|
-
const callback = jest.fn(
|
|
36
|
+
const callback = jest.fn();
|
|
37
37
|
|
|
38
38
|
expect(jest.isMockFunction(chrome.notifications.update)).toBe(true);
|
|
39
39
|
chrome.notifications.update('id', options, callback);
|
|
@@ -52,8 +52,8 @@ describe('chrome.notifications', () => {
|
|
|
52
52
|
return expect(chrome.notifications.update(options)).resolves.toBe(true);
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
test('clear', (
|
|
56
|
-
const callback = jest.fn(
|
|
55
|
+
test('clear', () => {
|
|
56
|
+
const callback = jest.fn();
|
|
57
57
|
|
|
58
58
|
expect(jest.isMockFunction(chrome.notifications.clear)).toBe(true);
|
|
59
59
|
chrome.notifications.clear('id', callback);
|
|
@@ -66,8 +66,8 @@ describe('chrome.notifications', () => {
|
|
|
66
66
|
return expect(chrome.notifications.clear('id')).resolves.toBe(true);
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
test('getAll', (
|
|
70
|
-
const callback = jest.fn(
|
|
69
|
+
test('getAll', () => {
|
|
70
|
+
const callback = jest.fn();
|
|
71
71
|
|
|
72
72
|
expect(jest.isMockFunction(chrome.notifications.getAll)).toBe(true);
|
|
73
73
|
chrome.notifications.getAll(callback);
|
|
@@ -80,8 +80,8 @@ describe('chrome.notifications', () => {
|
|
|
80
80
|
return expect(chrome.notifications.getAll()).resolves.toEqual([]);
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
test('getPermissionLevel', (
|
|
84
|
-
const callback = jest.fn(
|
|
83
|
+
test('getPermissionLevel', () => {
|
|
84
|
+
const callback = jest.fn();
|
|
85
85
|
|
|
86
86
|
expect(jest.isMockFunction(chrome.notifications.getPermissionLevel)).toBe(
|
|
87
87
|
true
|
|
@@ -20,23 +20,26 @@ describe('browser.runtime', () => {
|
|
|
20
20
|
expect(jest.isMockFunction(connection.disconnect)).toBe(true);
|
|
21
21
|
expect(browser.runtime.connect).toHaveBeenCalledTimes(1);
|
|
22
22
|
});
|
|
23
|
-
test('connect.onMessage listener', (
|
|
23
|
+
test('connect.onMessage listener', () => {
|
|
24
24
|
const name = 'CONNECT_NAME';
|
|
25
25
|
const listener = jest.fn();
|
|
26
|
+
const callback = jest.fn();
|
|
26
27
|
browser.runtime.connect(name).onMessage.addListener(listener);
|
|
27
|
-
browser.runtime.sendMessage({ test: 'message' },
|
|
28
|
+
browser.runtime.sendMessage({ test: 'message' }, callback);
|
|
28
29
|
expect(listener).toHaveBeenCalledWith({ test: 'message' });
|
|
30
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
29
31
|
});
|
|
30
32
|
test('getURL', () => {
|
|
31
33
|
const path = 'TEST_PATH';
|
|
32
|
-
const extensionOriginURL =
|
|
34
|
+
const extensionOriginURL =
|
|
35
|
+
globalThis[Symbol.for('jest-webextension-mock')].extensionPath;
|
|
33
36
|
expect(jest.isMockFunction(browser.runtime.getURL)).toBe(true);
|
|
34
37
|
const respPath = browser.runtime.getURL(path);
|
|
35
38
|
expect(respPath).toEqual(extensionOriginURL + path);
|
|
36
39
|
expect(browser.runtime.getURL).toHaveBeenCalledTimes(1);
|
|
37
40
|
});
|
|
38
|
-
test('sendMessage', (
|
|
39
|
-
const callback = jest.fn(
|
|
41
|
+
test('sendMessage', () => {
|
|
42
|
+
const callback = jest.fn();
|
|
40
43
|
expect(jest.isMockFunction(browser.runtime.sendMessage)).toBe(true);
|
|
41
44
|
browser.runtime.sendMessage({ test: 'message' }, callback);
|
|
42
45
|
expect(browser.runtime.sendMessage).toHaveBeenCalledTimes(1);
|
|
@@ -44,11 +47,13 @@ describe('browser.runtime', () => {
|
|
|
44
47
|
browser.runtime.sendMessage({ test: 'message' });
|
|
45
48
|
expect(browser.runtime.sendMessage).toHaveBeenCalledTimes(2);
|
|
46
49
|
});
|
|
47
|
-
test('sendMessage listener', (
|
|
50
|
+
test('sendMessage listener', () => {
|
|
48
51
|
const listener = jest.fn();
|
|
52
|
+
const callback = jest.fn();
|
|
49
53
|
browser.runtime.onMessage.addListener(listener);
|
|
50
|
-
browser.runtime.sendMessage({ test: 'message' },
|
|
54
|
+
browser.runtime.sendMessage({ test: 'message' }, callback);
|
|
51
55
|
expect(listener).toHaveBeenCalledWith({ test: 'message' });
|
|
56
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
52
57
|
});
|
|
53
58
|
test('sendMessage promise', () => {
|
|
54
59
|
return expect(browser.runtime.sendMessage({})).resolves.toBeUndefined();
|
|
@@ -85,32 +90,38 @@ describe('browser.runtime', () => {
|
|
|
85
90
|
});
|
|
86
91
|
test(`onMessageExternal.addListener`, () => {
|
|
87
92
|
const callback = jest.fn();
|
|
88
|
-
expect(
|
|
89
|
-
|
|
90
|
-
);
|
|
93
|
+
expect(
|
|
94
|
+
jest.isMockFunction(browser.runtime.onMessageExternal.addListener)
|
|
95
|
+
).toBe(true);
|
|
91
96
|
browser.runtime.onMessageExternal.addListener(callback);
|
|
92
|
-
expect(browser.runtime.onMessageExternal.addListener).toHaveBeenCalledTimes(
|
|
97
|
+
expect(browser.runtime.onMessageExternal.addListener).toHaveBeenCalledTimes(
|
|
98
|
+
1
|
|
99
|
+
);
|
|
93
100
|
expect(callback).toHaveBeenCalledTimes(0);
|
|
94
101
|
});
|
|
95
102
|
test(`onMessageExternal.removeListener`, () => {
|
|
96
103
|
const callback = jest.fn();
|
|
97
|
-
expect(
|
|
98
|
-
|
|
99
|
-
);
|
|
104
|
+
expect(
|
|
105
|
+
jest.isMockFunction(browser.runtime.onMessageExternal.removeListener)
|
|
106
|
+
).toBe(true);
|
|
100
107
|
browser.runtime.onMessageExternal.removeListener(callback);
|
|
101
108
|
expect(browser.runtime.onMessageExternal.hasListener(callback)).toBe(false);
|
|
102
|
-
expect(
|
|
109
|
+
expect(
|
|
110
|
+
browser.runtime.onMessageExternal.removeListener
|
|
111
|
+
).toHaveBeenCalledTimes(1);
|
|
103
112
|
expect(callback).toHaveBeenCalledTimes(0);
|
|
104
113
|
});
|
|
105
114
|
test(`onMessageExternal.hasListener`, () => {
|
|
106
115
|
const callback = jest.fn();
|
|
107
|
-
expect(
|
|
108
|
-
|
|
109
|
-
);
|
|
116
|
+
expect(
|
|
117
|
+
jest.isMockFunction(browser.runtime.onMessageExternal.hasListener)
|
|
118
|
+
).toBe(true);
|
|
110
119
|
browser.runtime.onMessageExternal.addListener(callback);
|
|
111
120
|
const returnVal = browser.runtime.onMessageExternal.hasListener(callback);
|
|
112
121
|
expect(returnVal).toBe(true);
|
|
113
|
-
expect(browser.runtime.onMessageExternal.hasListener).toHaveBeenCalledTimes(
|
|
122
|
+
expect(browser.runtime.onMessageExternal.hasListener).toHaveBeenCalledTimes(
|
|
123
|
+
1
|
|
124
|
+
);
|
|
114
125
|
expect(callback).toHaveBeenCalledTimes(0);
|
|
115
126
|
});
|
|
116
127
|
['addListener', 'removeListener', 'hasListener'].forEach((method) => {
|
package/__tests__/tabs.test.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
describe('browser.tabs', () => {
|
|
2
|
-
test('get', (
|
|
3
|
-
const callback = jest.fn(
|
|
2
|
+
test('get', () => {
|
|
3
|
+
const callback = jest.fn();
|
|
4
4
|
expect(jest.isMockFunction(chrome.tabs.get)).toBe(true);
|
|
5
5
|
chrome.tabs.get(1, callback);
|
|
6
6
|
expect(chrome.tabs.get).toHaveBeenCalledTimes(1);
|
|
7
7
|
expect(callback).toHaveBeenCalledTimes(1);
|
|
8
8
|
});
|
|
9
|
-
test('getCurrent', (
|
|
10
|
-
const callback = jest.fn(
|
|
9
|
+
test('getCurrent', () => {
|
|
10
|
+
const callback = jest.fn();
|
|
11
11
|
expect(jest.isMockFunction(chrome.tabs.getCurrent)).toBe(true);
|
|
12
12
|
chrome.tabs.getCurrent(callback);
|
|
13
13
|
expect(chrome.tabs.getCurrent).toHaveBeenCalledTimes(1);
|
|
@@ -24,8 +24,8 @@ describe('browser.tabs', () => {
|
|
|
24
24
|
expect(jest.isMockFunction(connection.onMessage.addListener)).toBe(true);
|
|
25
25
|
expect(chrome.tabs.connect).toHaveBeenCalledTimes(1);
|
|
26
26
|
});
|
|
27
|
-
test('create', (
|
|
28
|
-
const callback = jest.fn(
|
|
27
|
+
test('create', () => {
|
|
28
|
+
const callback = jest.fn();
|
|
29
29
|
const props = { pinned: true };
|
|
30
30
|
expect(jest.isMockFunction(chrome.tabs.create)).toBe(true);
|
|
31
31
|
chrome.tabs.create(props, callback);
|
|
@@ -37,16 +37,16 @@ describe('browser.tabs', () => {
|
|
|
37
37
|
const props = { pinned: true };
|
|
38
38
|
return expect(chrome.tabs.create(props)).resolves.toBe(props);
|
|
39
39
|
});
|
|
40
|
-
test('duplicate', (
|
|
41
|
-
const callback = jest.fn(
|
|
40
|
+
test('duplicate', () => {
|
|
41
|
+
const callback = jest.fn();
|
|
42
42
|
expect(jest.isMockFunction(chrome.tabs.duplicate)).toBe(true);
|
|
43
43
|
chrome.tabs.duplicate(1, callback);
|
|
44
44
|
expect(chrome.tabs.duplicate).toHaveBeenCalledTimes(1);
|
|
45
45
|
expect(callback).toHaveBeenCalledTimes(1);
|
|
46
46
|
expect(callback).toHaveBeenCalledWith({ id: 1 });
|
|
47
47
|
});
|
|
48
|
-
test('remove', (
|
|
49
|
-
const callback = jest.fn(
|
|
48
|
+
test('remove', () => {
|
|
49
|
+
const callback = jest.fn();
|
|
50
50
|
expect(jest.isMockFunction(chrome.tabs.remove)).toBe(true);
|
|
51
51
|
chrome.tabs.remove([1], callback);
|
|
52
52
|
expect(chrome.tabs.remove).toHaveBeenCalledTimes(1);
|
|
@@ -55,23 +55,23 @@ describe('browser.tabs', () => {
|
|
|
55
55
|
test('remove promise', () => {
|
|
56
56
|
expect(chrome.tabs.remove([1])).resolves.toBeUndefined();
|
|
57
57
|
});
|
|
58
|
-
test('query', (
|
|
59
|
-
const callback = jest.fn(
|
|
58
|
+
test('query', () => {
|
|
59
|
+
const callback = jest.fn();
|
|
60
60
|
expect(jest.isMockFunction(chrome.tabs.query)).toBe(true);
|
|
61
61
|
chrome.tabs.query({ pinned: true }, callback);
|
|
62
62
|
expect(chrome.tabs.query).toHaveBeenCalledTimes(1);
|
|
63
63
|
expect(callback).toHaveBeenCalledTimes(1);
|
|
64
64
|
expect(callback).toHaveBeenCalledWith([{}]);
|
|
65
65
|
});
|
|
66
|
-
test('highlight', (
|
|
67
|
-
const callback = jest.fn(
|
|
66
|
+
test('highlight', () => {
|
|
67
|
+
const callback = jest.fn();
|
|
68
68
|
expect(jest.isMockFunction(chrome.tabs.highlight)).toBe(true);
|
|
69
69
|
chrome.tabs.highlight({}, callback);
|
|
70
70
|
expect(chrome.tabs.highlight).toHaveBeenCalledTimes(1);
|
|
71
71
|
expect(callback).toHaveBeenCalledTimes(1);
|
|
72
72
|
});
|
|
73
|
-
test('update', (
|
|
74
|
-
const callback = jest.fn(
|
|
73
|
+
test('update', () => {
|
|
74
|
+
const callback = jest.fn();
|
|
75
75
|
const props = { pinned: true };
|
|
76
76
|
expect(jest.isMockFunction(chrome.tabs.update)).toBe(true);
|
|
77
77
|
chrome.tabs.update(1, props, callback);
|
|
@@ -81,8 +81,8 @@ describe('browser.tabs', () => {
|
|
|
81
81
|
chrome.tabs.update(props);
|
|
82
82
|
expect(chrome.tabs.update).toHaveBeenCalledTimes(2);
|
|
83
83
|
});
|
|
84
|
-
test('move', (
|
|
85
|
-
const callback = jest.fn(
|
|
84
|
+
test('move', () => {
|
|
85
|
+
const callback = jest.fn();
|
|
86
86
|
const props = { pinned: true };
|
|
87
87
|
expect(jest.isMockFunction(chrome.tabs.move)).toBe(true);
|
|
88
88
|
chrome.tabs.move([1, 2, 3], props, callback);
|
|
@@ -119,8 +119,8 @@ describe('browser.tabs', () => {
|
|
|
119
119
|
expect(callback).toHaveBeenCalledTimes(0);
|
|
120
120
|
});
|
|
121
121
|
});
|
|
122
|
-
test('reload', (
|
|
123
|
-
const callback = jest.fn(
|
|
122
|
+
test('reload', () => {
|
|
123
|
+
const callback = jest.fn();
|
|
124
124
|
expect(jest.isMockFunction(chrome.tabs.reload)).toBe(true);
|
|
125
125
|
|
|
126
126
|
chrome.tabs.reload(1, {}, callback);
|
|
@@ -128,8 +128,8 @@ describe('browser.tabs', () => {
|
|
|
128
128
|
expect(chrome.tabs.reload).toHaveBeenCalledTimes(1);
|
|
129
129
|
expect(callback).toHaveBeenCalledTimes(1);
|
|
130
130
|
});
|
|
131
|
-
test('sendMessage', (
|
|
132
|
-
const callback = jest.fn(
|
|
131
|
+
test('sendMessage', () => {
|
|
132
|
+
const callback = jest.fn();
|
|
133
133
|
expect(jest.isMockFunction(chrome.tabs.sendMessage)).toBe(true);
|
|
134
134
|
chrome.tabs.sendMessage(1, { test: 'message' }, callback);
|
|
135
135
|
expect(chrome.tabs.sendMessage).toHaveBeenCalledTimes(1);
|
|
@@ -137,11 +137,13 @@ describe('browser.tabs', () => {
|
|
|
137
137
|
chrome.tabs.sendMessage(1, { test: 'message' });
|
|
138
138
|
expect(chrome.tabs.sendMessage).toHaveBeenCalledTimes(2);
|
|
139
139
|
});
|
|
140
|
-
test('sendMessage listener', (
|
|
140
|
+
test('sendMessage listener', () => {
|
|
141
141
|
const listener = jest.fn();
|
|
142
|
+
const callback = jest.fn();
|
|
142
143
|
browser.runtime.onMessage.addListener(listener);
|
|
143
|
-
chrome.tabs.sendMessage(1, { test: 'message' },
|
|
144
|
+
chrome.tabs.sendMessage(1, { test: 'message' }, callback);
|
|
144
145
|
expect(listener).toHaveBeenCalledWith(1, { test: 'message' });
|
|
146
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
145
147
|
});
|
|
146
148
|
test('sendMessage promise', () => {
|
|
147
149
|
return expect(chrome.tabs.sendMessage({})).resolves.toBeUndefined();
|
package/dist/setup.js
CHANGED
|
@@ -1,93 +1,104 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
8
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
9
|
-
})), keys.push.apply(keys, symbols);
|
|
10
|
-
}
|
|
11
|
-
return keys;
|
|
3
|
+
function _arrayLikeToArray(r, a) {
|
|
4
|
+
(null == a || a > r.length) && (a = r.length);
|
|
5
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
6
|
+
return n;
|
|
12
7
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
function _arrayWithHoles(r) {
|
|
9
|
+
if (Array.isArray(r)) return r;
|
|
10
|
+
}
|
|
11
|
+
function _defineProperty(e, r, t) {
|
|
12
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
13
|
+
value: t,
|
|
14
|
+
enumerable: !0,
|
|
15
|
+
configurable: !0,
|
|
16
|
+
writable: !0
|
|
17
|
+
}) : e[r] = t, e;
|
|
18
|
+
}
|
|
19
|
+
function _iterableToArrayLimit(r, l) {
|
|
20
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
21
|
+
if (null != t) {
|
|
22
|
+
var e,
|
|
23
|
+
n,
|
|
24
|
+
i,
|
|
25
|
+
u,
|
|
26
|
+
a = [],
|
|
27
|
+
f = !0,
|
|
28
|
+
o = !1;
|
|
29
|
+
try {
|
|
30
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
31
|
+
if (Object(t) !== t) return;
|
|
32
|
+
f = !1;
|
|
33
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
34
|
+
} catch (r) {
|
|
35
|
+
o = !0, n = r;
|
|
36
|
+
} finally {
|
|
37
|
+
try {
|
|
38
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
39
|
+
} finally {
|
|
40
|
+
if (o) throw n;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return a;
|
|
21
44
|
}
|
|
22
|
-
return target;
|
|
23
45
|
}
|
|
24
|
-
function
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
28
|
-
return typeof obj;
|
|
29
|
-
} : function (obj) {
|
|
30
|
-
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
31
|
-
}, _typeof(obj);
|
|
46
|
+
function _nonIterableRest() {
|
|
47
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
32
48
|
}
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
} else {
|
|
42
|
-
obj[key] = value;
|
|
49
|
+
function ownKeys(e, r) {
|
|
50
|
+
var t = Object.keys(e);
|
|
51
|
+
if (Object.getOwnPropertySymbols) {
|
|
52
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
53
|
+
r && (o = o.filter(function (r) {
|
|
54
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
55
|
+
})), t.push.apply(t, o);
|
|
43
56
|
}
|
|
44
|
-
return
|
|
57
|
+
return t;
|
|
45
58
|
}
|
|
46
|
-
function
|
|
47
|
-
|
|
59
|
+
function _objectSpread2(e) {
|
|
60
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
61
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
62
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
63
|
+
_defineProperty(e, r, t[r]);
|
|
64
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
65
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return e;
|
|
48
69
|
}
|
|
49
|
-
function
|
|
50
|
-
|
|
70
|
+
function _slicedToArray(r, e) {
|
|
71
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
51
72
|
}
|
|
52
|
-
function
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
61
|
-
_arr.push(_s.value);
|
|
62
|
-
if (i && _arr.length === i) break;
|
|
63
|
-
}
|
|
64
|
-
} catch (err) {
|
|
65
|
-
_d = true;
|
|
66
|
-
_e = err;
|
|
67
|
-
} finally {
|
|
68
|
-
try {
|
|
69
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
70
|
-
} finally {
|
|
71
|
-
if (_d) throw _e;
|
|
72
|
-
}
|
|
73
|
+
function _toPrimitive(t, r) {
|
|
74
|
+
if ("object" != typeof t || !t) return t;
|
|
75
|
+
var e = t[Symbol.toPrimitive];
|
|
76
|
+
if (void 0 !== e) {
|
|
77
|
+
var i = e.call(t, r || "default");
|
|
78
|
+
if ("object" != typeof i) return i;
|
|
79
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
73
80
|
}
|
|
74
|
-
return
|
|
81
|
+
return ("string" === r ? String : Number)(t);
|
|
75
82
|
}
|
|
76
|
-
function
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
80
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
81
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
82
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
83
|
+
function _toPropertyKey(t) {
|
|
84
|
+
var i = _toPrimitive(t, "string");
|
|
85
|
+
return "symbol" == typeof i ? i : i + "";
|
|
83
86
|
}
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return
|
|
87
|
+
function _typeof(o) {
|
|
88
|
+
"@babel/helpers - typeof";
|
|
89
|
+
|
|
90
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
91
|
+
return typeof o;
|
|
92
|
+
} : function (o) {
|
|
93
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
94
|
+
}, _typeof(o);
|
|
88
95
|
}
|
|
89
|
-
function
|
|
90
|
-
|
|
96
|
+
function _unsupportedIterableToArray(r, a) {
|
|
97
|
+
if (r) {
|
|
98
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
99
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
100
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
101
|
+
}
|
|
91
102
|
}
|
|
92
103
|
|
|
93
104
|
// https://developer.chrome.com/extensions/omnibox
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jest-webextension-mock",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Mock the components of a WebExtension",
|
|
5
5
|
"main": "dist/setup.js",
|
|
6
6
|
"module": "src/setup.js",
|
|
@@ -18,20 +18,19 @@
|
|
|
18
18
|
"eslint-check": "eslint --print-config .eslintrc.js | eslint-config-prettier-check"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@babel/core": "^7.
|
|
22
|
-
"@babel/preset-env": "^7.
|
|
23
|
-
"@changesets/cli": "^2.27.
|
|
24
|
-
"babel-
|
|
25
|
-
"
|
|
26
|
-
"eslint": "^
|
|
27
|
-
"eslint-
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"rollup": "^2.30.0",
|
|
21
|
+
"@babel/core": "^7.25.8",
|
|
22
|
+
"@babel/preset-env": "^7.25.8",
|
|
23
|
+
"@changesets/cli": "^2.27.9",
|
|
24
|
+
"babel-jest": "^29.7.0",
|
|
25
|
+
"eslint": "^9.13.0",
|
|
26
|
+
"eslint-config-prettier": "^9.1.0",
|
|
27
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
28
|
+
"jest": "^29.7.0",
|
|
29
|
+
"prettier": "^3.3.3",
|
|
30
|
+
"rollup": "^2.79.2",
|
|
32
31
|
"rollup-plugin-babel": "^4.4.0",
|
|
33
32
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
34
|
-
"rollup-watch": "^4.
|
|
33
|
+
"rollup-watch": "^4.3.1"
|
|
35
34
|
},
|
|
36
35
|
"jest": {
|
|
37
36
|
"bail": true,
|