webext-schema 6.0.0 → 7.1.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/FUNDING.yml +13 -0
- package/.github/workflows/node.js.yml +31 -0
- package/README.md +37 -6
- package/SECURITY.md +36 -0
- package/eslint.config.mjs +46 -0
- package/index.js +9 -3
- package/modules/browser.js +39 -3
- package/modules/schema.js +3 -4
- package/modules/update.js +0 -5
- package/package.json +34 -25
- package/schemas/beta/webext.json +697 -17
- package/schemas/central/webext.json +694 -14
- package/schemas/mail/mailext.json +838 -104
- package/test/browser.test.js +3039 -0
- package/test/commander.test.js +134 -0
- package/test/common.test.js +120 -0
- package/test/constant.test.js +34 -0
- package/test/file/test 2.cmd +2 -0
- package/test/file/test 2.sh +2 -0
- package/test/file/test.cmd +2 -0
- package/test/file/test.js +1 -0
- package/test/file/test.sh +2 -0
- package/test/file/test.txt +1 -0
- package/test/file-util.test.js +370 -0
- package/test/index.test.js +59 -0
- package/test/mocha/setup.js +40 -0
- package/test/schema.test.js +1280 -0
- package/test/update.test.js +1054 -0
- package/types/index.d.ts +8 -1
- package/types/modules/browser.d.ts +61 -61
- package/types/modules/commander.d.ts +3 -3
- package/types/modules/common.d.ts +7 -7
- package/types/modules/constant.d.ts +3 -3
- package/types/modules/file-util.d.ts +16 -16
- package/types/modules/schema.d.ts +6 -6
- package/types/modules/update.d.ts +10 -11
- package/schemas/esr/webext.json +0 -21462
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/* api */
|
|
2
|
+
import { strict as assert } from 'node:assert';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
import { describe, it, beforeEach, afterEach } from 'mocha';
|
|
5
|
+
import sinon from 'sinon';
|
|
6
|
+
|
|
7
|
+
/* test */
|
|
8
|
+
import { Schema } from '../index.js';
|
|
9
|
+
|
|
10
|
+
describe('Schema', () => {
|
|
11
|
+
it('should be instance of Schema', () => {
|
|
12
|
+
const schema = new Schema();
|
|
13
|
+
assert.strictEqual(schema instanceof Schema, true);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('Process Error Handlers', () => {
|
|
18
|
+
let sandbox;
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
sandbox = sinon.createSandbox();
|
|
21
|
+
sandbox.stub(console, 'error');
|
|
22
|
+
sandbox.stub(process, 'exit');
|
|
23
|
+
});
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
sandbox.restore();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should handle uncaughtException', () => {
|
|
29
|
+
const listeners = process.listeners('uncaughtException');
|
|
30
|
+
const targetListener = listeners.find(fn =>
|
|
31
|
+
fn.toString().includes('Fatal Error (Uncaught Exception)')
|
|
32
|
+
);
|
|
33
|
+
assert.ok(targetListener,
|
|
34
|
+
'Target listener for uncaughtException should be found');
|
|
35
|
+
const testError = new Error('Test Uncaught Exception');
|
|
36
|
+
targetListener(testError);
|
|
37
|
+
assert.strictEqual(console.error.calledOnce, true);
|
|
38
|
+
assert.strictEqual(console.error.firstCall.args[0],
|
|
39
|
+
'Fatal Error (Uncaught Exception):');
|
|
40
|
+
assert.strictEqual(console.error.firstCall.args[1], testError);
|
|
41
|
+
assert.strictEqual(process.exit.calledOnceWithExactly(1), true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should handle unhandledRejection', () => {
|
|
45
|
+
const listeners = process.listeners('unhandledRejection');
|
|
46
|
+
const targetListener = listeners.find(fn =>
|
|
47
|
+
fn.toString().includes('Fatal Error (Unhandled Rejection)')
|
|
48
|
+
);
|
|
49
|
+
assert.ok(targetListener,
|
|
50
|
+
'Target listener for unhandledRejection should be found');
|
|
51
|
+
const testReason = 'Test Unhandled Rejection';
|
|
52
|
+
targetListener(testReason);
|
|
53
|
+
assert.strictEqual(console.error.calledOnce, true);
|
|
54
|
+
assert.strictEqual(console.error.firstCall.args[0],
|
|
55
|
+
'Fatal Error (Unhandled Rejection):');
|
|
56
|
+
assert.strictEqual(console.error.firstCall.args[1], testReason);
|
|
57
|
+
assert.strictEqual(process.exit.calledOnceWithExactly(1), true);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -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;
|