jest-webextension-mock 3.8.8 → 3.8.9
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/__tests__/runtime.test.js +2 -1
- package/dist/setup.js +56 -11
- package/package.json +1 -1
- package/src/index.js +5 -0
- package/src/runtime.js +2 -1
|
@@ -29,9 +29,10 @@ describe('browser.runtime', () => {
|
|
|
29
29
|
});
|
|
30
30
|
test('getURL', () => {
|
|
31
31
|
const path = 'TEST_PATH';
|
|
32
|
+
const extensionOriginURL = globalThis[Symbol.for('jest-webextension-mock')].extensionPath;
|
|
32
33
|
expect(jest.isMockFunction(browser.runtime.getURL)).toBe(true);
|
|
33
34
|
const respPath = browser.runtime.getURL(path);
|
|
34
|
-
expect(respPath).toEqual(path);
|
|
35
|
+
expect(respPath).toEqual(extensionOriginURL + path);
|
|
35
36
|
expect(browser.runtime.getURL).toHaveBeenCalledTimes(1);
|
|
36
37
|
});
|
|
37
38
|
test('sendMessage', (done) => {
|
package/dist/setup.js
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
function ownKeys(object, enumerableOnly) {
|
|
4
|
+
var keys = Object.keys(object);
|
|
5
|
+
|
|
6
|
+
if (Object.getOwnPropertySymbols) {
|
|
7
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
8
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
9
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
10
|
+
})), keys.push.apply(keys, symbols);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return keys;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function _objectSpread2(target) {
|
|
17
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
18
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
19
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
20
|
+
_defineProperty(target, key, source[key]);
|
|
21
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
22
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return target;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function _typeof(obj) {
|
|
30
|
+
"@babel/helpers - typeof";
|
|
31
|
+
|
|
32
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
33
|
+
return typeof obj;
|
|
34
|
+
} : function (obj) {
|
|
35
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
36
|
+
}, _typeof(obj);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function _defineProperty(obj, key, value) {
|
|
40
|
+
if (key in obj) {
|
|
41
|
+
Object.defineProperty(obj, key, {
|
|
42
|
+
value: value,
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
writable: true
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
obj[key] = value;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return obj;
|
|
52
|
+
}
|
|
53
|
+
|
|
3
54
|
// https://developer.chrome.com/extensions/omnibox
|
|
4
55
|
var omnibox = {
|
|
5
56
|
setDefaultSuggestion: jest.fn(),
|
|
@@ -84,7 +135,8 @@ var runtime = {
|
|
|
84
135
|
hasListener: jest.fn()
|
|
85
136
|
},
|
|
86
137
|
getURL: jest.fn(function (path) {
|
|
87
|
-
|
|
138
|
+
var origin = globalThis[Symbol["for"]('jest-webextension-mock')].extensionPath;
|
|
139
|
+
return String(new URL(path, origin));
|
|
88
140
|
}),
|
|
89
141
|
openOptionsPage: jest.fn(),
|
|
90
142
|
getManifest: jest.fn(function () {
|
|
@@ -190,16 +242,6 @@ var tabs = {
|
|
|
190
242
|
})
|
|
191
243
|
};
|
|
192
244
|
|
|
193
|
-
function _typeof(obj) {
|
|
194
|
-
"@babel/helpers - typeof";
|
|
195
|
-
|
|
196
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
197
|
-
return typeof obj;
|
|
198
|
-
} : function (obj) {
|
|
199
|
-
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
200
|
-
}, _typeof(obj);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
245
|
var store = {};
|
|
204
246
|
|
|
205
247
|
function resolveKey(key) {
|
|
@@ -563,6 +605,9 @@ var geckoProfiler = {
|
|
|
563
605
|
}
|
|
564
606
|
};
|
|
565
607
|
|
|
608
|
+
globalThis[Symbol["for"]('jest-webextension-mock')] = _objectSpread2({
|
|
609
|
+
extensionPath: 'moz-extension://8b413e68-1e0d-4cad-b98e-1eb000799783/'
|
|
610
|
+
}, globalThis[Symbol["for"]('jest-webextension-mock')]);
|
|
566
611
|
var chrome = {
|
|
567
612
|
omnibox: omnibox,
|
|
568
613
|
tabs: tabs,
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -13,6 +13,11 @@ import { downloads } from './downloads';
|
|
|
13
13
|
// Firefox specific API
|
|
14
14
|
import { geckoProfiler } from './geckoProfiler';
|
|
15
15
|
|
|
16
|
+
globalThis[Symbol.for('jest-webextension-mock')] = {
|
|
17
|
+
extensionPath: 'moz-extension://8b413e68-1e0d-4cad-b98e-1eb000799783/',
|
|
18
|
+
...globalThis[Symbol.for('jest-webextension-mock')]
|
|
19
|
+
};
|
|
20
|
+
|
|
16
21
|
const chrome = {
|
|
17
22
|
omnibox,
|
|
18
23
|
tabs,
|
package/src/runtime.js
CHANGED
|
@@ -56,7 +56,8 @@ export const runtime = {
|
|
|
56
56
|
hasListener: jest.fn(),
|
|
57
57
|
},
|
|
58
58
|
getURL: jest.fn(function (path) {
|
|
59
|
-
|
|
59
|
+
const origin = globalThis[Symbol.for('jest-webextension-mock')].extensionPath;
|
|
60
|
+
return String(new URL(path, origin));
|
|
60
61
|
}),
|
|
61
62
|
openOptionsPage: jest.fn(),
|
|
62
63
|
getManifest: jest.fn(() => ({ manifest_version: 3 })),
|