jest-webextension-mock 3.8.9 → 3.8.12
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/README.md +0 -7
- package/__tests__/permissions.test.js +39 -0
- package/__tests__/tabs.test.js +16 -0
- package/dist/setup.js +37 -62
- package/package.json +6 -5
- package/src/index.js +4 -2
- package/src/permissions.js +17 -0
- package/src/tabs.js +10 -0
- package/.github/workflows/publish.yml +0 -22
package/README.md
CHANGED
|
@@ -100,10 +100,3 @@ it('should toggle the profiler on from stopped', () => {
|
|
|
100
100
|
npm install
|
|
101
101
|
npm test
|
|
102
102
|
```
|
|
103
|
-
|
|
104
|
-
## Publish
|
|
105
|
-
|
|
106
|
-
Publishing new releases is automated via the GitHub Action https://github.com/mikeal/merge-release tool.
|
|
107
|
-
|
|
108
|
-
To ensure your feature is properly released prefix your commit message with `feat` for any new feature. For example: `feat: new API` and this will bump the minor release number. All other changes will be assumed as patch releases unless you include the string `BREAKING CHANGE` in your commit message or description which will trigger a new major release. (do not do this unless absolutely required)
|
|
109
|
-
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
test('chrome.permissions.contains', () => {
|
|
2
|
+
expect(jest.isMockFunction(chrome.permissions.contains)).toBe(true);
|
|
3
|
+
chrome.permissions.contains({ permissions: ['tabs'] }, () => {});
|
|
4
|
+
expect(chrome.permissions.contains).toBeCalled();
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
test('chrome.permissions.getAll', () => {
|
|
8
|
+
expect(jest.isMockFunction(chrome.permissions.getAll)).toBe(true);
|
|
9
|
+
chrome.permissions.getAll(() => {});
|
|
10
|
+
expect(chrome.permissions.getAll).toBeCalled();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('chrome.permissions.remove', () => {
|
|
14
|
+
expect(jest.isMockFunction(chrome.permissions.remove)).toBe(true);
|
|
15
|
+
chrome.permissions.remove({ permissions: ['tabs'] }, () => {});
|
|
16
|
+
expect(chrome.permissions.remove).toBeCalled();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('chrome.permissions.request', () => {
|
|
20
|
+
expect(jest.isMockFunction(chrome.permissions.request)).toBe(true);
|
|
21
|
+
chrome.permissions.request({ permissions: ['tabs'] }, () => {});
|
|
22
|
+
expect(chrome.permissions.request).toBeCalled();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('chrome.permissions.onAdded.addListener', () => {
|
|
26
|
+
expect(jest.isMockFunction(chrome.permissions.onAdded.addListener)).toBe(
|
|
27
|
+
true
|
|
28
|
+
);
|
|
29
|
+
chrome.permissions.onAdded.addListener(() => {});
|
|
30
|
+
expect(chrome.permissions.onAdded.addListener).toBeCalled();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('chrome.permissions.onRemoved.addListener', () => {
|
|
34
|
+
expect(jest.isMockFunction(chrome.permissions.onRemoved.addListener)).toBe(
|
|
35
|
+
true
|
|
36
|
+
);
|
|
37
|
+
chrome.permissions.onRemoved.addListener(() => {});
|
|
38
|
+
expect(chrome.permissions.onRemoved.addListener).toBeCalled();
|
|
39
|
+
});
|
package/__tests__/tabs.test.js
CHANGED
|
@@ -102,6 +102,22 @@ describe('browser.tabs', () => {
|
|
|
102
102
|
expect(browser.tabs.onUpdated[method]).toHaveBeenCalledTimes(1);
|
|
103
103
|
expect(callback).toHaveBeenCalledTimes(0);
|
|
104
104
|
});
|
|
105
|
+
|
|
106
|
+
test(`onRemoved.${method}`, () => {
|
|
107
|
+
const callback = jest.fn();
|
|
108
|
+
expect(jest.isMockFunction(browser.tabs.onRemoved[method])).toBe(true);
|
|
109
|
+
browser.tabs.onRemoved[method](callback);
|
|
110
|
+
expect(browser.tabs.onRemoved[method]).toHaveBeenCalledTimes(1);
|
|
111
|
+
expect(callback).toHaveBeenCalledTimes(0);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test(`onCreated.${method}`, () => {
|
|
115
|
+
const callback = jest.fn();
|
|
116
|
+
expect(jest.isMockFunction(browser.tabs.onCreated[method])).toBe(true);
|
|
117
|
+
browser.tabs.onCreated[method](callback);
|
|
118
|
+
expect(browser.tabs.onCreated[method]).toHaveBeenCalledTimes(1);
|
|
119
|
+
expect(callback).toHaveBeenCalledTimes(0);
|
|
120
|
+
});
|
|
105
121
|
});
|
|
106
122
|
test('reload', (done) => {
|
|
107
123
|
const callback = jest.fn(() => done());
|
package/dist/setup.js
CHANGED
|
@@ -2,17 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
function ownKeys(object, enumerableOnly) {
|
|
4
4
|
var keys = Object.keys(object);
|
|
5
|
-
|
|
6
5
|
if (Object.getOwnPropertySymbols) {
|
|
7
6
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
8
7
|
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
9
8
|
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
10
9
|
})), keys.push.apply(keys, symbols);
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
return keys;
|
|
14
12
|
}
|
|
15
|
-
|
|
16
13
|
function _objectSpread2(target) {
|
|
17
14
|
for (var i = 1; i < arguments.length; i++) {
|
|
18
15
|
var source = null != arguments[i] ? arguments[i] : {};
|
|
@@ -22,10 +19,8 @@ function _objectSpread2(target) {
|
|
|
22
19
|
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
23
20
|
});
|
|
24
21
|
}
|
|
25
|
-
|
|
26
22
|
return target;
|
|
27
23
|
}
|
|
28
|
-
|
|
29
24
|
function _typeof(obj) {
|
|
30
25
|
"@babel/helpers - typeof";
|
|
31
26
|
|
|
@@ -35,7 +30,6 @@ function _typeof(obj) {
|
|
|
35
30
|
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
36
31
|
}, _typeof(obj);
|
|
37
32
|
}
|
|
38
|
-
|
|
39
33
|
function _defineProperty(obj, key, value) {
|
|
40
34
|
if (key in obj) {
|
|
41
35
|
Object.defineProperty(obj, key, {
|
|
@@ -47,11 +41,11 @@ function _defineProperty(obj, key, value) {
|
|
|
47
41
|
} else {
|
|
48
42
|
obj[key] = value;
|
|
49
43
|
}
|
|
50
|
-
|
|
51
44
|
return obj;
|
|
52
45
|
}
|
|
53
46
|
|
|
54
47
|
// https://developer.chrome.com/extensions/omnibox
|
|
48
|
+
|
|
55
49
|
var omnibox = {
|
|
56
50
|
setDefaultSuggestion: jest.fn(),
|
|
57
51
|
onInputStarted: {
|
|
@@ -91,11 +85,9 @@ var runtime = {
|
|
|
91
85
|
onMessageListeners.forEach(function (listener) {
|
|
92
86
|
return listener(message);
|
|
93
87
|
});
|
|
94
|
-
|
|
95
88
|
if (cb !== undefined) {
|
|
96
89
|
return cb();
|
|
97
90
|
}
|
|
98
|
-
|
|
99
91
|
return Promise.resolve();
|
|
100
92
|
}),
|
|
101
93
|
onMessage: {
|
|
@@ -167,25 +159,22 @@ var tabs = {
|
|
|
167
159
|
onMessage: {
|
|
168
160
|
addListener: jest.fn()
|
|
169
161
|
},
|
|
170
|
-
postMessage: jest.fn()
|
|
171
|
-
|
|
162
|
+
postMessage: jest.fn()
|
|
163
|
+
// TODO: add sender
|
|
172
164
|
};
|
|
173
165
|
}),
|
|
174
166
|
create: jest.fn(function () {
|
|
175
167
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
176
168
|
var cb = arguments.length > 1 ? arguments[1] : undefined;
|
|
177
|
-
|
|
178
169
|
if (cb !== undefined) {
|
|
179
170
|
return cb(props);
|
|
180
171
|
}
|
|
181
|
-
|
|
182
172
|
return Promise.resolve(props);
|
|
183
173
|
}),
|
|
184
174
|
remove: jest.fn(function (tabIds, cb) {
|
|
185
175
|
if (cb !== undefined) {
|
|
186
176
|
return cb();
|
|
187
177
|
}
|
|
188
|
-
|
|
189
178
|
return Promise.resolve();
|
|
190
179
|
}),
|
|
191
180
|
duplicate: jest.fn(function () {
|
|
@@ -226,15 +215,23 @@ var tabs = {
|
|
|
226
215
|
removeListener: jest.fn(),
|
|
227
216
|
hasListener: jest.fn()
|
|
228
217
|
},
|
|
218
|
+
onRemoved: {
|
|
219
|
+
addListener: jest.fn(),
|
|
220
|
+
removeListener: jest.fn(),
|
|
221
|
+
hasListener: jest.fn()
|
|
222
|
+
},
|
|
223
|
+
onCreated: {
|
|
224
|
+
addListener: jest.fn(),
|
|
225
|
+
removeListener: jest.fn(),
|
|
226
|
+
hasListener: jest.fn()
|
|
227
|
+
},
|
|
229
228
|
sendMessage: jest.fn(function (tabId, message, cb) {
|
|
230
229
|
onMessageListeners.forEach(function (listener) {
|
|
231
230
|
return listener(tabId, message);
|
|
232
231
|
});
|
|
233
|
-
|
|
234
232
|
if (cb !== undefined) {
|
|
235
233
|
return cb();
|
|
236
234
|
}
|
|
237
|
-
|
|
238
235
|
return Promise.resolve();
|
|
239
236
|
}),
|
|
240
237
|
reload: jest.fn(function (tabId, reloadProperties, cb) {
|
|
@@ -243,7 +240,6 @@ var tabs = {
|
|
|
243
240
|
};
|
|
244
241
|
|
|
245
242
|
var store = {};
|
|
246
|
-
|
|
247
243
|
function resolveKey(key) {
|
|
248
244
|
if (typeof key === 'string') {
|
|
249
245
|
var result = {};
|
|
@@ -260,37 +256,30 @@ function resolveKey(key) {
|
|
|
260
256
|
return acc;
|
|
261
257
|
}, {});
|
|
262
258
|
}
|
|
263
|
-
|
|
264
259
|
throw new Error('Wrong key given');
|
|
265
260
|
}
|
|
266
|
-
|
|
267
261
|
var storage = {
|
|
268
262
|
sync: {
|
|
269
263
|
get: jest.fn(function (id, cb) {
|
|
270
264
|
var result = id === null ? store : resolveKey(id);
|
|
271
|
-
|
|
272
265
|
if (cb !== undefined) {
|
|
273
266
|
return cb(result);
|
|
274
267
|
}
|
|
275
|
-
|
|
276
268
|
return Promise.resolve(result);
|
|
277
269
|
}),
|
|
278
270
|
getBytesInUse: jest.fn(function (id, cb) {
|
|
279
271
|
if (cb !== undefined) {
|
|
280
272
|
return cb(0);
|
|
281
273
|
}
|
|
282
|
-
|
|
283
274
|
return Promise.resolve(0);
|
|
284
275
|
}),
|
|
285
276
|
set: jest.fn(function (payload, cb) {
|
|
286
277
|
Object.keys(payload).forEach(function (key) {
|
|
287
278
|
return store[key] = payload[key];
|
|
288
279
|
});
|
|
289
|
-
|
|
290
280
|
if (cb !== undefined) {
|
|
291
281
|
return cb();
|
|
292
282
|
}
|
|
293
|
-
|
|
294
283
|
return Promise.resolve();
|
|
295
284
|
}),
|
|
296
285
|
remove: jest.fn(function (id, cb) {
|
|
@@ -298,49 +287,40 @@ var storage = {
|
|
|
298
287
|
keys.forEach(function (key) {
|
|
299
288
|
return delete store[key];
|
|
300
289
|
});
|
|
301
|
-
|
|
302
290
|
if (cb !== undefined) {
|
|
303
291
|
return cb();
|
|
304
292
|
}
|
|
305
|
-
|
|
306
293
|
return Promise.resolve();
|
|
307
294
|
}),
|
|
308
295
|
clear: jest.fn(function (cb) {
|
|
309
296
|
store = {};
|
|
310
|
-
|
|
311
297
|
if (cb !== undefined) {
|
|
312
298
|
return cb();
|
|
313
299
|
}
|
|
314
|
-
|
|
315
300
|
return Promise.resolve();
|
|
316
301
|
})
|
|
317
302
|
},
|
|
318
303
|
local: {
|
|
319
304
|
get: jest.fn(function (id, cb) {
|
|
320
305
|
var result = id === null ? store : resolveKey(id);
|
|
321
|
-
|
|
322
306
|
if (cb !== undefined) {
|
|
323
307
|
return cb(result);
|
|
324
308
|
}
|
|
325
|
-
|
|
326
309
|
return Promise.resolve(result);
|
|
327
310
|
}),
|
|
328
311
|
getBytesInUse: jest.fn(function (id, cb) {
|
|
329
312
|
if (cb !== undefined) {
|
|
330
313
|
return cb(0);
|
|
331
314
|
}
|
|
332
|
-
|
|
333
315
|
return Promise.resolve(0);
|
|
334
316
|
}),
|
|
335
317
|
set: jest.fn(function (payload, cb) {
|
|
336
318
|
Object.keys(payload).forEach(function (key) {
|
|
337
319
|
return store[key] = payload[key];
|
|
338
320
|
});
|
|
339
|
-
|
|
340
321
|
if (cb !== undefined) {
|
|
341
322
|
return cb();
|
|
342
323
|
}
|
|
343
|
-
|
|
344
324
|
return Promise.resolve();
|
|
345
325
|
}),
|
|
346
326
|
remove: jest.fn(function (id, cb) {
|
|
@@ -348,49 +328,40 @@ var storage = {
|
|
|
348
328
|
keys.forEach(function (key) {
|
|
349
329
|
return delete store[key];
|
|
350
330
|
});
|
|
351
|
-
|
|
352
331
|
if (cb !== undefined) {
|
|
353
332
|
return cb();
|
|
354
333
|
}
|
|
355
|
-
|
|
356
334
|
return Promise.resolve();
|
|
357
335
|
}),
|
|
358
336
|
clear: jest.fn(function (cb) {
|
|
359
337
|
store = {};
|
|
360
|
-
|
|
361
338
|
if (cb !== undefined) {
|
|
362
339
|
return cb();
|
|
363
340
|
}
|
|
364
|
-
|
|
365
341
|
return Promise.resolve();
|
|
366
342
|
})
|
|
367
343
|
},
|
|
368
344
|
managed: {
|
|
369
345
|
get: jest.fn(function (id, cb) {
|
|
370
346
|
var result = id === null ? store : resolveKey(id);
|
|
371
|
-
|
|
372
347
|
if (cb !== undefined) {
|
|
373
348
|
return cb(result);
|
|
374
349
|
}
|
|
375
|
-
|
|
376
350
|
return Promise.resolve(result);
|
|
377
351
|
}),
|
|
378
352
|
getBytesInUse: jest.fn(function (id, cb) {
|
|
379
353
|
if (cb !== undefined) {
|
|
380
354
|
return cb(0);
|
|
381
355
|
}
|
|
382
|
-
|
|
383
356
|
return Promise.resolve(0);
|
|
384
357
|
}),
|
|
385
358
|
set: jest.fn(function (payload, cb) {
|
|
386
359
|
Object.keys(payload).forEach(function (key) {
|
|
387
360
|
return store[key] = payload[key];
|
|
388
361
|
});
|
|
389
|
-
|
|
390
362
|
if (cb !== undefined) {
|
|
391
363
|
return cb();
|
|
392
364
|
}
|
|
393
|
-
|
|
394
365
|
return Promise.resolve();
|
|
395
366
|
}),
|
|
396
367
|
remove: jest.fn(function (id, cb) {
|
|
@@ -398,20 +369,16 @@ var storage = {
|
|
|
398
369
|
keys.forEach(function (key) {
|
|
399
370
|
return delete store[key];
|
|
400
371
|
});
|
|
401
|
-
|
|
402
372
|
if (cb !== undefined) {
|
|
403
373
|
return cb();
|
|
404
374
|
}
|
|
405
|
-
|
|
406
375
|
return Promise.resolve();
|
|
407
376
|
}),
|
|
408
377
|
clear: jest.fn(function (cb) {
|
|
409
378
|
store = {};
|
|
410
|
-
|
|
411
379
|
if (cb !== undefined) {
|
|
412
380
|
return cb();
|
|
413
381
|
}
|
|
414
|
-
|
|
415
382
|
return Promise.resolve();
|
|
416
383
|
})
|
|
417
384
|
},
|
|
@@ -426,10 +393,8 @@ var getDetails = function getDetails(details, cb) {
|
|
|
426
393
|
if (cb !== undefined) {
|
|
427
394
|
return cb();
|
|
428
395
|
}
|
|
429
|
-
|
|
430
396
|
return Promise.resolve();
|
|
431
397
|
};
|
|
432
|
-
|
|
433
398
|
var browserAction = {
|
|
434
399
|
setTitle: jest.fn(),
|
|
435
400
|
getTitle: jest.fn(getDetails),
|
|
@@ -448,12 +413,12 @@ var browserAction = {
|
|
|
448
413
|
};
|
|
449
414
|
|
|
450
415
|
// https://developer.chrome.com/extensions/commands
|
|
416
|
+
|
|
451
417
|
var commands = {
|
|
452
418
|
getAll: jest.fn(function (cb) {
|
|
453
419
|
if (cb !== undefined) {
|
|
454
420
|
return cb();
|
|
455
421
|
}
|
|
456
|
-
|
|
457
422
|
return Promise.resolve();
|
|
458
423
|
}),
|
|
459
424
|
onCommand: {
|
|
@@ -465,22 +430,17 @@ var cbOrPromise$1 = function cbOrPromise(cb, value) {
|
|
|
465
430
|
if (cb !== undefined) {
|
|
466
431
|
return cb(value);
|
|
467
432
|
}
|
|
468
|
-
|
|
469
433
|
return Promise.resolve(value);
|
|
470
434
|
};
|
|
471
|
-
|
|
472
435
|
var create = function create(notificationId, options, cb) {
|
|
473
436
|
if (typeof notificationId !== 'string') {
|
|
474
437
|
notificationId = 'generated-id';
|
|
475
438
|
}
|
|
476
|
-
|
|
477
439
|
if (typeof options === 'function') {
|
|
478
440
|
cb = options;
|
|
479
441
|
}
|
|
480
|
-
|
|
481
442
|
return cbOrPromise$1(cb, notificationId);
|
|
482
443
|
};
|
|
483
|
-
|
|
484
444
|
var notifications = {
|
|
485
445
|
create: jest.fn(create),
|
|
486
446
|
update: jest.fn(function (notificationId, options, cb) {
|
|
@@ -540,10 +500,8 @@ var cbOrPromise = function cbOrPromise(cb, value) {
|
|
|
540
500
|
if (cb !== undefined) {
|
|
541
501
|
return cb(value);
|
|
542
502
|
}
|
|
543
|
-
|
|
544
503
|
return Promise.resolve(value);
|
|
545
504
|
};
|
|
546
|
-
|
|
547
505
|
var downloads = {
|
|
548
506
|
acceptDanger: jest.fn(function (downloadId, cb) {
|
|
549
507
|
return cbOrPromise(cb);
|
|
@@ -578,6 +536,20 @@ var downloads = {
|
|
|
578
536
|
showDefaultFolder: jest.fn()
|
|
579
537
|
};
|
|
580
538
|
|
|
539
|
+
// https://developer.chrome.com/extensions/permissions
|
|
540
|
+
var permissions = {
|
|
541
|
+
contains: jest.fn(),
|
|
542
|
+
getAll: jest.fn(),
|
|
543
|
+
remove: jest.fn(),
|
|
544
|
+
request: jest.fn(),
|
|
545
|
+
onAdded: {
|
|
546
|
+
addListener: jest.fn()
|
|
547
|
+
},
|
|
548
|
+
onRemoved: {
|
|
549
|
+
addListener: jest.fn()
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
|
|
581
553
|
var geckoProfiler = {
|
|
582
554
|
stop: jest.fn(function () {
|
|
583
555
|
return Promise.resolve();
|
|
@@ -620,7 +592,8 @@ var chrome = {
|
|
|
620
592
|
i18n: i18n,
|
|
621
593
|
webNavigation: webNavigation,
|
|
622
594
|
extension: extension,
|
|
623
|
-
downloads: downloads
|
|
595
|
+
downloads: downloads,
|
|
596
|
+
permissions: permissions
|
|
624
597
|
};
|
|
625
598
|
// Firefox uses 'browser' but aliases it to chrome
|
|
626
599
|
|
|
@@ -630,14 +603,16 @@ var chrome = {
|
|
|
630
603
|
* directly call the module in their `setupFiles` property.
|
|
631
604
|
*/
|
|
632
605
|
global.chrome = chrome;
|
|
633
|
-
global.browser = chrome;
|
|
606
|
+
global.browser = chrome;
|
|
607
|
+
|
|
608
|
+
// Firefox specific globals
|
|
634
609
|
// if (navigator.userAgent.indexOf('Firefox') !== -1) {
|
|
635
610
|
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts#exportFunction
|
|
636
|
-
|
|
637
611
|
global.exportFunction = jest.fn(function (func) {
|
|
638
612
|
return func;
|
|
639
|
-
});
|
|
640
|
-
|
|
613
|
+
});
|
|
614
|
+
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts#cloneInto
|
|
641
615
|
global.cloneInto = jest.fn(function (obj) {
|
|
642
616
|
return obj;
|
|
643
|
-
});
|
|
617
|
+
});
|
|
618
|
+
// }
|
package/package.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jest-webextension-mock",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.12",
|
|
4
4
|
"description": "Mock the components of a WebExtension",
|
|
5
5
|
"main": "dist/setup.js",
|
|
6
6
|
"module": "src/setup.js",
|
|
7
|
-
"author": "
|
|
7
|
+
"author": "Marwan Zibaoui <marwan.zibaoui@gmail.com> (https://mas.to/@Rickymarou)",
|
|
8
8
|
"license": "ISC",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/
|
|
11
|
+
"url": "https://github.com/RickyMarou/jest-webextension-mock"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
14
|
"test": "jest",
|
|
15
15
|
"build": "rollup -c",
|
|
16
|
+
"release": "bumpp && npm publish",
|
|
16
17
|
"prettier": "prettier --write \"{config,src,__{tests,setups}__}/**/*.js\" rollup.config.js",
|
|
17
18
|
"eslint-check": "eslint --print-config .eslintrc.js | eslint-config-prettier-check"
|
|
18
19
|
},
|
|
@@ -21,6 +22,7 @@
|
|
|
21
22
|
"@babel/preset-env": "^7.11.5",
|
|
22
23
|
"babel-core": "^7.0.0-bridge.0",
|
|
23
24
|
"babel-jest": "^26.5.2",
|
|
25
|
+
"bumpp": "^9.4.0",
|
|
24
26
|
"eslint": "^7.11.0",
|
|
25
27
|
"eslint-config-prettier": "^6.12.0",
|
|
26
28
|
"eslint-plugin-prettier": "^3.1.4",
|
|
@@ -44,6 +46,5 @@
|
|
|
44
46
|
"setupFiles": [
|
|
45
47
|
"./__setups__/chrome.js"
|
|
46
48
|
]
|
|
47
|
-
}
|
|
48
|
-
"dependencies": {}
|
|
49
|
+
}
|
|
49
50
|
}
|
package/src/index.js
CHANGED
|
@@ -9,13 +9,14 @@ import { i18n } from './i18n';
|
|
|
9
9
|
import { webNavigation } from './webNavigation';
|
|
10
10
|
import { extension } from './extension';
|
|
11
11
|
import { downloads } from './downloads';
|
|
12
|
+
import { permissions } from './permissions';
|
|
12
13
|
|
|
13
14
|
// Firefox specific API
|
|
14
15
|
import { geckoProfiler } from './geckoProfiler';
|
|
15
16
|
|
|
16
17
|
globalThis[Symbol.for('jest-webextension-mock')] = {
|
|
17
|
-
|
|
18
|
-
...globalThis[Symbol.for('jest-webextension-mock')]
|
|
18
|
+
extensionPath: 'moz-extension://8b413e68-1e0d-4cad-b98e-1eb000799783/',
|
|
19
|
+
...globalThis[Symbol.for('jest-webextension-mock')],
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
const chrome = {
|
|
@@ -31,6 +32,7 @@ const chrome = {
|
|
|
31
32
|
webNavigation,
|
|
32
33
|
extension,
|
|
33
34
|
downloads,
|
|
35
|
+
permissions,
|
|
34
36
|
};
|
|
35
37
|
|
|
36
38
|
export { chrome };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// https://developer.chrome.com/extensions/permissions
|
|
2
|
+
|
|
3
|
+
export let onMessageListeners = [];
|
|
4
|
+
export let onMessageExternalListeners = [];
|
|
5
|
+
|
|
6
|
+
export const permissions = {
|
|
7
|
+
contains: jest.fn(),
|
|
8
|
+
getAll: jest.fn(),
|
|
9
|
+
remove: jest.fn(),
|
|
10
|
+
request: jest.fn(),
|
|
11
|
+
onAdded: {
|
|
12
|
+
addListener: jest.fn(),
|
|
13
|
+
},
|
|
14
|
+
onRemoved: {
|
|
15
|
+
addListener: jest.fn(),
|
|
16
|
+
},
|
|
17
|
+
};
|
package/src/tabs.js
CHANGED
|
@@ -45,6 +45,16 @@ export const tabs = {
|
|
|
45
45
|
removeListener: jest.fn(),
|
|
46
46
|
hasListener: jest.fn(),
|
|
47
47
|
},
|
|
48
|
+
onRemoved: {
|
|
49
|
+
addListener: jest.fn(),
|
|
50
|
+
removeListener: jest.fn(),
|
|
51
|
+
hasListener: jest.fn(),
|
|
52
|
+
},
|
|
53
|
+
onCreated: {
|
|
54
|
+
addListener: jest.fn(),
|
|
55
|
+
removeListener: jest.fn(),
|
|
56
|
+
hasListener: jest.fn(),
|
|
57
|
+
},
|
|
48
58
|
sendMessage: jest.fn((tabId, message, cb) => {
|
|
49
59
|
onMessageListeners.forEach((listener) => listener(tabId, message));
|
|
50
60
|
if (cb !== undefined) {
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
on:
|
|
2
|
-
push:
|
|
3
|
-
branches:
|
|
4
|
-
- main
|
|
5
|
-
|
|
6
|
-
name: Publish
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
all:
|
|
10
|
-
name: Merge-Release
|
|
11
|
-
runs-on: ubuntu-latest
|
|
12
|
-
steps:
|
|
13
|
-
- uses: actions/checkout@v3
|
|
14
|
-
- run: npm ci
|
|
15
|
-
- run: npm test
|
|
16
|
-
- run: npm run build --if-present
|
|
17
|
-
- run: git status --porcelain dist/setup.js
|
|
18
|
-
- uses: mikeal/merge-release@master
|
|
19
|
-
if: github.ref == 'refs/heads/main'
|
|
20
|
-
env:
|
|
21
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
22
|
-
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
|