From a0eb07f3fec67f933091ac358b58b674aa3e73dc Mon Sep 17 00:00:00 2001 From: "asamuzaK (Kazz)" Date: Thu, 28 Nov 2024 18:37:20 +0900 Subject: [PATCH] Update tests --- test/browser.test.js | 414 ++++++++++++++++--------------- test/commander.test.js | 12 +- test/common.test.js | 16 +- test/constant.test.js | 8 +- test/file-util.test.js | 44 ++-- test/index.test.js | 4 +- test/schema.test.js | 540 +++++++++++++++++++++++------------------ test/update.test.js | 533 +++++++++++++++++++++++++++------------- 8 files changed, 928 insertions(+), 643 deletions(-) diff --git a/test/browser.test.js b/test/browser.test.js index 0e00740..38f95c8 100644 --- a/test/browser.test.js +++ b/test/browser.test.js @@ -3,9 +3,9 @@ */ /* api */ -import sinon from 'sinon'; -import { assert } from 'chai'; +import { strict as assert } from 'node:assert'; import { afterEach, beforeEach, describe, it } from 'mocha'; +import sinon from 'sinon'; import { browser } from './mocha/setup.js'; /* test */ @@ -25,7 +25,7 @@ describe('browser', () => { }); it('should get browser object', () => { - assert.isObject(browser, 'browser'); + assert.strictEqual(typeof browser, 'object', 'browser'); }); describe('check if permission is granted', () => { @@ -62,80 +62,80 @@ describe('browser', () => { it('should get result', async () => { const res = await func(); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); it('should get result', async () => { const res = await func('foo'); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); it('should get result', async () => { const res = await func([]); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); it('should get result', async () => { const res = await func({ foo: ['bar'] }); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); it('should get result', async () => { const res = await func({ origins: ['https://mozilla.org/'] }); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); it('should get result', async () => { const res = await func({ origins: ['https://example.com/'] }); - assert.isTrue(res, 'result'); + assert.strictEqual(res, true, 'result'); }); it('should get result', async () => { const res = await func({ origins: ['http://www.example.com/foo'] }); - assert.isTrue(res, 'result'); + assert.strictEqual(res, true, 'result'); }); it('should get result', async () => { const res = await func({ permissions: ['alarms'] }); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); it('should get result', async () => { const res = await func({ permissions: ['tabs'] }); - assert.isTrue(res, 'result'); + assert.strictEqual(res, true, 'result'); }); it('should get result', async () => { const res = await func({ permissions: ['tabs', 'bookmarks'] }); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); it('should get result', async () => { const res = await func({ permissions: ['tabs', 'browserSettings'] }); - assert.isTrue(res, 'result'); + assert.strictEqual(res, true, 'result'); }); it('should get result', async () => { const res = await func({ permissions: ['tabs', 'browserSettings', 'commands'] }); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); it('should get result', async () => { @@ -143,7 +143,7 @@ describe('browser', () => { origins: ['https://example.com/'], permissions: ['tabs'] }); - assert.isTrue(res, 'result'); + assert.strictEqual(res, true, 'result'); }); it('should get result', async () => { @@ -151,7 +151,7 @@ describe('browser', () => { origins: ['https://mozilla.org/'], permissions: ['tabs'] }); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); it('should get result', async () => { @@ -159,7 +159,7 @@ describe('browser', () => { origins: ['https://example.com/'], permissions: ['alarms'] }); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); }); @@ -171,22 +171,22 @@ describe('browser', () => { const i = browser.bookmarks.create.callCount; const res = await func({ foo: 'bar' }); assert.strictEqual(browser.bookmarks.create.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get null if no argument given', async () => { const res = await func(); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get null if argument is not object', async () => { const res = await func('foo'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get null if argument is empty object', async () => { const res = await func({}); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get object', async () => { @@ -204,7 +204,7 @@ describe('browser', () => { const i = browser.bookmarks.create.callCount; const res = await func({ foo: 'bar' }); assert.strictEqual(browser.bookmarks.create.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should call function', async () => { @@ -224,8 +224,7 @@ describe('browser', () => { it('should throw if ID not found', async () => { browser.bookmarks.getSubTree.withArgs('foo').rejects(new Error('error')); await func('foo').catch(e => { - assert.instanceOf(e, Error, 'error'); - assert.strictEqual(e.message, 'error', 'message'); + assert.deepStrictEqual(e, new Error('error')); }); }); @@ -269,12 +268,12 @@ describe('browser', () => { browser.browserSettings.closeTabsByDoubleClick.get.callCount, i, 'not called' ); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get null', async () => { const res = await func(); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get object', async () => { @@ -296,7 +295,7 @@ describe('browser', () => { browser.browserSettings.contextMenuShowEvent.get.callCount, i, 'not called' ); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); it('should get true', async () => { @@ -314,7 +313,7 @@ describe('browser', () => { browser.browserSettings.contextMenuShowEvent.set.callCount, j, 'not called' ); - assert.isTrue(res, 'result'); + assert.strictEqual(res, true, 'result'); }); it('should get true', async () => { @@ -334,7 +333,7 @@ describe('browser', () => { browser.browserSettings.contextMenuShowEvent.set.callCount, j + 1, 'called' ); - assert.isTrue(res, 'result'); + assert.strictEqual(res, true, 'result'); }); it('should get false', async () => { @@ -354,7 +353,7 @@ describe('browser', () => { browser.browserSettings.contextMenuShowEvent.set.callCount, j + 1, 'called' ); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); it('should get false', async () => { @@ -373,7 +372,7 @@ describe('browser', () => { browser.browserSettings.contextMenuShowEvent.set.callCount, j, 'not called' ); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); }); @@ -388,7 +387,7 @@ describe('browser', () => { browser.browserSettings.contextMenuShowEvent.clear.callCount, i, 'not called' ); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); it('should get true', async () => { @@ -399,7 +398,7 @@ describe('browser', () => { browser.browserSettings.contextMenuShowEvent.clear.callCount, i + 1, 'called' ); - assert.isTrue(res, 'result'); + assert.strictEqual(res, true, 'result'); }); it('should get false', async () => { @@ -410,7 +409,7 @@ describe('browser', () => { browser.browserSettings.contextMenuShowEvent.clear.callCount, i + 1, 'called' ); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); }); @@ -424,7 +423,7 @@ describe('browser', () => { assert.strictEqual( browser.browserSettings.newTabPosition.get.callCount, i, 'not called' ); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get value', async () => { @@ -444,12 +443,12 @@ describe('browser', () => { it('should get false if permission is not granted', async () => { browser.permissions.contains.resolves(false); const res = await func(); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); it('should get true', async () => { const res = await func(); - assert.isTrue(res, 'result'); + assert.strictEqual(res, true, 'result'); }); }); @@ -477,25 +476,30 @@ describe('browser', () => { it('should get null', async () => { browser.permissions.contains.resolves(false); const res = await func('foo', ''); - assert.isFalse(browser.commands.reset.calledOnce, 'called'); - assert.isFalse(browser.commands.update.calledOnce, 'not called'); - assert.isNull(res, 'result'); + assert.strictEqual(browser.commands.reset.calledOnce, false, + 'not called'); + assert.strictEqual(browser.commands.update.calledOnce, false, + 'not called'); + assert.deepEqual(res, null, 'result'); }); it('should get null', async () => { const res = await func('foo', 'a'); - assert.isFalse(browser.commands.reset.calledOnce, 'called'); - assert.isFalse(browser.commands.update.calledOnce, 'not called'); - assert.isNull(res, 'result'); + assert.strictEqual(browser.commands.reset.calledOnce, false, + 'not called'); + assert.strictEqual(browser.commands.update.calledOnce, false, + 'not called'); + assert.deepEqual(res, null, 'result'); }); it('should call function', async () => { browser.commands.reset.resolves(undefined); browser.commands.update.rejects(); const res = await func('foo', ''); - assert.isTrue(browser.commands.reset.calledOnce, 'called'); - assert.isFalse(browser.commands.update.calledOnce, 'not called'); - assert.isUndefined(res, 'result'); + assert.strictEqual(browser.commands.reset.calledOnce, true, 'called'); + assert.strictEqual(browser.commands.update.calledOnce, false, + 'not called'); + assert.strictEqual(res, undefined, 'result'); }); it('should call function', async () => { @@ -550,8 +554,9 @@ describe('browser', () => { const res = await func('foo', item); assert.strictEqual(browser.commands.update.callCount, i + 1, `called ${item}`); - assert.isFalse(browser.commands.reset.calledOnce, 'not called'); - assert.isUndefined(res, 'result'); + assert.strictEqual(browser.commands.reset.calledOnce, false, + 'not called'); + assert.strictEqual(res, undefined, 'result'); } }); @@ -559,9 +564,10 @@ describe('browser', () => { browser.commands.reset.rejects(); browser.commands.update.resolves(undefined); const res = await func('foo', ' Ctrl+a '); - assert.isTrue(browser.commands.update.calledOnce, 'called'); - assert.isFalse(browser.commands.reset.calledOnce, 'not called'); - assert.isUndefined(res, 'result'); + assert.strictEqual(browser.commands.update.calledOnce, true, 'called'); + assert.strictEqual(browser.commands.reset.calledOnce, false, + 'not called'); + assert.strictEqual(res, undefined, 'result'); }); }); @@ -574,13 +580,13 @@ describe('browser', () => { const res = await func(); assert.strictEqual(browser.contextualIdentities.query.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should throw', async () => { browser.contextualIdentities.query.rejects(new Error('error')); await func().catch(e => { - assert.instanceOf(e, Error, 'error'); + assert.deepStrictEqual(e, new Error('error')); }); }); @@ -594,7 +600,7 @@ describe('browser', () => { } ]); const res = await func(); - assert.isArray(res, 'array'); + assert.strictEqual(Array.isArray(res), true, 'array'); assert.deepEqual(res, [{ foo: 'bar' }, { baz: 'qux' }], 'result'); }); }); @@ -604,13 +610,15 @@ describe('browser', () => { it('should throw if no argument given', async () => { await func().catch(e => { - assert.strictEqual(e.message, 'Expected String but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Undefined.')); }); }); it('should throw if given argument is not string', async () => { await func(1).catch(e => { - assert.strictEqual(e.message, 'Expected String but got Number.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Number.')); }); }); @@ -620,14 +628,14 @@ describe('browser', () => { const res = await func('foo'); assert.strictEqual(browser.contextualIdentities.get.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should throw', async () => { browser.contextualIdentities.get.withArgs('foo') .rejects(new Error('error')); await func('foo').catch(e => { - assert.instanceOf(e, Error, 'error'); + assert.deepStrictEqual(e, new Error('error')); }); }); @@ -646,25 +654,25 @@ describe('browser', () => { const i = browser.management.getAll.callCount; const res = await func(); assert.strictEqual(browser.management.getAll.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get null', async () => { const res = await func(); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should throw', async () => { browser.management.getAll.rejects(new Error('error')); await func().catch(e => { - assert.instanceOf(e, Error, 'error'); + assert.deepStrictEqual(e, new Error('error')); }); }); it('should get null', async () => { browser.management.getAll.resolves([]); const res = await func(); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get array', async () => { @@ -690,8 +698,7 @@ describe('browser', () => { const res = await func(); const { called } = stub; stub.restore(); - assert.isFalse(called, 'not logged'); - assert.isArray(res, 'array'); + assert.strictEqual(called, false, 'not logged'); assert.deepEqual(res, [ { enabled: true, @@ -706,13 +713,15 @@ describe('browser', () => { it('should throw if no argument given', async () => { await func().catch(e => { - assert.strictEqual(e.message, 'Expected String but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Undefined.')); }); }); it('should throw if given argument is not string', async () => { await func(1).catch(e => { - assert.strictEqual(e.message, 'Expected String but got Number.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Number.')); }); }); @@ -721,13 +730,13 @@ describe('browser', () => { const i = browser.management.get.callCount; const res = await func('foo'); assert.strictEqual(browser.management.get.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should reject if given id is not found', async () => { browser.management.get.withArgs('foo').rejects(new Error('error')); await func('foo').catch(e => { - assert.strictEqual(e.message, 'error'); + assert.deepStrictEqual(e, new Error('error')); }); }); @@ -746,25 +755,25 @@ describe('browser', () => { const i = browser.management.getAll.callCount; const res = await func(); assert.strictEqual(browser.management.getAll.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get null', async () => { const res = await func(); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should throw', async () => { browser.management.getAll.rejects(new Error('error')); await func().catch(e => { - assert.instanceOf(e, Error, 'error'); + assert.deepStrictEqual(e, new Error('error')); }); }); it('should get null', async () => { browser.management.getAll.resolves([]); const res = await func(); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get array', async () => { @@ -783,7 +792,6 @@ describe('browser', () => { } ]); const res = await func(); - assert.isArray(res, 'array'); assert.deepEqual(res, [ { type: 'extension' @@ -800,13 +808,15 @@ describe('browser', () => { it('should throw if no argument given', async () => { await func().catch(e => { - assert.strictEqual(e.message, 'Expected String but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Undefined.')); }); }); - it('should throw if no argument given', async () => { + it('should throw if given argument is not string', async () => { await func(1).catch(e => { - assert.strictEqual(e.message, 'Expected String but got Number.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Number.')); }); }); @@ -816,13 +826,13 @@ describe('browser', () => { const res = await func('foo'); assert.strictEqual(browser.notifications.clear.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get result', async () => { browser.notifications.clear.withArgs('foo').resolves(true); const res = await func('foo'); - assert.isTrue(res, 'result'); + assert.strictEqual(res, true, 'result'); }); }); @@ -831,13 +841,15 @@ describe('browser', () => { it('should throw if no argument given', async () => { await func().catch(e => { - assert.strictEqual(e.message, 'Expected String but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Undefined.')); }); }); it('should throw if first argument is not string', async () => { await func(1).catch(e => { - assert.strictEqual(e.message, 'Expected String but got Number.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Number.')); }); }); @@ -847,7 +859,7 @@ describe('browser', () => { const res = await func('foo'); assert.strictEqual(browser.notifications.create.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get message', async () => { @@ -882,15 +894,15 @@ describe('browser', () => { it('should throw if no argument given', async () => { await func().catch(e => { - assert.strictEqual(e.message, - 'Expected String or Array but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String or Array but got Undefined.')); }); }); it('should throw if given argument is not string or array', async () => { await func(1).catch(e => { - assert.strictEqual(e.message, - 'Expected String or Array but got Number.'); + assert.deepStrictEqual(e, + new TypeError('Expected String or Array but got Number.')); }); }); @@ -898,21 +910,21 @@ describe('browser', () => { browser.permissions.remove.withArgs({ permissions: ['foo'] }) .resolves(true); const res = await func('foo'); - assert.isTrue(res, 'result'); + assert.strictEqual(res, true, 'result'); }); it('should get result', async () => { browser.permissions.remove.withArgs({ permissions: ['foo'] }) .resolves(false); const res = await func('foo'); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); it('should get result', async () => { browser.permissions.remove.withArgs({ permissions: ['foo'] }) .resolves(true); const res = await func(['foo']); - assert.isTrue(res, 'result'); + assert.strictEqual(res, true, 'result'); }); }); @@ -921,15 +933,15 @@ describe('browser', () => { it('should throw if no argument given', async () => { await func().catch(e => { - assert.strictEqual(e.message, - 'Expected String or Array but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String or Array but got Undefined.')); }); }); it('should throw if given argument is not string or array', async () => { await func(1).catch(e => { - assert.strictEqual(e.message, - 'Expected String or Array but got Number.'); + assert.deepStrictEqual(e, + new TypeError('Expected String or Array but got Number.')); }); }); @@ -937,21 +949,21 @@ describe('browser', () => { browser.permissions.request.withArgs({ permissions: ['foo'] }) .resolves(true); const res = await func('foo'); - assert.isTrue(res, 'result'); + assert.strictEqual(res, true, 'result'); }); it('should get result', async () => { browser.permissions.request.withArgs({ permissions: ['foo'] }) .resolves(false); const res = await func('foo'); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); it('should get result', async () => { browser.permissions.request.withArgs({ permissions: ['foo'] }) .resolves(true); const res = await func(['foo']); - assert.isTrue(res, 'result'); + assert.strictEqual(res, true, 'result'); }); }); @@ -1060,7 +1072,7 @@ describe('browser', () => { assert.strictEqual(browser.tabs.sendMessage.callCount, i, 'not called'); assert.strictEqual(browser.runtime.sendMessage.callCount, j, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should call function', async () => { @@ -1106,7 +1118,7 @@ describe('browser', () => { assert.strictEqual(browser.tabs.sendMessage.callCount, i, 'not called'); assert.strictEqual(browser.runtime.sendMessage.callCount, j, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); }); @@ -1116,12 +1128,12 @@ describe('browser', () => { it('should get false if permission is not granted', async () => { browser.permissions.contains.resolves(false); const res = await func(); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); it('should get true', async () => { const res = await func(); - assert.isTrue(res, 'result'); + assert.strictEqual(res, true, 'result'); }); }); @@ -1135,7 +1147,7 @@ describe('browser', () => { const res = await func(); assert.strictEqual(browser.scripting.executeScript.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should not call function if no tabId in target', async () => { @@ -1146,7 +1158,7 @@ describe('browser', () => { }); assert.strictEqual(browser.scripting.executeScript.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should not call function if files / func is not included', async () => { @@ -1159,7 +1171,7 @@ describe('browser', () => { }); assert.strictEqual(browser.scripting.executeScript.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should not call function if files is an empty array', async () => { @@ -1173,7 +1185,7 @@ describe('browser', () => { }); assert.strictEqual(browser.scripting.executeScript.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should throw', async () => { @@ -1185,7 +1197,7 @@ describe('browser', () => { tabId: 1 } }).catch(e => { - assert.instanceOf(e, Error, 'error'); + assert.deepStrictEqual(e, new Error('error')); }); stubErr.restore(); }); @@ -1215,7 +1227,7 @@ describe('browser', () => { }); assert.strictEqual(browser.scripting.executeScript.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should call function', async () => { @@ -1270,7 +1282,7 @@ describe('browser', () => { const i = browser.search.query.callCount; const res = await func('foo'); assert.strictEqual(browser.search.query.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should call function', async () => { @@ -1328,15 +1340,15 @@ describe('browser', () => { it('should throw if no argument given', async () => { await func().catch(e => { - assert.strictEqual(e.message, - 'Expected String but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Undefined.')); }); }); it('should throw if 1st argument is not string', async () => { await func(1).catch(e => { - assert.strictEqual(e.message, - 'Expected String but got Number.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Number.')); }); }); @@ -1384,31 +1396,31 @@ describe('browser', () => { const res = await func(); assert.strictEqual(browser.sessions.getRecentlyClosed.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get null', async () => { browser.sessions.getRecentlyClosed.resolves([]); const res = await func(); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get null', async () => { browser.sessions.getRecentlyClosed.resolves([]); const res = await func(1); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get null', async () => { browser.sessions.getRecentlyClosed.resolves([{}]); const res = await func(); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get null', async () => { browser.sessions.getRecentlyClosed.resolves([{ tab: { windowId: 2 } }]); const res = await func(1); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get object', async () => { @@ -1434,13 +1446,15 @@ describe('browser', () => { it('should throw if no argument given', async () => { await func().catch(e => { - assert.strictEqual(e.message, 'Expected String but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Undefined.')); }); }); it('should throw if given argument is not string', async () => { await func(1).catch(e => { - assert.strictEqual(e.message, 'Expected String but got Number.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Number.')); }); }); @@ -1450,7 +1464,7 @@ describe('browser', () => { const res = await func('foo', 1); assert.strictEqual(browser.sessions.getWindowValue.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get object', async () => { @@ -1472,13 +1486,15 @@ describe('browser', () => { it('should throw if no argument given', async () => { await func().catch(e => { - assert.strictEqual(e.message, 'Expected String but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Undefined.')); }); }); it('should throw if given argument is not string', async () => { await func(1).catch(e => { - assert.strictEqual(e.message, 'Expected String but got Number.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Number.')); }); }); @@ -1488,7 +1504,7 @@ describe('browser', () => { const res = await func('foo'); assert.strictEqual(browser.sessions.getWindowValue.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get object', async () => { @@ -1503,13 +1519,15 @@ describe('browser', () => { it('should throw if no argument given', async () => { await func().catch(e => { - assert.strictEqual(e.message, 'Expected String but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Undefined.')); }); }); it('should throw if given argument is not string', async () => { await func(1).catch(e => { - assert.strictEqual(e.message, 'Expected String but got Number.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Number.')); }); }); @@ -1630,7 +1648,7 @@ describe('browser', () => { 'not called'); */ assert.strictEqual(browser.storage.sync.get.callCount, l, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should not call function', async () => { @@ -1647,7 +1665,7 @@ describe('browser', () => { 'not called'); */ assert.strictEqual(browser.storage.sync.get.callCount, l, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should call function', async () => { @@ -1713,7 +1731,7 @@ describe('browser', () => { 'not called'); */ assert.strictEqual(browser.storage.sync.get.callCount, l, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should not call function', async () => { @@ -1730,7 +1748,7 @@ describe('browser', () => { 'not called'); */ assert.strictEqual(browser.storage.sync.get.callCount, l, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should call function', async () => { @@ -1948,8 +1966,8 @@ describe('browser', () => { it('should throw', async () => { await func().catch(e => { - assert.instanceOf(e, TypeError, 'error'); - assert.strictEqual(e.message, 'Expected Number but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected Number but got Undefined.')); }); }); @@ -1988,7 +2006,7 @@ describe('browser', () => { it('should get null if no argument given', async () => { const res = await func(); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should call function', async () => { @@ -2006,7 +2024,7 @@ describe('browser', () => { assert.strictEqual(browser.tabs.executeScript.withArgs(1, { file }).callCount, i + 1, 'called'); - assert.isFalse(errCalled, 'error not called'); + assert.strictEqual(errCalled, false, 'error not called'); assert.deepEqual(res, [{}], 'result'); }); @@ -2025,8 +2043,8 @@ describe('browser', () => { assert.strictEqual(browser.tabs.executeScript.withArgs(1, { file }).callCount, i + 1, 'called'); - assert.isTrue(errCalled, 'error called'); - assert.isFalse(res, 'result'); + assert.strictEqual(errCalled, true, 'error called'); + assert.strictEqual(res, false, 'result'); }); it('should get result', async () => { @@ -2044,7 +2062,7 @@ describe('browser', () => { assert.strictEqual(browser.tabs.executeScript.withArgs({ file }).callCount, i + 1, 'called'); - assert.isFalse(errCalled, 'error not called'); + assert.strictEqual(errCalled, false, 'error not called'); assert.deepEqual(res, [{}], 'result'); }); @@ -2063,8 +2081,8 @@ describe('browser', () => { assert.strictEqual(browser.tabs.executeScript.withArgs({ file }).callCount, i + 1, 'called'); - assert.isTrue(errCalled, 'error called'); - assert.isFalse(res, 'result'); + assert.strictEqual(errCalled, true, 'error called'); + assert.strictEqual(res, false, 'result'); }); it('should get result', async () => { @@ -2082,7 +2100,7 @@ describe('browser', () => { assert.strictEqual(browser.tabs.executeScript.withArgs({ file }).callCount, i + 1, 'called'); - assert.isFalse(errCalled, 'error not called'); + assert.strictEqual(errCalled, false, 'error not called'); assert.deepEqual(res, [{}], 'result'); }); @@ -2101,8 +2119,8 @@ describe('browser', () => { assert.strictEqual(browser.tabs.executeScript.withArgs({ file }).callCount, i + 1, 'called'); - assert.isTrue(errCalled, 'error called'); - assert.isFalse(res, 'result'); + assert.strictEqual(errCalled, true, 'error called'); + assert.strictEqual(res, false, 'result'); }); }); @@ -2136,7 +2154,7 @@ describe('browser', () => { i + 1, 'called'); assert.strictEqual(browser.tabs.executeScript.withArgs(2, {}).callCount, j + 1, 'called'); - assert.isTrue(errCalled, 'error called'); + assert.strictEqual(errCalled, true, 'error called'); assert.deepEqual(res, [[{}], false], 'result'); }); @@ -2187,7 +2205,7 @@ describe('browser', () => { file, allFrames: true }).callCount, j + 1, 'called'); - assert.isTrue(errCalled, 'error called'); + assert.strictEqual(errCalled, true, 'error called'); assert.deepEqual(res, [[{}, {}], false], 'result'); }); }); @@ -2197,35 +2215,35 @@ describe('browser', () => { it('should get null if no arguments given', async () => { const res = await func(); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get null if no opts given', async () => { const i = browser.tabs.executeScript.callCount; const res = await func(1); assert.strictEqual(browser.tabs.executeScript.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get null if opts is empty array', async () => { const i = browser.tabs.executeScript.callCount; const res = await func(1, []); assert.strictEqual(browser.tabs.executeScript.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get null if opts is empty array', async () => { const i = browser.tabs.executeScript.callCount; const res = await func([]); assert.strictEqual(browser.tabs.executeScript.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get null if opts is empty array', async () => { const i = browser.tabs.executeScript.callCount; const res = await func(null, []); assert.strictEqual(browser.tabs.executeScript.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get result', async () => { @@ -2248,7 +2266,7 @@ describe('browser', () => { i + 1, 'called'); assert.strictEqual(browser.tabs.executeScript.withArgs(1, opt2).callCount, j + 1, 'called'); - assert.isTrue(errCalled, 'error called'); + assert.strictEqual(errCalled, true, 'error called'); assert.deepEqual(res, [{}], 'result'); }); @@ -2272,7 +2290,7 @@ describe('browser', () => { i + 1, 'called'); assert.strictEqual(browser.tabs.executeScript.withArgs(opt2).callCount, j + 1, 'called'); - assert.isTrue(errCalled, 'error called'); + assert.strictEqual(errCalled, true, 'error called'); assert.deepEqual(res, [{}], 'result'); }); @@ -2296,7 +2314,7 @@ describe('browser', () => { i + 1, 'called'); assert.strictEqual(browser.tabs.executeScript.withArgs(opt2).callCount, j + 1, 'called'); - assert.isTrue(errCalled, 'error called'); + assert.strictEqual(errCalled, true, 'error called'); assert.deepEqual(res, [{}], 'result'); }); }); @@ -2323,7 +2341,7 @@ describe('browser', () => { it('should get null', async () => { browser.tabs.query.resolves([]); const res = await func(1); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get number', async () => { @@ -2394,13 +2412,15 @@ describe('browser', () => { it('should throw if no argument given', async () => { await func().catch(e => { - assert.strictEqual(e.message, 'Expected Number but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected Number but got Undefined.')); }); }); it('should throw if argument is not number', async () => { await func('').catch(e => { - assert.strictEqual(e.message, 'Expected Number but got String.'); + assert.deepStrictEqual(e, + new TypeError('Expected Number but got String.')); }); }); @@ -2416,15 +2436,15 @@ describe('browser', () => { it('should throw if no argument given', async () => { await func().catch(e => { - assert.strictEqual(e.message, - 'Expected Number or Array but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected Number or Array but got Undefined.')); }); }); it('should throw if argument is not number', async () => { await func('').catch(e => { - assert.strictEqual(e.message, - 'Expected Number or Array but got String.'); + assert.deepStrictEqual(e, + new TypeError('Expected Number or Array but got String.')); }); }); @@ -2446,21 +2466,21 @@ describe('browser', () => { it('should throw if no argument given', async () => { await func().catch(e => { - assert.strictEqual(e.message, - 'Expected Number or Array but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected Number or Array but got Undefined.')); }); }); it('should throw if argument is not number', async () => { await func('').catch(e => { - assert.strictEqual(e.message, - 'Expected Number or Array but got String.'); + assert.deepStrictEqual(e, + new TypeError('Expected Number or Array but got String.')); }); }); it('should get null', async () => { const res = await func(1); - assert.isNull(res, 'res'); + assert.deepEqual(res, null, 'res'); }); it('should get array', async () => { @@ -2493,13 +2513,15 @@ describe('browser', () => { it('should throw if no argument given', async () => { await func().catch(e => { - assert.strictEqual(e.message, 'Expected Number but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected Number but got Undefined.')); }); }); it('should throw if argument is not number', async () => { await func('').catch(e => { - assert.strictEqual(e.message, 'Expected Number but got String.'); + assert.deepStrictEqual(e, + new TypeError('Expected Number but got String.')); }); }); @@ -2525,13 +2547,15 @@ describe('browser', () => { it('should throw if no argument given', async () => { await func().catch(e => { - assert.strictEqual(e.message, 'Expected Array but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected Array but got Undefined.')); }); }); it('should throw if argument is not number or array', async () => { await func('').catch(e => { - assert.strictEqual(e.message, 'Expected Array but got String.'); + assert.deepStrictEqual(e, + new TypeError('Expected Array but got String.')); }); }); @@ -2553,20 +2577,22 @@ describe('browser', () => { it('should throw if no argument given', async () => { await func().catch(e => { - assert.strictEqual(e.message, 'Expected Number but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected Number but got Undefined.')); }); }); it('should throw if argument is not number', async () => { await func('').catch(e => { - assert.strictEqual(e.message, 'Expected Number but got String.'); + assert.deepStrictEqual(e, + new TypeError('Expected Number but got String.')); }); }); it('should throw if tab does not exist', async () => { browser.tabs.update.withArgs(1).throws(new Error('error')); await func(1).catch(e => { - assert.strictEqual(e.message, 'error'); + assert.deepStrictEqual(e, new Error('error')); }); }); @@ -2576,7 +2602,7 @@ describe('browser', () => { const res = await func(1); assert.strictEqual(browser.tabs.update.withArgs(1).callCount, i + 1, 'called'); - assert.isObject(res, 'res'); + assert.strictEqual(typeof res, 'object', 'res'); }); it('should get object', async () => { @@ -2588,7 +2614,7 @@ describe('browser', () => { i + 1, 'called' ); - assert.isObject(res, 'res'); + assert.strictEqual(typeof res, 'object', 'res'); }); }); @@ -2597,13 +2623,15 @@ describe('browser', () => { it('should throw if no argument given', async () => { await func().catch(e => { - assert.strictEqual(e.message, 'Expected Number but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected Number but got Undefined.')); }); }); it('should throw if argument is not number', async () => { await func('').catch(e => { - assert.strictEqual(e.message, 'Expected Number but got String.'); + assert.deepStrictEqual(e, + new TypeError('Expected Number but got String.')); }); }); @@ -2631,7 +2659,7 @@ describe('browser', () => { const res = await func(); assert.strictEqual(browser.tabs.captureVisibleTab.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should call function', async () => { @@ -2669,7 +2697,7 @@ describe('browser', () => { const res = await func(); assert.strictEqual(browser.tabs.captureVisibleTab.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should call function', async () => { @@ -2733,7 +2761,7 @@ describe('browser', () => { const res = await func(); assert.strictEqual(browser.tabs.captureVisibleTab.callCount, i, 'not called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should call function', async () => { @@ -2790,32 +2818,34 @@ describe('browser', () => { it('should throw if no argument given', async () => { await func().catch(e => { - assert.strictEqual(e.message, 'Expected Number but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected Number but got Undefined.')); }); }); it('should throw if argument is not number', async () => { await func('').catch(e => { - assert.strictEqual(e.message, 'Expected Number but got String.'); + assert.deepStrictEqual(e, + new TypeError('Expected Number but got String.')); }); }); it('should get result', async () => { const res = await func(-1); - assert.isFalse(res, 'res'); + assert.strictEqual(res, false, 'res'); }); it('should get result', async () => { const e = new Error('error'); browser.tabs.get.withArgs(1).rejects(e); const res = await func(1); - assert.isFalse(res, 'res'); + assert.strictEqual(res, false, 'res'); }); it('should get result', async () => { browser.tabs.get.withArgs(1).resolves({}); const res = await func(1); - assert.isTrue(res, 'res'); + assert.strictEqual(res, true, 'res'); }); }); @@ -2855,7 +2885,7 @@ describe('browser', () => { const i = browser.windows.create.callCount; const res = await func(); assert.strictEqual(browser.windows.create.callCount, i + 1, 'called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get function called and get result', async () => { @@ -2863,7 +2893,7 @@ describe('browser', () => { const i = browser.windows.create.callCount; const res = await func(); assert.strictEqual(browser.windows.create.callCount, i + 1, 'called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get function called and get result', async () => { @@ -2892,7 +2922,7 @@ describe('browser', () => { }).callCount; const res = await func(); assert.strictEqual(browser.windows.getAll.callCount, i + 1, 'called'); - assert.isArray(res, 'result'); + assert.strictEqual(Array.isArray(res), true, 'result'); }); it('should get function called and get result', async () => { @@ -2906,7 +2936,7 @@ describe('browser', () => { }).callCount; const res = await func(true); assert.strictEqual(browser.windows.getAll.callCount, i + 1, 'called'); - assert.isArray(res, 'result'); + assert.strictEqual(Array.isArray(res), true, 'result'); }); }); @@ -2918,7 +2948,7 @@ describe('browser', () => { const i = browser.windows.getCurrent.callCount; const res = await func(); assert.strictEqual(browser.windows.getCurrent.callCount, i + 1, 'called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get function called and get result', async () => { @@ -2926,7 +2956,7 @@ describe('browser', () => { const i = browser.windows.getCurrent.callCount; const res = await func(); assert.strictEqual(browser.windows.getCurrent.callCount, i + 1, 'called'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get function called and get result', async () => { @@ -2946,8 +2976,8 @@ describe('browser', () => { it('should throw', async () => { await func().catch(e => { - assert.strictEqual(e.message, 'Expected Number but got Undefined.', - 'throw'); + assert.deepStrictEqual(e, + new TypeError('Expected Number but got Undefined.')); }); }); @@ -2978,7 +3008,7 @@ describe('browser', () => { it('should get result', async () => { browser.windows.getAll.resolves([]); const res = await func(); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); it('should get result', async () => { @@ -2991,7 +3021,7 @@ describe('browser', () => { } ]); const res = await func(); - assert.isFalse(res, 'result'); + assert.strictEqual(res, false, 'result'); }); it('should get result', async () => { @@ -3004,7 +3034,7 @@ describe('browser', () => { } ]); const res = await func(); - assert.isTrue(res, 'result'); + assert.strictEqual(res, true, 'result'); }); }); }); diff --git a/test/commander.test.js b/test/commander.test.js index 905d90f..7750ce7 100644 --- a/test/commander.test.js +++ b/test/commander.test.js @@ -1,8 +1,8 @@ /* api */ +import { strict as assert } from 'node:assert'; import fs from 'node:fs'; import path from 'node:path'; import sinon from 'sinon'; -import { assert } from 'chai'; import { describe, it } from 'mocha'; /* test */ @@ -17,7 +17,7 @@ describe('clean directory', () => { cleanDirectory({ dir }); const { called: rmCalled } = stubRm; stubRm.restore(); - assert.isFalse(rmCalled, 'not called'); + assert.strictEqual(rmCalled, false, 'not called'); }); it('should call funtion', () => { @@ -29,8 +29,8 @@ describe('clean directory', () => { const { called: infoCalled } = stubInfo; stubRm.restore(); stubInfo.restore(); - assert.isTrue(rmCalled, 'called'); - assert.isFalse(infoCalled, 'not called'); + assert.strictEqual(rmCalled, true, 'called'); + assert.strictEqual(infoCalled, false, 'not called'); }); it('should call funtion', () => { @@ -42,8 +42,8 @@ describe('clean directory', () => { const { calledOnce: infoCalled } = stubInfo; stubRm.restore(); stubInfo.restore(); - assert.isTrue(rmCalled, 'called'); - assert.isTrue(infoCalled, 'not called'); + assert.strictEqual(rmCalled, true, 'called'); + assert.strictEqual(infoCalled, true, 'called'); }); }); diff --git a/test/common.test.js b/test/common.test.js index a7161d0..1270ba8 100644 --- a/test/common.test.js +++ b/test/common.test.js @@ -1,6 +1,6 @@ /* api */ +import { strict as assert } from 'node:assert'; import sinon from 'sinon'; -import { assert } from 'chai'; import { describe, it } from 'mocha'; /* test */ @@ -42,7 +42,7 @@ describe('isObjectNotEmpty', () => { it('should get false', () => { const items = [{}, [], ['foo'], '', 'foo', undefined, null, 1, true]; for (const item of items) { - assert.isFalse(isObjectNotEmpty(item)); + assert.strictEqual(isObjectNotEmpty(item), false); } }); @@ -50,7 +50,7 @@ describe('isObjectNotEmpty', () => { const item = { foo: 'bar' }; - assert.isTrue(isObjectNotEmpty(item)); + assert.strictEqual(isObjectNotEmpty(item), true); }); }); @@ -74,9 +74,9 @@ describe('logErr', () => { const res = logErr(new Error(msg)); const { calledOnce } = consoleError; consoleError.restore(); - assert.isTrue(calledOnce); + assert.strictEqual(calledOnce, true); assert.strictEqual(errMsg, msg); - assert.isFalse(res); + assert.strictEqual(res, false); }); }); @@ -90,7 +90,7 @@ describe('logMsg', () => { const res = logMsg(msg); const { calledOnce } = consoleLog; consoleLog.restore(); - assert.isTrue(calledOnce); + assert.strictEqual(calledOnce, true); assert.strictEqual(logMessage, msg); assert.strictEqual(res, msg); }); @@ -106,9 +106,9 @@ describe('logWarn', () => { const res = logWarn(msg); const { calledOnce } = consoleWarn; consoleWarn.restore(); - assert.isTrue(calledOnce); + assert.strictEqual(calledOnce, true); assert.strictEqual(warnMsg, msg); - assert.isFalse(res); + assert.strictEqual(res, false); }); }); diff --git a/test/constant.test.js b/test/constant.test.js index 882998d..cf484e0 100644 --- a/test/constant.test.js +++ b/test/constant.test.js @@ -1,5 +1,5 @@ /* api */ -import { assert } from 'chai'; +import { strict as assert } from 'node:assert'; import { describe, it } from 'mocha'; import { isString } from '../modules/common.js'; @@ -10,7 +10,7 @@ describe('string constants', () => { it('should get string', () => { const arr = [CHAR]; arr.forEach(i => { - assert.isTrue(isString(i)); + assert.strictEqual(isString(i), true); }); }); }); @@ -19,7 +19,7 @@ describe('number constants', () => { it('should get number', () => { const arr = [INDENT]; arr.forEach(i => { - assert.isTrue(typeof i === 'number'); + assert.strictEqual(typeof i, 'number'); }); }); }); @@ -28,7 +28,7 @@ describe('boolean constants', () => { it('should get boolean', () => { const arr = [IS_WIN]; arr.forEach(i => { - assert.isTrue(typeof i === 'boolean'); + assert.strictEqual(typeof i, 'boolean'); }); }); }); diff --git a/test/file-util.test.js b/test/file-util.test.js index f28e6df..c844444 100644 --- a/test/file-util.test.js +++ b/test/file-util.test.js @@ -1,9 +1,9 @@ /* api */ +import { strict as assert } from 'node:assert'; import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import process from 'node:process'; -import { assert } from 'chai'; import { describe, it } from 'mocha'; import { IS_WIN } from '../modules/constant.js'; @@ -71,13 +71,13 @@ describe('convertUriToFilePath', () => { }); it('should throw if string is not given', () => { - assert.throws(() => convertUriToFilePath(), + assert.throws(() => convertUriToFilePath(), TypeError, 'Expected String but got Undefined'); }); it('should get null if protocol does not match', () => { const uri = 'http://example.com'; - assert.isNull(convertUriToFilePath(uri)); + assert.deepEqual(convertUriToFilePath(uri), null); }); }); @@ -92,17 +92,15 @@ describe('createDirectory', () => { it('should throw if given argument is not a string', async () => { await createDirectory().catch(e => { - assert.instanceOf(e, TypeError, 'error'); - assert.strictEqual(e.message, 'Expected String but got Undefined.', - 'message'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Undefined.')); }); }); it('should throw if given second argument is not a number', async () => { await createDirectory('/foo/bar', 'baz').catch(e => { - assert.instanceOf(e, TypeError, 'error'); - assert.strictEqual(e.message, 'Expected Number but got String.', - 'message'); + assert.deepStrictEqual(e, + new TypeError('Expected Number but got String.')); }); }); }); @@ -123,7 +121,8 @@ describe('createFile', () => { it('should throw if first argument is not a string', () => { createFile().catch(e => { - assert.strictEqual(e.message, 'Expected String but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Undefined.')); }); }); @@ -132,10 +131,8 @@ describe('createFile', () => { () => { const file = path.join(TMPDIR, 'webext-schema', 'test.txt'); createFile(file).catch(e => { - assert.strictEqual( - e.message, - 'Expected String, Buffer, Uint8Array but got Undefined.' - ); + assert.deepStrictEqual(e, + new TypeError('Expected String, Buffer, Uint8Array but got Undefined.')); }); } ); @@ -169,7 +166,7 @@ describe('removeDir', () => { it('should ignore if dir is not a directory', () => { const foo = path.resolve('foo'); - assert.isFalse(isDir(foo)); + assert.strictEqual(isDir(foo), false); assert.doesNotThrow(() => removeDir(foo, TMPDIR)); }); @@ -178,7 +175,7 @@ describe('removeDir', () => { const foo = path.join(TMPDIR, 'foo'); await fs.mkdirSync(dirPath); await fs.mkdirSync(foo); - assert.throws(() => removeDir(foo, dirPath), + assert.throws(() => removeDir(foo, dirPath), Error, `${foo} is not a subdirectory of ${dirPath}.`); await fs.rmdirSync(dirPath); await fs.rmdirSync(foo); @@ -213,7 +210,7 @@ describe('removeDirectory', () => { it('should ignore if dir is not a directory', async () => { const foo = path.resolve('foo'); - assert.isFalse(isDir(foo)); + assert.strictEqual(isDir(foo), false); await removeDirectory(foo, TMPDIR).catch(e => { assert.isUndefined(e); }); @@ -225,9 +222,8 @@ describe('removeDirectory', () => { await fs.mkdirSync(dirPath); await fs.mkdirSync(foo); await removeDirectory(foo, dirPath).catch(e => { - assert.instanceOf(e, Error); - assert.strictEqual(e.message, - `${foo} is not a subdirectory of ${dirPath}.`); + assert.deepStrictEqual(e, + new Error(`${foo} is not a subdirectory of ${dirPath}.`)); }); await fs.rmdirSync(dirPath); await fs.rmdirSync(foo); @@ -274,7 +270,7 @@ describe('getFileNameFromFilePath', () => { describe('getFileTimestamp', () => { it('should get positive integer', () => { const p = path.resolve(path.join('test', 'file', 'test.sh')); - assert.isAbove(getFileTimestamp(p), 0); + assert.strictEqual(getFileTimestamp(p) > 0, true); }); it('should get 0 if file does not exist', () => { @@ -286,16 +282,16 @@ describe('getFileTimestamp', () => { describe('getStat', () => { it('should be an object', () => { const p = path.resolve(path.join('test', 'file', 'test.sh')); - assert.property(getStat(p), 'mode'); + assert.strictEqual(typeof getStat(p), 'object'); }); it('should get null if given argument is not string', () => { - assert.isNull(getStat()); + assert.deepEqual(getStat(), null); }); it('should get null if file does not exist', () => { const p = path.resolve(path.join('test', 'file', 'foo.txt')); - assert.isNull(getStat(p)); + assert.deepEqual(getStat(p), null); }); }); diff --git a/test/index.test.js b/test/index.test.js index d54967f..ac6495a 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,5 +1,5 @@ /* api */ -import { assert } from 'chai'; +import { strict as assert } from 'node:assert'; import { describe, it } from 'mocha'; /* test */ @@ -8,6 +8,6 @@ import { Schema } from '../index.js'; describe('Schema', () => { it('should be instance of Schema', () => { const schema = new Schema(); - assert.instanceOf(schema, Schema); + assert.strictEqual(schema instanceof Schema, true); }); }); diff --git a/test/schema.test.js b/test/schema.test.js index 4c085c2..0b13dd1 100644 --- a/test/schema.test.js +++ b/test/schema.test.js @@ -1,5 +1,5 @@ /* api */ -import { assert } from 'chai'; +import { strict as assert } from 'node:assert'; import { describe, it } from 'mocha'; /* test */ @@ -9,17 +9,17 @@ describe('Schema', () => { describe('construct', () => { it('should be instance of Schema', () => { const schema = new Schema(); - assert.instanceOf(schema, Schema, 'instance'); + assert.strictEqual(schema instanceof Schema, true, 'instance'); assert.strictEqual(schema.channel, 'beta', 'channel'); - assert.isObject(schema._sandbox, 'sandbox'); + assert.strictEqual(typeof schema._sandbox, 'object', 'sandbox'); schema._sandbox.restore(); }); it('should be instance of Schema', () => { const schema = new Schema('central'); - assert.instanceOf(schema, Schema, 'instance'); + assert.strictEqual(schema instanceof Schema, true, 'instance'); assert.strictEqual(schema.channel, 'central', 'channel'); - assert.isObject(schema._sandbox, 'sandbox'); + assert.strictEqual(typeof schema._sandbox, 'object', 'sandbox'); schema._sandbox.restore(); }); @@ -31,9 +31,9 @@ describe('Schema', () => { useFakeServer: true }; const schema = new Schema(config); - assert.instanceOf(schema, Schema, 'instance'); + assert.strictEqual(schema instanceof Schema, true, 'instance'); assert.strictEqual(schema.channel, 'beta', 'channel'); - assert.isObject(schema._sandbox, 'sandbox'); + assert.strictEqual(typeof schema._sandbox, 'object', 'sandbox'); schema._sandbox.restore(); }); @@ -45,9 +45,9 @@ describe('Schema', () => { useFakeServer: true }; const schema = new Schema('central', config); - assert.instanceOf(schema, Schema, 'instance'); + assert.strictEqual(schema instanceof Schema, true, 'instance'); assert.strictEqual(schema.channel, 'central', 'channel'); - assert.isObject(schema._sandbox, 'sandbox'); + assert.strictEqual(typeof schema._sandbox, 'object', 'sandbox'); schema._sandbox.restore(); }); }); @@ -156,21 +156,21 @@ describe('Schema', () => { const schema = new Schema(); schema._browser = {}; const res = schema._getTargetFromNamespace(); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get null', () => { const schema = new Schema(); schema._browser = {}; const res = schema._getTargetFromNamespace(''); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get null', () => { const schema = new Schema(); schema._browser = {}; const res = schema._getTargetFromNamespace('foo'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get target object', () => { @@ -190,7 +190,7 @@ describe('Schema', () => { } }; const res = schema._getTargetFromNamespace('foo.baz'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get target object', () => { @@ -556,11 +556,12 @@ describe('Schema', () => { type: 'function' } ]); - assert.isObject(res, {}, 'result'); - assert.isObject(res.foo, {}, 'result'); - assert.isFunction(res.foo.addListener, 'addListener'); - assert.isFunction(res.foo.hasListener, 'hasListener'); - assert.isFunction(res.foo.removeListener, 'removeListener'); + assert.strictEqual(typeof res, 'object', 'result'); + assert.strictEqual(typeof res.foo, 'object', 'result'); + assert.strictEqual(typeof res.foo.addListener, 'function', 'addListener'); + assert.strictEqual(typeof res.foo.hasListener, 'function', 'hasListener'); + assert.strictEqual(typeof res.foo.removeListener, 'function', + 'removeListener'); }); it('should add listeners', () => { @@ -573,11 +574,12 @@ describe('Schema', () => { type: 'function' } ]); - assert.isObject(res, {}, 'result'); - assert.isObject(res.foo, {}, 'result'); - assert.isFunction(res.foo.addListener, 'addListener'); - assert.isFunction(res.foo.hasListener, 'hasListener'); - assert.isFunction(res.foo.removeListener, 'removeListener'); + assert.strictEqual(typeof res, 'object', 'result'); + assert.strictEqual(typeof res.foo, 'object', 'result'); + assert.strictEqual(typeof res.foo.addListener, 'function', 'addListener'); + assert.strictEqual(typeof res.foo.hasListener, 'function', 'hasListener'); + assert.strictEqual(typeof res.foo.removeListener, 'function', + 'removeListener'); }); }); @@ -629,8 +631,8 @@ describe('Schema', () => { type: 'function' } ]); - assert.isObject(res, {}, 'result'); - assert.isFunction(res.foo, 'function'); + assert.strictEqual(typeof res, 'object', 'result'); + assert.strictEqual(typeof res.foo, 'function', 'function'); }); it('should add functions', () => { @@ -643,8 +645,8 @@ describe('Schema', () => { type: 'function' } ]); - assert.isObject(res, {}, 'result'); - assert.isFunction(res.foo, 'function'); + assert.strictEqual(typeof res, 'object', 'result'); + assert.strictEqual(typeof res.foo, 'function', 'function'); }); }); @@ -725,8 +727,8 @@ describe('Schema', () => { type: 'function' } }, 'foo'); - assert.isObject(res, 'result'); - assert.isFunction(res.bar, 'property'); + assert.strictEqual(typeof res, 'object', 'result'); + assert.strictEqual(typeof res.bar, 'function', 'property'); }); it('should add properties', () => { @@ -858,72 +860,66 @@ describe('Schema', () => { it('should get object', () => { const schema = new Schema(); const res = schema._parseSchemaContent(); - assert.isObject(res, 'result'); assert.deepEqual(res, schema._schema, 'schema'); const items = Object.entries(res); for (const [key, value] of items) { - assert.isTrue(key.endsWith('.json'), `${key}`); - assert.isArray(value, `${key} value`); + assert.strictEqual(key.endsWith('.json'), true, `${key}`); + assert.strictEqual(Array.isArray(value), true, `${key} value`); } }); it('should get object', () => { const schema = new Schema('beta'); const res = schema._parseSchemaContent(); - assert.isObject(res, 'result'); assert.deepEqual(res, schema._schema, 'schema'); const items = Object.entries(res); for (const [key, value] of items) { - assert.isTrue(key.endsWith('.json'), `${key}`); - assert.isArray(value, `${key} value`); + assert.strictEqual(key.endsWith('.json'), true, `${key}`); + assert.strictEqual(Array.isArray(value), true, `${key} value`); } }); it('should get object', () => { const schema = new Schema('central'); const res = schema._parseSchemaContent(); - assert.isObject(res, 'result'); assert.deepEqual(res, schema._schema, 'schema'); const items = Object.entries(res); for (const [key, value] of items) { - assert.isTrue(key.endsWith('.json'), `${key}`); - assert.isArray(value, `${key} value`); + assert.strictEqual(key.endsWith('.json'), true, `${key}`); + assert.strictEqual(Array.isArray(value), true, `${key} value`); } }); it('should get object', () => { const schema = new Schema('esr'); const res = schema._parseSchemaContent(); - assert.isObject(res, 'result'); assert.deepEqual(res, schema._schema, 'schema'); const items = Object.entries(res); for (const [key, value] of items) { - assert.isTrue(key.endsWith('.json'), `${key}`); - assert.isArray(value, `${key} value`); + assert.strictEqual(key.endsWith('.json'), true, `${key}`); + assert.strictEqual(Array.isArray(value), true, `${key} value`); } }); it('should get object', () => { const schema = new Schema('release'); const res = schema._parseSchemaContent(); - assert.isObject(res, 'result'); assert.deepEqual(res, schema._schema, 'schema'); const items = Object.entries(res); for (const [key, value] of items) { - assert.isTrue(key.endsWith('.json'), `${key}`); - assert.isArray(value, `${key} value`); + assert.strictEqual(key.endsWith('.json'), true, `${key}`); + assert.strictEqual(Array.isArray(value), true, `${key} value`); } }); it('should get object', () => { const schema = new Schema('mail'); const res = schema._parseSchemaContent(); - assert.isObject(res, 'result'); assert.deepEqual(res, schema._schema, 'schema'); const items = Object.entries(res); for (const [key, value] of items) { - assert.isTrue(key.endsWith('.json'), `${key}`); - assert.isArray(value, `${key} value`); + assert.strictEqual(key.endsWith('.json'), true, `${key}`); + assert.strictEqual(Array.isArray(value), true, `${key} value`); } }); }); @@ -931,40 +927,39 @@ describe('Schema', () => { describe('get schema', () => { it('should throw', () => { const schema = new Schema(); - assert.throws(() => schema.get(), + assert.throws(() => schema.get(), TypeError, 'Expected String but got Undefined.'); }); it('should get null', () => { const schema = new Schema(); const res = schema.get('foo'); - assert.isNull(res, 'result'); + assert.deepEqual(res, null, 'result'); }); it('should get array', () => { const schema = new Schema(); const res = schema.get('browser_action.json'); - assert.isArray(res, 'result'); + assert.strictEqual(Array.isArray(res), true, 'result'); }); it('should get array', () => { const schema = new Schema(); schema._parseSchemaContent(); - assert.isObject(schema._schema, 'schema'); const res = schema.get('browser_action.json'); - assert.isArray(res, 'result'); + assert.strictEqual(Array.isArray(res), true, 'result'); }); it('should get array', () => { const schema = new Schema(); const res = schema.get('browser_action'); - assert.isArray(res, 'result'); + assert.strictEqual(Array.isArray(res), true, 'result'); }); it('should get array', () => { const schema = new Schema(); const res = schema.get('browserAction'); - assert.isArray(res, 'result'); + assert.strictEqual(Array.isArray(res), true, 'result'); }); }); @@ -972,22 +967,22 @@ describe('Schema', () => { it('should get object', () => { const schema = new Schema(); schema._parseSchemaContent(); - assert.isObject(schema._schema, 'schema'); + assert.strictEqual(typeof schema._schema, 'object', 'schema'); const res = schema.getAll(); - assert.isObject(res, 'result'); + assert.strictEqual(typeof res, 'object', 'result'); const keys = Object.keys(res); for (const key of keys) { - assert.isTrue(key.endsWith('.json'), 'key'); + assert.strictEqual(key.endsWith('.json'), true, 'key'); } }); it('should get object', () => { const schema = new Schema(); const res = schema.getAll(); - assert.isObject(res, 'result'); + assert.strictEqual(typeof res, 'object', 'result'); const keys = Object.keys(res); for (const key of keys) { - assert.isTrue(key.endsWith('.json'), 'key'); + assert.strictEqual(key.endsWith('.json'), true, 'key'); } }); }); @@ -996,56 +991,56 @@ describe('Schema', () => { it('should get array', () => { const schema = new Schema(); schema._parseSchemaContent(); - assert.isObject(schema._schema, 'schema'); + assert.strictEqual(typeof schema._schema, 'object', 'schema'); const res = schema.list(); - assert.isArray(res, 'result'); + assert.strictEqual(Array.isArray(res), true, 'result'); for (const key of res) { - assert.isTrue(key.endsWith('.json'), 'key'); + assert.strictEqual(key.endsWith('.json'), true, 'key'); } }); it('should get array', () => { const schema = new Schema(); const res = schema.list(); - assert.isArray(res, 'result'); + assert.strictEqual(Array.isArray(res), true, 'result'); for (const key of res) { - assert.isTrue(key.endsWith('.json'), 'key'); + assert.strictEqual(key.endsWith('.json'), true, 'key'); } }); it('should get array', () => { const schema = new Schema('beta'); const res = schema.list(); - assert.isArray(res, 'result'); + assert.strictEqual(Array.isArray(res), true, 'result'); for (const key of res) { - assert.isTrue(key.endsWith('.json'), 'key'); + assert.strictEqual(key.endsWith('.json'), true, 'key'); } }); it('should get array', () => { const schema = new Schema('central'); const res = schema.list(); - assert.isArray(res, 'result'); + assert.strictEqual(Array.isArray(res), true, 'result'); for (const key of res) { - assert.isTrue(key.endsWith('.json'), 'key'); + assert.strictEqual(key.endsWith('.json'), true, 'key'); } }); it('should get array', () => { const schema = new Schema('esr'); const res = schema.list(); - assert.isArray(res, 'result'); + assert.strictEqual(Array.isArray(res), true, 'result'); for (const key of res) { - assert.isTrue(key.endsWith('.json'), 'key'); + assert.strictEqual(key.endsWith('.json'), true, 'key'); } }); it('should get array', () => { const schema = new Schema('release'); const res = schema.list(); - assert.isArray(res, 'result'); + assert.strictEqual(Array.isArray(res), true, 'result'); for (const key of res) { - assert.isTrue(key.endsWith('.json'), 'key'); + assert.strictEqual(key.endsWith('.json'), true, 'key'); } }); }); @@ -1054,217 +1049,286 @@ describe('Schema', () => { it('should get stubbed api', () => { const schema = new Schema(); schema._parseSchemaContent(); - assert.isObject(schema._schema, 'schema'); + assert.strictEqual(typeof schema._schema, 'object', 'schema'); const browser = schema.mock(); - assert.isObject(browser, 'browser'); + assert.strictEqual(typeof browser, 'object', 'browser'); const { bookmarks, browserAction, browserSettings, commands, contextMenus, contextualIdentities, devtools, i18n, management, menus, notifications, permissions, privacy, runtime, sessions, storage, tabs, theme, windows } = browser; const { inspectedWindow } = devtools; - assert.isObject(bookmarks, 'bookmarks'); - assert.isFunction(bookmarks.create, 'bookmarks.create'); - assert.isNumber(bookmarks.create.callCount, 'stub bookmarks.create'); - assert.isObject(browserAction, 'browserAction'); - assert.isFunction(browserAction.setTitle, 'browserAction.setTitle'); - assert.isNumber(browserAction.setTitle.callCount, + assert.strictEqual(typeof bookmarks, 'object', 'bookmarks'); + assert.strictEqual(typeof bookmarks.create, 'function', + 'bookmarks.create'); + assert.strictEqual(typeof bookmarks.create.callCount, 'number', + 'stub bookmarks.create'); + assert.strictEqual(typeof browserAction, 'object', 'browserAction'); + assert.strictEqual(typeof browserAction.setTitle, 'function', + 'browserAction.setTitle'); + assert.strictEqual(typeof browserAction.setTitle.callCount, 'number', 'stub browserAction.setTitle'); - assert.isObject(browserAction.onClicked, 'browserAction.onClicked'); - assert.isFunction(browserAction.onClicked.addListener, + assert.strictEqual(typeof browserAction.onClicked, 'object', + 'browserAction.onClicked'); + assert.strictEqual(typeof browserAction.onClicked.addListener, 'function', 'browserAction.onClicked.addListener'); - assert.isNumber(browserAction.onClicked.addListener.callCount, - 'stub browserAction.onClicked.addListener.callCount'); - assert.isObject(browserSettings, 'browserSettings'); - assert.isObject(browserSettings.closeTabsByDoubleClick, - 'browserSettings.closeTabsByDoubleClick'); - assert.isObject(commands, 'commands'); - assert.isFunction(commands.update, 'commands.update'); - assert.isNumber(commands.update.callCount, 'stub commands.update'); - assert.isObject(contextMenus, 'contextMenus'); - assert.isFunction(contextMenus.create, 'contextMenus.create'); - assert.isNumber(contextMenus.create.callCount, + assert.strictEqual(typeof browserAction.onClicked.addListener.callCount, + 'number', 'stub browserAction.onClicked.addListener.callCount'); + assert.strictEqual(typeof browserSettings, 'object', 'browserSettings'); + assert.strictEqual(typeof browserSettings.closeTabsByDoubleClick, + 'object', 'browserSettings.closeTabsByDoubleClick'); + assert.strictEqual(typeof commands, 'object', 'commands'); + assert.strictEqual(typeof commands.update, 'function', + 'commands.update'); + assert.strictEqual(typeof commands.update.callCount, 'number', + 'stub commands.update'); + assert.strictEqual(typeof contextMenus, 'object', 'contextMenus'); + assert.strictEqual(typeof contextMenus.create, 'function', + 'contextMenus.create'); + assert.strictEqual(typeof contextMenus.create.callCount, 'number', 'stub contextMenus.create'); - assert.isObject(contextualIdentities, 'contextualIdentities'); - assert.isFunction(contextualIdentities.get, 'contextualIdentities.get'); - assert.isNumber(contextualIdentities.get.callCount, + assert.strictEqual(typeof contextualIdentities, 'object', + 'contextualIdentities'); + assert.strictEqual(typeof contextualIdentities.get, 'function', + 'contextualIdentities.get'); + assert.strictEqual(typeof contextualIdentities.get.callCount, 'number', 'stub contextualIdentities.get'); - assert.isObject(devtools, 'devtools'); - assert.isObject(inspectedWindow, 'inspectedWindow'); - assert.isFunction(inspectedWindow.reload, 'inspectedWindow.reload'); - assert.isNumber(inspectedWindow.reload.callCount, + assert.strictEqual(typeof devtools, 'object', 'devtools'); + assert.strictEqual(typeof inspectedWindow, 'object', 'inspectedWindow'); + assert.strictEqual(typeof inspectedWindow.reload, 'function', + 'inspectedWindow.reload'); + assert.strictEqual(typeof inspectedWindow.reload.callCount, 'number', 'stub inspectedWindow.reload'); - assert.isObject(i18n, 'i18n'); - assert.isFunction(i18n.getMessage, 'i18n.getMessage'); - assert.isNumber(i18n.getMessage.callCount, 'stub i18n.getMessage'); - assert.isObject(management, 'management'); - assert.isFunction(management.get, 'management.get'); - assert.isNumber(management.get.callCount, 'stub management.get'); - assert.isObject(menus, 'menus'); - assert.isFunction(menus.create, 'menus.create'); - assert.isNumber(menus.create.callCount, 'stub menus.create'); - assert.isFunction(menus.getTargetElement, 'menus.getTargetElement'); - assert.isNumber(menus.getTargetElement.callCount, + assert.strictEqual(typeof i18n, 'object', 'i18n'); + assert.strictEqual(typeof i18n.getMessage, 'function', + 'i18n.getMessage'); + assert.strictEqual(typeof i18n.getMessage.callCount, 'number', + 'stub i18n.getMessage'); + assert.strictEqual(typeof management, 'object', 'management'); + assert.strictEqual(typeof management.get, 'function', + 'management.get'); + assert.strictEqual(typeof management.get.callCount, 'number', + 'stub management.get'); + assert.strictEqual(typeof menus, 'object', 'menus'); + assert.strictEqual(typeof menus.create, 'function', + 'menus.create'); + assert.strictEqual(typeof menus.create.callCount, 'number', + 'stub menus.create'); + assert.strictEqual(typeof menus.getTargetElement, 'function', + 'menus.getTargetElement'); + assert.strictEqual(typeof menus.getTargetElement.callCount, 'number', 'stub menus.getTargetElement'); - assert.isFunction(menus.removeAll, 'menus.removeAll'); - assert.isNumber(menus.removeAll.callCount, 'stub menus.removeAll'); - assert.isObject(notifications, 'notifications'); - assert.isFunction(notifications.create, 'notifications.create'); - assert.isNumber(notifications.create.callCount, + assert.strictEqual(typeof menus.removeAll, 'function', + 'menus.removeAll'); + assert.strictEqual(typeof menus.removeAll.callCount, 'number', + 'stub menus.removeAll'); + assert.strictEqual(typeof notifications, 'object', 'notifications'); + assert.strictEqual(typeof notifications.create, 'function', + 'notifications.create'); + assert.strictEqual(typeof notifications.create.callCount, 'number', 'stub notifications.create'); - assert.isObject(notifications.onClosed, 'notifications.onClosed'); - assert.isFunction(notifications.onClosed.addListener, + assert.strictEqual(typeof notifications.onClosed, 'object', + 'notifications.onClosed'); + assert.strictEqual(typeof notifications.onClosed.addListener, 'function', 'notifications.onClosed.addListener'); - assert.isNumber(notifications.onClosed.addListener.callCount, - 'stub notifications.onClosed.addListener'); - assert.isObject(permissions, 'permissions'); - assert.isFunction(permissions.request, 'permissions.request'); - assert.isNumber(permissions.request.callCount, + assert.strictEqual(typeof notifications.onClosed.addListener.callCount, + 'number', 'stub notifications.onClosed.addListener'); + assert.strictEqual(typeof permissions, 'object', 'permissions'); + assert.strictEqual(typeof permissions.request, 'function', + 'permissions.request'); + assert.strictEqual(typeof permissions.request.callCount, 'number', 'stub permissions.request'); - assert.isObject(privacy.network.tlsVersionRestrictionConfig, - 'privacy.network.tlsVersionRestrictionConfig'); - assert.isObject(runtime, 'runtime'); - assert.isFunction(runtime.connect, 'runtime.connect'); - assert.isNumber(runtime.connect.callCount, 'stub runtime.connect'); - assert.isObject(runtime.Port, 'runtime.Port'); - assert.isFunction(runtime.Port.disconnect, 'runtime.Port.disconnect'); - assert.isFunction(runtime.Port.onDisconnect.addListener, + assert.strictEqual(typeof privacy.network.tlsVersionRestrictionConfig, + 'object', 'privacy.network.tlsVersionRestrictionConfig'); + assert.strictEqual(typeof runtime, 'object', 'runtime'); + assert.strictEqual(typeof runtime.connect, 'function', + 'runtime.connect'); + assert.strictEqual(typeof runtime.connect.callCount, 'number', + 'stub runtime.connect'); + assert.strictEqual(typeof runtime.Port, 'object', 'runtime.Port'); + assert.strictEqual(typeof runtime.Port.disconnect, 'function', 'runtime.Port.disconnect'); - assert.isFunction(runtime.Port.onDisconnect.addListener, - 'runtime.Port.onDisconnect.addListener'); - assert.isObject(sessions, 'sessions'); - assert.isFunction(sessions.getRecentlyClosed, + assert.strictEqual(typeof runtime.Port.onDisconnect.addListener, + 'function', 'runtime.Port.disconnect'); + assert.strictEqual(typeof runtime.Port.onDisconnect.addListener, + 'function', 'runtime.Port.onDisconnect.addListener'); + assert.strictEqual(typeof sessions, 'object', 'sessions'); + assert.strictEqual(typeof sessions.getRecentlyClosed, 'function', 'sessions.getRecentlyClosed'); - assert.isNumber(sessions.getRecentlyClosed.callCount, + assert.strictEqual(typeof sessions.getRecentlyClosed.callCount, 'number', 'stub sessions.getRecentlyClosed'); - assert.isObject(storage, 'storage'); - assert.isObject(storage.local, 'storage.local'); - assert.isFunction(storage.local.get, 'storage.local.get'); - assert.isNumber(storage.local.get.callCount, 'stub storage.local.get'); - assert.isObject(storage.onChanged, 'storage.onChanged'); - assert.isFunction(storage.onChanged.addListener, + assert.strictEqual(typeof storage, 'object', 'storage'); + assert.strictEqual(typeof storage.local, 'object', 'storage.local'); + assert.strictEqual(typeof storage.local.get, 'function', + 'storage.local.get'); + assert.strictEqual(typeof storage.local.get.callCount, 'number', + 'stub storage.local.get'); + assert.strictEqual(typeof storage.onChanged, 'object', + 'storage.onChanged'); + assert.strictEqual(typeof storage.onChanged.addListener, 'function', 'storage.onChanged.addListener'); - assert.isNumber(storage.onChanged.addListener.callCount, - 'stub storage.onChanged.addListener'); - assert.isObject(tabs, 'tabs'); - assert.isFunction(tabs.get, 'tabs.get'); - assert.isNumber(tabs.get.callCount, 'stub tabs.get'); - assert.isObject(theme, 'theme'); - assert.isFunction(theme.getCurrent, 'theme.getCurrent'); - assert.isNumber(theme.getCurrent.callCount, 'stub theme.getCurrent'); - assert.isObject(windows, 'windows'); - assert.isFunction(windows.get, 'windows.get'); - assert.isNumber(windows.get.callCount, 'stub windows.get'); + assert.strictEqual(typeof storage.onChanged.addListener.callCount, + 'number', 'stub storage.onChanged.addListener'); + assert.strictEqual(typeof tabs, 'object', 'tabs'); + assert.strictEqual(typeof tabs.get, 'function', + 'tabs.get'); + assert.strictEqual(typeof tabs.get.callCount, 'number', + 'stub tabs.get'); + assert.strictEqual(typeof theme, 'object', 'theme'); + assert.strictEqual(typeof theme.getCurrent, 'function', + 'theme.getCurrent'); + assert.strictEqual(typeof theme.getCurrent.callCount, 'number', + 'stub theme.getCurrent'); + assert.strictEqual(typeof windows, 'object', 'windows'); + assert.strictEqual(typeof windows.get, 'function', + 'windows.get'); + assert.strictEqual(typeof windows.get.callCount, 'number', + 'stub windows.get'); }); it('should get stubbed api', () => { const schema = new Schema(); const browser = schema.mock(); - assert.isObject(browser, 'browser'); + assert.strictEqual(typeof browser, 'object', 'browser'); const { bookmarks, browserAction, browserSettings, commands, contextMenus, contextualIdentities, devtools, i18n, management, menus, notifications, permissions, privacy, runtime, sessions, storage, tabs, theme, windows } = browser; const { inspectedWindow } = devtools; - assert.isObject(bookmarks, 'bookmarks'); - assert.isFunction(bookmarks.create, 'bookmarks.create'); - assert.isNumber(bookmarks.create.callCount, 'stub bookmarks.create'); - assert.isObject(browserAction, 'browserAction'); - assert.isFunction(browserAction.setTitle, 'browserAction.setTitle'); - assert.isNumber(browserAction.setTitle.callCount, + assert.strictEqual(typeof bookmarks, 'object', 'bookmarks'); + assert.strictEqual(typeof bookmarks.create, 'function', + 'bookmarks.create'); + assert.strictEqual(typeof bookmarks.create.callCount, 'number', + 'stub bookmarks.create'); + assert.strictEqual(typeof browserAction, 'object', 'browserAction'); + assert.strictEqual(typeof browserAction.setTitle, 'function', + 'browserAction.setTitle'); + assert.strictEqual(typeof browserAction.setTitle.callCount, 'number', 'stub browserAction.setTitle'); - assert.isObject(browserAction.onClicked, 'browserAction.onClicked'); - assert.isFunction(browserAction.onClicked.addListener, + assert.strictEqual(typeof browserAction.onClicked, 'object', + 'browserAction.onClicked'); + assert.strictEqual(typeof browserAction.onClicked.addListener, 'function', 'browserAction.onClicked.addListener'); - assert.isNumber(browserAction.onClicked.addListener.callCount, - 'stub browserAction.onClicked.addListener.callCount'); - assert.isObject(browserSettings, 'browserSettings'); - assert.isObject(browserSettings.closeTabsByDoubleClick, - 'browserSettings.closeTabsByDoubleClick'); - assert.isObject(commands, 'commands'); - assert.isFunction(commands.update, 'commands.update'); - assert.isNumber(commands.update.callCount, 'stub commands.update'); - assert.isObject(contextMenus, 'contextMenus'); - assert.isFunction(contextMenus.create, 'contextMenus.create'); - assert.isNumber(contextMenus.create.callCount, + assert.strictEqual(typeof browserAction.onClicked.addListener.callCount, + 'number', 'stub browserAction.onClicked.addListener.callCount'); + assert.strictEqual(typeof browserSettings, 'object', 'browserSettings'); + assert.strictEqual(typeof browserSettings.closeTabsByDoubleClick, + 'object', 'browserSettings.closeTabsByDoubleClick'); + assert.strictEqual(typeof commands, 'object', 'commands'); + assert.strictEqual(typeof commands.update, 'function', + 'commands.update'); + assert.strictEqual(typeof commands.update.callCount, 'number', + 'stub commands.update'); + assert.strictEqual(typeof contextMenus, 'object', 'contextMenus'); + assert.strictEqual(typeof contextMenus.create, 'function', + 'contextMenus.create'); + assert.strictEqual(typeof contextMenus.create.callCount, 'number', 'stub contextMenus.create'); - assert.isObject(contextualIdentities, 'contextualIdentities'); - assert.isFunction(contextualIdentities.get, 'contextualIdentities.get'); - assert.isNumber(contextualIdentities.get.callCount, + assert.strictEqual(typeof contextualIdentities, 'object', + 'contextualIdentities'); + assert.strictEqual(typeof contextualIdentities.get, 'function', + 'contextualIdentities.get'); + assert.strictEqual(typeof contextualIdentities.get.callCount, 'number', 'stub contextualIdentities.get'); - assert.isObject(devtools, 'devtools'); - assert.isObject(inspectedWindow, 'inspectedWindow'); - assert.isFunction(inspectedWindow.reload, 'inspectedWindow.reload'); - assert.isNumber(inspectedWindow.reload.callCount, + assert.strictEqual(typeof devtools, 'object', 'devtools'); + assert.strictEqual(typeof inspectedWindow, 'object', 'inspectedWindow'); + assert.strictEqual(typeof inspectedWindow.reload, 'function', + 'inspectedWindow.reload'); + assert.strictEqual(typeof inspectedWindow.reload.callCount, 'number', 'stub inspectedWindow.reload'); - assert.isObject(i18n, 'i18n'); - assert.isFunction(i18n.getMessage, 'i18n.getMessage'); - assert.isNumber(i18n.getMessage.callCount, 'stub i18n.getMessage'); - assert.isObject(management, 'management'); - assert.isFunction(management.get, 'management.get'); - assert.isNumber(management.get.callCount, 'stub management.get'); - assert.isObject(menus, 'menus'); - assert.isFunction(menus.create, 'menus.create'); - assert.isNumber(menus.create.callCount, 'stub menus.create'); - assert.isFunction(menus.getTargetElement, 'menus.getTargetElement'); - assert.isNumber(menus.getTargetElement.callCount, + assert.strictEqual(typeof i18n, 'object', 'i18n'); + assert.strictEqual(typeof i18n.getMessage, 'function', + 'i18n.getMessage'); + assert.strictEqual(typeof i18n.getMessage.callCount, 'number', + 'stub i18n.getMessage'); + assert.strictEqual(typeof management, 'object', 'management'); + assert.strictEqual(typeof management.get, 'function', + 'management.get'); + assert.strictEqual(typeof management.get.callCount, 'number', + 'stub management.get'); + assert.strictEqual(typeof menus, 'object', 'menus'); + assert.strictEqual(typeof menus.create, 'function', + 'menus.create'); + assert.strictEqual(typeof menus.create.callCount, 'number', + 'stub menus.create'); + assert.strictEqual(typeof menus.getTargetElement, 'function', + 'menus.getTargetElement'); + assert.strictEqual(typeof menus.getTargetElement.callCount, 'number', 'stub menus.getTargetElement'); - assert.isFunction(menus.removeAll, 'menus.removeAll'); - assert.isNumber(menus.removeAll.callCount, 'stub menus.removeAll'); - assert.isObject(notifications, 'notifications'); - assert.isFunction(notifications.create, 'notifications.create'); - assert.isNumber(notifications.create.callCount, + assert.strictEqual(typeof menus.removeAll, 'function', + 'menus.removeAll'); + assert.strictEqual(typeof menus.removeAll.callCount, 'number', + 'stub menus.removeAll'); + assert.strictEqual(typeof notifications, 'object', 'notifications'); + assert.strictEqual(typeof notifications.create, 'function', + 'notifications.create'); + assert.strictEqual(typeof notifications.create.callCount, 'number', 'stub notifications.create'); - assert.isObject(notifications.onClosed, 'notifications.onClosed'); - assert.isFunction(notifications.onClosed.addListener, + assert.strictEqual(typeof notifications.onClosed, 'object', + 'notifications.onClosed'); + assert.strictEqual(typeof notifications.onClosed.addListener, 'function', 'notifications.onClosed.addListener'); - assert.isNumber(notifications.onClosed.addListener.callCount, - 'stub notifications.onClosed.addListener'); - assert.isObject(permissions, 'permissions'); - assert.isFunction(permissions.request, 'permissions.request'); - assert.isNumber(permissions.request.callCount, + assert.strictEqual(typeof notifications.onClosed.addListener.callCount, + 'number', 'stub notifications.onClosed.addListener'); + assert.strictEqual(typeof permissions, 'object', 'permissions'); + assert.strictEqual(typeof permissions.request, 'function', + 'permissions.request'); + assert.strictEqual(typeof permissions.request.callCount, 'number', 'stub permissions.request'); - assert.isObject(privacy.network.tlsVersionRestrictionConfig, - 'privacy.network.tlsVersionRestrictionConfig'); - assert.isObject(runtime, 'runtime'); - assert.isFunction(runtime.connect, 'runtime.connect'); - assert.isNumber(runtime.connect.callCount, 'stub runtime.connect'); - assert.isObject(runtime.Port, 'runtime.Port'); - assert.isFunction(runtime.Port.disconnect, 'runtime.Port.disconnect'); - assert.isFunction(runtime.Port.onDisconnect.addListener, + assert.strictEqual(typeof privacy.network.tlsVersionRestrictionConfig, + 'object', 'privacy.network.tlsVersionRestrictionConfig'); + assert.strictEqual(typeof runtime, 'object', 'runtime'); + assert.strictEqual(typeof runtime.connect, 'function', + 'runtime.connect'); + assert.strictEqual(typeof runtime.connect.callCount, 'number', + 'stub runtime.connect'); + assert.strictEqual(typeof runtime.Port, 'object', 'runtime.Port'); + assert.strictEqual(typeof runtime.Port.disconnect, 'function', 'runtime.Port.disconnect'); - assert.isFunction(runtime.Port.onDisconnect.addListener, - 'runtime.Port.onDisconnect.addListener'); - assert.isObject(sessions, 'sessions'); - assert.isFunction(sessions.getRecentlyClosed, + assert.strictEqual(typeof runtime.Port.onDisconnect.addListener, + 'function', 'runtime.Port.disconnect'); + assert.strictEqual(typeof runtime.Port.onDisconnect.addListener, + 'function', 'runtime.Port.onDisconnect.addListener'); + assert.strictEqual(typeof sessions, 'object', 'sessions'); + assert.strictEqual(typeof sessions.getRecentlyClosed, 'function', 'sessions.getRecentlyClosed'); - assert.isNumber(sessions.getRecentlyClosed.callCount, + assert.strictEqual(typeof sessions.getRecentlyClosed.callCount, 'number', 'stub sessions.getRecentlyClosed'); - assert.isObject(storage, 'storage'); - assert.isObject(storage.local, 'storage.local'); - assert.isFunction(storage.local.get, 'storage.local.get'); - assert.isNumber(storage.local.get.callCount, 'stub storage.local.get'); - assert.isObject(storage.onChanged, 'storage.onChanged'); - assert.isFunction(storage.onChanged.addListener, + assert.strictEqual(typeof storage, 'object', 'storage'); + assert.strictEqual(typeof storage.local, 'object', 'storage.local'); + assert.strictEqual(typeof storage.local.get, 'function', + 'storage.local.get'); + assert.strictEqual(typeof storage.local.get.callCount, 'number', + 'stub storage.local.get'); + assert.strictEqual(typeof storage.onChanged, 'object', + 'storage.onChanged'); + assert.strictEqual(typeof storage.onChanged.addListener, 'function', 'storage.onChanged.addListener'); - assert.isNumber(storage.onChanged.addListener.callCount, - 'stub storage.onChanged.addListener'); - assert.isObject(tabs, 'tabs'); - assert.isFunction(tabs.get, 'tabs.get'); - assert.isNumber(tabs.get.callCount, 'stub tabs.get'); - assert.isObject(theme, 'theme'); - assert.isFunction(theme.getCurrent, 'theme.getCurrent'); - assert.isNumber(theme.getCurrent.callCount, 'stub theme.getCurrent'); - assert.isObject(windows, 'windows'); - assert.isFunction(windows.get, 'windows.get'); - assert.isNumber(windows.get.callCount, 'stub windows.get'); + assert.strictEqual(typeof storage.onChanged.addListener.callCount, + 'number', 'stub storage.onChanged.addListener'); + assert.strictEqual(typeof tabs, 'object', 'tabs'); + assert.strictEqual(typeof tabs.get, 'function', + 'tabs.get'); + assert.strictEqual(typeof tabs.get.callCount, 'number', + 'stub tabs.get'); + assert.strictEqual(typeof theme, 'object', 'theme'); + assert.strictEqual(typeof theme.getCurrent, 'function', + 'theme.getCurrent'); + assert.strictEqual(typeof theme.getCurrent.callCount, 'number', + 'stub theme.getCurrent'); + assert.strictEqual(typeof windows, 'object', 'windows'); + assert.strictEqual(typeof windows.get, 'function', + 'windows.get'); + assert.strictEqual(typeof windows.get.callCount, 'number', + 'stub windows.get'); }); it('should access sandbox', () => { const browser = new Schema().mock(); - assert.isObject(browser._sandbox, 'sandbox'); - assert.isFunction(browser._sandbox.stub, 'stub'); + assert.strictEqual(typeof browser._sandbox, 'object', 'sandbox'); + assert.strictEqual(typeof browser._sandbox.stub, 'function', + 'stub'); const i = browser.runtime.connect.callCount; browser.runtime.connect(); assert.strictEqual(browser.runtime.connect.callCount, i + 1, 'called'); @@ -1284,8 +1348,10 @@ describe('Schema', () => { const port2 = mockConnect({ name: 'bar' }); assert.strictEqual(port1.name, 'foo', 'name'); assert.strictEqual(port2.name, 'bar', 'name'); - assert.isFunction(port1.onDisconnect.addListener, 'function'); - assert.isFunction(port2.onDisconnect.addListener, 'function'); + assert.strictEqual(typeof port1.onDisconnect.addListener, 'function', + 'function'); + assert.strictEqual(typeof port2.onDisconnect.addListener, 'function', + 'function'); // reset mockConnect.reset(); diff --git a/test/update.test.js b/test/update.test.js index d6613bd..6ff3157 100644 --- a/test/update.test.js +++ b/test/update.test.js @@ -1,9 +1,9 @@ /* api */ +import { strict as assert } from 'node:assert'; import fs from 'node:fs'; import path from 'node:path'; import process from 'node:process'; import sinon from 'sinon'; -import { assert } from 'chai'; import { afterEach, beforeEach, describe, it } from 'mocha'; import { MockAgent, getGlobalDispatcher, setGlobalDispatcher } from 'undici'; @@ -29,19 +29,21 @@ describe('fetch text', () => { it('should throw', async () => { await fetchText().catch(e => { - assert.instanceOf(e, TypeError, 'error'); - assert.strictEqual(e.message, 'Expected String but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Undefined.')); }); }); it('should throw', async () => { const url = new URL('https://example.com'); mockAgent.get(url.origin).intercept({ path: url.pathname, method: 'GET' }) - .reply(404); + .reply(404, { + ok: false, + status: 404 + }); await fetchText('https://example.com').catch(e => { - assert.instanceOf(e, Error, 'error'); - assert.strictEqual(e.message, - 'Network response was not ok. status: 404'); + assert.deepStrictEqual(e, + new Error('Network response was not ok. status: 404')); }); }); @@ -119,15 +121,15 @@ describe('get schema data', () => { it('should throw', async () => { await getSchemaData().catch(e => { - assert.instanceOf(e, TypeError, 'error'); - assert.strictEqual(e.message, 'Expected String but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Undefined.')); }); }); it('should throw', async () => { await getSchemaData('foo').catch(e => { - assert.instanceOf(e, TypeError, 'error'); - assert.strictEqual(e.message, 'Expected String but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Undefined.')); }); }); @@ -159,8 +161,8 @@ describe('get schema file list from jar manifest', () => { it('should throw', async () => { await getFileList().catch(e => { - assert.instanceOf(e, TypeError, 'error'); - assert.strictEqual(e.message, 'Expected String but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Undefined.')); }); }); @@ -192,8 +194,8 @@ describe('get all schema data', () => { it('should throw', async () => { await getAllSchemaData().catch(e => { - assert.instanceOf(e, TypeError, 'error'); - assert.strictEqual(e.message, 'Expected String but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Undefined.')); }); }); @@ -208,7 +210,7 @@ describe('get all schema data', () => { mockPool.intercept({ path: '/bar.json', method: 'GET' }) .reply(200, '{ "baz": "qux" }'); const res = await getAllSchemaData('https://example.com/'); - assert.isFalse(stubInfo.called, 'info'); + assert.strictEqual(stubInfo.called, false, 'info'); stubInfo.restore(); assert.deepEqual(res, [ { @@ -237,7 +239,7 @@ describe('get all schema data', () => { mockPool.intercept({ path: '/bar.json', method: 'GET' }) .reply(200, '{ "baz": "qux" }'); const res = await getAllSchemaData('https://example.com/', true); - assert.isTrue(stubInfo.called, 'info'); + assert.strictEqual(stubInfo.called, true, 'info'); stubInfo.restore(); assert.deepEqual(res, [ { @@ -270,15 +272,15 @@ describe('get listed schema data', () => { it('should throw', async () => { await getListedSchemaData().catch(e => { - assert.instanceOf(e, TypeError, 'error'); - assert.strictEqual(e.message, 'Expected String but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Undefined.')); }); }); it('should throw', async () => { await getListedSchemaData('foo').catch(e => { - assert.instanceOf(e, TypeError, 'error'); - assert.strictEqual(e.message, 'Expected Array but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected Array but got Undefined.')); }); }); @@ -292,7 +294,7 @@ describe('get listed schema data', () => { .reply(200, '{ "baz": "qux" }'); const res = await getListedSchemaData('https://example.com/', ['foo.json', 'bar.json']); - assert.isFalse(stubInfo.called, 'info'); + assert.strictEqual(stubInfo.called, false, 'info'); stubInfo.restore(); assert.deepEqual(res, [ { @@ -320,7 +322,7 @@ describe('get listed schema data', () => { .reply(200, '{ "baz": "qux" }'); const res = await getListedSchemaData('https://example.com/', ['foo.json', 'bar.json'], true); - assert.isTrue(stubInfo.called, 'info'); + assert.strictEqual(stubInfo.called, true, 'info'); stubInfo.restore(); assert.deepEqual(res, [ { @@ -353,8 +355,8 @@ describe('get MailExtensions schema data', () => { it('should throw', async () => { await getMailExtSchemaData().catch(e => { - assert.instanceOf(e, TypeError, 'error'); - assert.strictEqual(e.message, 'Expected String but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Undefined.')); }); }); @@ -369,7 +371,7 @@ describe('get MailExtensions schema data', () => { mockPool.intercept({ path: '/schemas/browserAction.json', method: 'GET' }) .reply(200, '{ "bar": "baz" }'); const res = await getMailExtSchemaData('https://example.com/'); - assert.isFalse(stubInfo.called, 'info'); + assert.strictEqual(stubInfo.called, false, 'info'); stubInfo.restore(); assert.deepEqual(res, [ { @@ -398,7 +400,7 @@ describe('get MailExtensions schema data', () => { mockPool.intercept({ path: '/schemas/browserAction.json', method: 'GET' }) .reply(200, '{ "bar": "baz" }'); const res = await getMailExtSchemaData('https://example.com/', true); - assert.isTrue(stubInfo.called, 'info'); + assert.strictEqual(stubInfo.called, true, 'info'); stubInfo.restore(); assert.deepEqual(res, [ { @@ -438,32 +440,55 @@ describe('create unified schema', () => { }); describe('save schema file', () => { + const globalDispatcher = getGlobalDispatcher(); + const mockAgent = new MockAgent(); + beforeEach(() => { + setGlobalDispatcher(mockAgent); + mockAgent.disableNetConnect(); + }); + afterEach(() => { + mockAgent.enableNetConnect(); + setGlobalDispatcher(globalDispatcher); + }); + it('should throw', async () => { await saveSchemaFile().catch(e => { - assert.instanceOf(e, TypeError, 'error'); - assert.strictEqual(e.message, 'Expected String but got Undefined.'); + assert.deepStrictEqual(e, + new TypeError('Expected String but got Undefined.')); }); }); it('should create file', async () => { - const stubAll = sinon.stub(Promise, 'all').resolves([ - [ - { - file: 'foo', - schema: { - foo: 'bar' - } - } - ], - [ - { - file: 'baz', - schema: { - baz: 'qux' - } - } - ] - ]); + const url = new URL('https://hg.mozilla.org/mozilla-central/raw-file/tip/'); + const mockPool = mockAgent.get(url.origin); + const browserItems = [ + 'commands.json', + 'pkcs11.json' + ]; + for (const item of browserItems) { + mockPool.intercept({ + path: `${url.pathname}browser/components/extensions/schemas/${item}`, + method: 'GET' + }).reply(200, `{ "browser": "${item}" }`); + } + const toolkitItems = [ + 'content_scripts.json', 'experiments.json', 'extension.json', 'i18n.json', + 'management.json', 'permissions.json', 'runtime.json', 'theme.json' + ]; + for (const item of toolkitItems) { + mockPool.intercept({ + path: `${url.pathname}toolkit/components/extensions/schemas/${item}`, + method: 'GET' + }).reply(200, `{ "toolkit": "${item}" }`); + } + mockPool.intercept({ + path: '/comm-central/raw-file/tip/mail/components/extensions/jar.mn', + method: 'GET' + }).reply(200, '# comment\n\nmessenger.jar:\n% content/messenger/ext-mail.json\n content/messenger/schemas/accounts.json\n'); + mockPool.intercept({ + path: '/comm-central/raw-file/tip/mail/components/extensions/schemas/accounts.json', + method: 'GET' + }).reply(200, '{ "mail": "accounts.json" }'); const stubWrite = sinon.stub(fs.promises, 'writeFile'); const stubInfo = sinon.stub(console, 'info'); const i = stubWrite.callCount; @@ -474,7 +499,6 @@ describe('save schema file', () => { const { callCount: writeCallCount } = stubWrite; const { callCount: infoCallCount } = stubInfo; stubInfo.restore(); - stubAll.restore(); stubWrite.restore(); assert.strictEqual(writeCallCount, i + 1, 'write'); assert.strictEqual(infoCallCount, j, 'info'); @@ -482,24 +506,36 @@ describe('save schema file', () => { }); it('should create file', async () => { - const stubAll = sinon.stub(Promise, 'all').resolves([ - [ - { - file: 'foo', - schema: { - foo: 'bar' - } - } - ], - [ - { - file: 'baz', - schema: { - baz: 'qux' - } - } - ] - ]); + const url = new URL('https://hg.mozilla.org/mozilla-central/raw-file/tip/'); + const mockPool = mockAgent.get(url.origin); + const browserItems = [ + 'commands.json', + 'pkcs11.json' + ]; + for (const item of browserItems) { + mockPool.intercept({ + path: `${url.pathname}browser/components/extensions/schemas/${item}`, + method: 'GET' + }).reply(200, `{ "browser": "${item}" }`); + } + const toolkitItems = [ + 'content_scripts.json', 'experiments.json', 'extension.json', 'i18n.json', + 'management.json', 'permissions.json', 'runtime.json', 'theme.json' + ]; + for (const item of toolkitItems) { + mockPool.intercept({ + path: `${url.pathname}toolkit/components/extensions/schemas/${item}`, + method: 'GET' + }).reply(200, `{ "toolkit": "${item}" }`); + } + mockPool.intercept({ + path: '/comm-central/raw-file/tip/mail/components/extensions/jar.mn', + method: 'GET' + }).reply(200, '# comment\n\nmessenger.jar:\n% content/messenger/ext-mail.json\n content/messenger/schemas/accounts.json\n'); + mockPool.intercept({ + path: '/comm-central/raw-file/tip/mail/components/extensions/schemas/accounts.json', + method: 'GET' + }).reply(200, '{ "mail": "accounts.json" }'); const stubWrite = sinon.stub(fs.promises, 'writeFile'); const stubInfo = sinon.stub(console, 'info'); const i = stubWrite.callCount; @@ -511,31 +547,39 @@ describe('save schema file', () => { const { callCount: infoCallCount } = stubInfo; stubInfo.restore(); stubWrite.restore(); - stubAll.restore(); assert.strictEqual(writeCallCount, i + 1, 'write'); - assert.strictEqual(infoCallCount, j + 3, 'info'); + assert.strictEqual(infoCallCount, j + 12, 'info'); assert.strictEqual(res, filePath, 'result'); }); it('should create file', async () => { - const stubAll = sinon.stub(Promise, 'all').resolves([ - [ - { - file: 'foo', - schema: { - foo: 'bar' - } - } - ], - [ - { - file: 'baz', - schema: { - baz: 'qux' - } - } - ] - ]); + const url = + new URL('https://hg.mozilla.org/releases/mozilla-release/raw-file/tip/'); + const mockPool = mockAgent.get(url.origin); + mockPool.intercept({ + path: `${url.pathname}browser/components/extensions/schemas/jar.mn`, + method: 'GET' + }).reply(200, 'content/extensions/schemas/foo.json\ncontent/extensions/schemas/bar.json\n'); + mockPool.intercept({ + path: `${url.pathname}browser/components/extensions/schemas/foo.json`, + method: 'GET' + }).reply(200, '{ "browser": "foo.json" }'); + mockPool.intercept({ + path: `${url.pathname}browser/components/extensions/schemas/bar.json`, + method: 'GET' + }).reply(200, '{ "browser": "bar.json" }'); + mockPool.intercept({ + path: `${url.pathname}toolkit/components/extensions/schemas/jar.mn`, + method: 'GET' + }).reply(200, 'content/extensions/schemas/baz.json\ncontent/extensions/schemas/qux.json\n'); + mockPool.intercept({ + path: `${url.pathname}toolkit/components/extensions/schemas/baz.json`, + method: 'GET' + }).reply(200, '{ "toolkit": "baz.json" }'); + mockPool.intercept({ + path: `${url.pathname}toolkit/components/extensions/schemas/qux.json`, + method: 'GET' + }).reply(200, '{ "toolkit": "qux.json" }'); const stubWrite = sinon.stub(fs.promises, 'writeFile'); const stubInfo = sinon.stub(console, 'info'); const i = stubWrite.callCount; @@ -546,7 +590,6 @@ describe('save schema file', () => { const { callCount: writeCallCount } = stubWrite; const { callCount: infoCallCount } = stubInfo; stubInfo.restore(); - stubAll.restore(); stubWrite.restore(); assert.strictEqual(writeCallCount, i + 1, 'write'); assert.strictEqual(infoCallCount, j, 'info'); @@ -554,24 +597,33 @@ describe('save schema file', () => { }); it('should create file', async () => { - const stubAll = sinon.stub(Promise, 'all').resolves([ - [ - { - file: 'foo', - schema: { - foo: 'bar' - } - } - ], - [ - { - file: 'baz', - schema: { - baz: 'qux' - } - } - ] - ]); + const url = + new URL('https://hg.mozilla.org/releases/mozilla-release/raw-file/tip/'); + const mockPool = mockAgent.get(url.origin); + mockPool.intercept({ + path: `${url.pathname}browser/components/extensions/schemas/jar.mn`, + method: 'GET' + }).reply(200, 'content/extensions/schemas/foo.json\ncontent/extensions/schemas/bar.json\n'); + mockPool.intercept({ + path: `${url.pathname}browser/components/extensions/schemas/foo.json`, + method: 'GET' + }).reply(200, '{ "browser": "foo.json" }'); + mockPool.intercept({ + path: `${url.pathname}browser/components/extensions/schemas/bar.json`, + method: 'GET' + }).reply(200, '{ "browser": "bar.json" }'); + mockPool.intercept({ + path: `${url.pathname}toolkit/components/extensions/schemas/jar.mn`, + method: 'GET' + }).reply(200, 'content/extensions/schemas/baz.json\ncontent/extensions/schemas/qux.json\n'); + mockPool.intercept({ + path: `${url.pathname}toolkit/components/extensions/schemas/baz.json`, + method: 'GET' + }).reply(200, '{ "toolkit": "baz.json" }'); + mockPool.intercept({ + path: `${url.pathname}toolkit/components/extensions/schemas/qux.json`, + method: 'GET' + }).reply(200, '{ "toolkit": "qux.json" }'); const stubWrite = sinon.stub(fs.promises, 'writeFile'); const stubInfo = sinon.stub(console, 'info'); const i = stubWrite.callCount; @@ -583,112 +635,253 @@ describe('save schema file', () => { const { callCount: infoCallCount } = stubInfo; stubInfo.restore(); stubWrite.restore(); - stubAll.restore(); assert.strictEqual(writeCallCount, i + 1, 'write'); - assert.strictEqual(infoCallCount, j + 1, 'info'); + assert.strictEqual(infoCallCount, j + 5, 'info'); assert.strictEqual(res, filePath, 'result'); }); }); describe('update schemas files', () => { - it('should call function', async () => { - const stubAll = sinon.stub(Promise, 'allSettled').resolves([ - { - status: 'resolved' - }, - { - status: 'resolved' - }, - { - reason: new Error('error'), - status: 'rejected' - }, - { - reason: new Error('error'), - status: 'rejected' - }, - { - status: 'resolved' - } - ]); + const globalDispatcher = getGlobalDispatcher(); + const mockAgent = new MockAgent(); + beforeEach(() => { + setGlobalDispatcher(mockAgent); + mockAgent.disableNetConnect(); + }); + afterEach(() => { + mockAgent.enableNetConnect(); + setGlobalDispatcher(globalDispatcher); + }); + + it('should not call function', async () => { + const url = new URL('https://hg.mozilla.org/mozilla-central/raw-file/tip/'); + const centralPath = url.pathname; + const betaPath = '/releases/mozilla-beta/raw-file/tip/'; + const releasePath = '/releases/mozilla-release/raw-file/tip/'; + const esrPath = `/releases/mozilla-esr${ESR_VER}/raw-file/tip/`; + const mailPath = '/comm-central/raw-file/tip/'; + const mockPool = mockAgent.get(url.origin); + for (const item of [centralPath, betaPath, releasePath, esrPath]) { + mockPool.intercept({ + path: `${item}browser/components/extensions/schemas/jar.mn`, + method: 'GET' + }).reply(200, 'content/extensions/schemas/foo.json\ncontent/extensions/schemas/bar.json\n'); + mockPool.intercept({ + path: `${item}browser/components/extensions/schemas/foo.json`, + method: 'GET' + }).reply(200, '{ "browser": "foo.json" }'); + mockPool.intercept({ + path: `${item}browser/components/extensions/schemas/bar.json`, + method: 'GET' + }).reply(200, '{ "browser": "bar.json" }'); + mockPool.intercept({ + path: `${item}toolkit/components/extensions/schemas/jar.mn`, + method: 'GET' + }).reply(200, 'content/extensions/schemas/baz.json\ncontent/extensions/schemas/qux.json\n'); + mockPool.intercept({ + path: `${item}toolkit/components/extensions/schemas/baz.json`, + method: 'GET' + }).reply(200, '{ "toolkit": "baz.json" }'); + mockPool.intercept({ + path: `${item}toolkit/components/extensions/schemas/qux.json`, + method: 'GET' + }).reply(200, '{ "toolkit": "qux.json" }'); + } + const browserItems = [ + 'commands.json', + 'pkcs11.json' + ]; + for (const item of browserItems) { + mockPool.intercept({ + path: `${centralPath}browser/components/extensions/schemas/${item}`, + method: 'GET' + }).reply(200, `{ "browser": "${item}" }`); + } + const toolkitItems = [ + 'content_scripts.json', 'experiments.json', 'extension.json', 'i18n.json', + 'management.json', 'permissions.json', 'runtime.json', 'theme.json' + ]; + for (const item of toolkitItems) { + mockPool.intercept({ + path: `${centralPath}toolkit/components/extensions/schemas/${item}`, + method: 'GET' + }).reply(200, `{ "toolkit": "${item}" }`); + } + mockPool.intercept({ + path: `${mailPath}mail/components/extensions/jar.mn`, + method: 'GET' + }).reply(200, 'content/messenger/schemas/quux.json\n'); + mockPool.intercept({ + path: `${mailPath}mail/components/extensions/schemas/quux.json`, + method: 'GET' + }).reply(200, '{ "mail": "quux.json" }'); + const stubWrite = sinon.stub(fs.promises, 'writeFile'); const stubTrace = sinon.stub(console, 'trace'); const i = stubTrace.callCount; const stubInfo = sinon.stub(console, 'info'); await updateSchemas(); const { callCount: traceCallCount } = stubTrace; - stubAll.restore(); + stubWrite.restore(); stubTrace.restore(); stubInfo.restore(); - assert.strictEqual(traceCallCount, i + 2, 'trace'); + assert.strictEqual(traceCallCount, i, 'trace not called'); }); it('should not call function', async () => { - const stubAll = sinon.stub(Promise, 'allSettled').resolves([ - { - status: 'resolved' - }, - { - status: 'resolved' - }, - { - status: 'resolved' - }, - { - status: 'resolved' - }, - { - status: 'resolved' - } - ]); + const url = new URL('https://hg.mozilla.org/mozilla-central/raw-file/tip/'); + const centralPath = url.pathname; + const betaPath = '/releases/mozilla-beta/raw-file/tip/'; + const releasePath = '/releases/mozilla-release/raw-file/tip/'; + const esrPath = `/releases/mozilla-esr${ESR_VER}/raw-file/tip/`; + const mailPath = '/comm-central/raw-file/tip/'; + const mockPool = mockAgent.get(url.origin); + for (const item of [centralPath, betaPath, releasePath, esrPath]) { + mockPool.intercept({ + path: `${item}browser/components/extensions/schemas/jar.mn`, + method: 'GET' + }).reply(200, 'content/extensions/schemas/foo.json\ncontent/extensions/schemas/bar.json\n'); + mockPool.intercept({ + path: `${item}browser/components/extensions/schemas/foo.json`, + method: 'GET' + }).reply(200, '{ "browser": "foo.json" }'); + mockPool.intercept({ + path: `${item}browser/components/extensions/schemas/bar.json`, + method: 'GET' + }).reply(200, '{ "browser": "bar.json" }'); + mockPool.intercept({ + path: `${item}toolkit/components/extensions/schemas/jar.mn`, + method: 'GET' + }).reply(200, 'content/extensions/schemas/baz.json\ncontent/extensions/schemas/qux.json\n'); + mockPool.intercept({ + path: `${item}toolkit/components/extensions/schemas/baz.json`, + method: 'GET' + }).reply(200, '{ "toolkit": "baz.json" }'); + mockPool.intercept({ + path: `${item}toolkit/components/extensions/schemas/qux.json`, + method: 'GET' + }).reply(200, '{ "toolkit": "qux.json" }'); + } + const browserItems = [ + 'commands.json', + 'pkcs11.json' + ]; + for (const item of browserItems) { + mockPool.intercept({ + path: `${centralPath}browser/components/extensions/schemas/${item}`, + method: 'GET' + }).reply(200, `{ "browser": "${item}" }`); + } + const toolkitItems = [ + 'content_scripts.json', 'experiments.json', 'extension.json', 'i18n.json', + 'management.json', 'permissions.json', 'runtime.json', 'theme.json' + ]; + for (const item of toolkitItems) { + mockPool.intercept({ + path: `${centralPath}toolkit/components/extensions/schemas/${item}`, + method: 'GET' + }).reply(200, `{ "toolkit": "${item}" }`); + } + mockPool.intercept({ + path: `${mailPath}mail/components/extensions/jar.mn`, + method: 'GET' + }).reply(200, 'content/messenger/schemas/quux.json\n'); + mockPool.intercept({ + path: `${mailPath}mail/components/extensions/schemas/quux.json`, + method: 'GET' + }).reply(400, '{ "ok": false, "status": 400 }'); + const stubWrite = sinon.stub(fs.promises, 'writeFile'); const stubTrace = sinon.stub(console, 'trace'); const i = stubTrace.callCount; const stubInfo = sinon.stub(console, 'info'); await updateSchemas(); const { callCount: traceCallCount } = stubTrace; - stubAll.restore(); + stubWrite.restore(); stubTrace.restore(); stubInfo.restore(); - assert.strictEqual(traceCallCount, i, 'trace'); + assert.strictEqual(traceCallCount, i + 1, 'trace called'); }); - it('should call function', async () => { - const stubAll = sinon.stub(Promise, 'allSettled').resolves([ - { - reason: new Error('error'), - status: 'rejected' - } - ]); + it('should not call function', async () => { + const url = + new URL('https://hg.mozilla.org/releases/mozilla-beta/raw-file/tip/'); + const mockPool = mockAgent.get(url.origin); + mockPool.intercept({ + path: `${url.pathname}browser/components/extensions/schemas/jar.mn`, + method: 'GET' + }).reply(200, 'content/extensions/schemas/foo.json\ncontent/extensions/schemas/bar.json\n'); + mockPool.intercept({ + path: `${url.pathname}browser/components/extensions/schemas/foo.json`, + method: 'GET' + }).reply(200, '{ "browser": "foo.json" }'); + mockPool.intercept({ + path: `${url.pathname}browser/components/extensions/schemas/bar.json`, + method: 'GET' + }).reply(200, '{ "browser": "bar.json" }'); + mockPool.intercept({ + path: `${url.pathname}toolkit/components/extensions/schemas/jar.mn`, + method: 'GET' + }).reply(200, 'content/extensions/schemas/baz.json\ncontent/extensions/schemas/qux.json\n'); + mockPool.intercept({ + path: `${url.pathname}toolkit/components/extensions/schemas/baz.json`, + method: 'GET' + }).reply(200, '{ "toolkit": "baz.json" }'); + mockPool.intercept({ + path: `${url.pathname}toolkit/components/extensions/schemas/qux.json`, + method: 'GET' + }).reply(200, '{ "toolkit": "qux.json" }'); + const stubWrite = sinon.stub(fs.promises, 'writeFile'); const stubTrace = sinon.stub(console, 'trace'); const i = stubTrace.callCount; const stubInfo = sinon.stub(console, 'info'); - const opt = { + await updateSchemas({ channel: 'beta' - }; - await updateSchemas(opt); + }); const { callCount: traceCallCount } = stubTrace; - stubAll.restore(); + stubWrite.restore(); stubTrace.restore(); stubInfo.restore(); - assert.strictEqual(traceCallCount, i + 1, 'trace'); + assert.strictEqual(traceCallCount, i, 'trace not called'); }); it('should not call function', async () => { - const stubAll = sinon.stub(Promise, 'allSettled').resolves([ - { - status: 'resolved' - } - ]); + const url = + new URL('https://hg.mozilla.org/releases/mozilla-beta/raw-file/tip/'); + const mockPool = mockAgent.get(url.origin); + mockPool.intercept({ + path: `${url.pathname}browser/components/extensions/schemas/jar.mn`, + method: 'GET' + }).reply(200, 'content/extensions/schemas/foo.json\ncontent/extensions/schemas/bar.json\n'); + mockPool.intercept({ + path: `${url.pathname}browser/components/extensions/schemas/foo.json`, + method: 'GET' + }).reply(200, '{ "browser": "foo.json" }'); + mockPool.intercept({ + path: `${url.pathname}browser/components/extensions/schemas/bar.json`, + method: 'GET' + }).reply(200, '{ "browser": "bar.json" }'); + mockPool.intercept({ + path: `${url.pathname}toolkit/components/extensions/schemas/jar.mn`, + method: 'GET' + }).reply(200, 'content/extensions/schemas/baz.json\ncontent/extensions/schemas/qux.json\n'); + mockPool.intercept({ + path: `${url.pathname}toolkit/components/extensions/schemas/baz.json`, + method: 'GET' + }).reply(200, '{ "toolkit": "baz.json" }'); + mockPool.intercept({ + path: `${url.pathname}toolkit/components/extensions/schemas/qux.json`, + method: 'GET' + }).reply(400, '{ "ok": false, "status": 400 }'); + const stubWrite = sinon.stub(fs.promises, 'writeFile'); const stubTrace = sinon.stub(console, 'trace'); const i = stubTrace.callCount; const stubInfo = sinon.stub(console, 'info'); - const opt = { + await updateSchemas({ channel: 'beta' - }; - await updateSchemas(opt); + }); const { callCount: traceCallCount } = stubTrace; - stubAll.restore(); + stubWrite.restore(); stubTrace.restore(); stubInfo.restore(); - assert.strictEqual(traceCallCount, i, 'trace'); + assert.strictEqual(traceCallCount, i + 1, 'trace called'); }); });