webext-schema 5.6.1 → 7.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.
@@ -0,0 +1,40 @@
1
+ /**
2
+ * setup.js
3
+ */
4
+
5
+ import process from 'node:process';
6
+ import { Schema } from '../../index.js';
7
+
8
+ /**
9
+ * get channel
10
+ * @returns {string} - channel
11
+ */
12
+ const getChannel = () => {
13
+ let ch;
14
+ const reg = /(?<=--channel=)[a-z]+/;
15
+ const args = process.argv.filter(arg => reg.test(arg));
16
+ if (args.length) {
17
+ [ch] = reg.exec(args);
18
+ } else {
19
+ ch = 'beta';
20
+ }
21
+ return ch;
22
+ };
23
+
24
+ const channel = getChannel();
25
+
26
+ console.log(`Channel: ${channel}`);
27
+
28
+ export const browser = new Schema(channel).mock();
29
+
30
+ export const mockPort = ({ name, sender }) => {
31
+ const port = Object.assign({}, browser.runtime.Port);
32
+ port.name = name;
33
+ port.sender = sender;
34
+ return port;
35
+ };
36
+
37
+ browser.i18n.getMessage.callsFake((...args) => args.toString());
38
+ browser.permissions.contains.resolves(true);
39
+
40
+ global.browser = browser;