From 525fd5941161c20eec76c2c73c4beeb280b2f794 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Mon, 11 Jan 2021 11:21:14 +0530 Subject: [PATCH 01/35] initial attempt to export adb utils --- src/main.js | 3 ++- src/util/adb.js | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main.js b/src/main.js index 3a1a456550..a6c6283320 100644 --- a/src/main.js +++ b/src/main.js @@ -2,9 +2,10 @@ import {main} from './program'; import cmd from './cmd'; import * as logger from './util/logger'; +import {listADBDevices, listADBFirefoxAPKs} from './util/adb'; // This only exposes util/logger so far. // Do we need anything else? -const util = {logger}; +const util = {logger, listADBDevices, listADBFirefoxAPKs}; export default {main, cmd, util}; diff --git a/src/util/adb.js b/src/util/adb.js index 213f0134fb..dc103749be 100644 --- a/src/util/adb.js +++ b/src/util/adb.js @@ -1,15 +1,9 @@ /* @flow */ import defaultADB from '@devicefarmer/adbkit'; -import { - isErrorWithCode, - UsageError, - WebExtError, -} from '../errors'; +import {isErrorWithCode, UsageError, WebExtError} from '../errors'; import {createLogger} from '../util/logger'; -import packageIdentifiers, { - defaultApkComponents, -} from '../firefox/package-identifiers'; +import packageIdentifiers, {defaultApkComponents} from '../firefox/package-identifiers'; export const DEVICE_DIR_BASE = '/sdcard/'; export const ARTIFACTS_DIR_PREFIX = 'web-ext-artifacts-'; @@ -418,3 +412,15 @@ export default class ADBUtils { }); } } + +export async function listADBDevices(adbBin?: string): Promise> { + const adbClient = new ADBUtils({adbBin}); + return await adbClient.discoverDevices(); +} + +export async function listADBFirefoxAPKs( + adbBin?: string +): Promise> { + const adbClient = new ADBUtils({adbBin}); + return await adbClient.discoverInstalledFirefoxAPKs(); +} From b94db982f15c362d4415970947aeb8df1a9fdcbd Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Mon, 11 Jan 2021 11:24:58 +0530 Subject: [PATCH 02/35] revert accidental changes to imports --- src/util/adb.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/util/adb.js b/src/util/adb.js index dc103749be..9e0cfb6908 100644 --- a/src/util/adb.js +++ b/src/util/adb.js @@ -1,9 +1,15 @@ /* @flow */ import defaultADB from '@devicefarmer/adbkit'; -import {isErrorWithCode, UsageError, WebExtError} from '../errors'; +import { + isErrorWithCode, + UsageError, + WebExtError +} from '../errors'; import {createLogger} from '../util/logger'; -import packageIdentifiers, {defaultApkComponents} from '../firefox/package-identifiers'; +import packageIdentifiers, { + defaultApkComponents, +} from '../firefox/package-identifiers'; export const DEVICE_DIR_BASE = '/sdcard/'; export const ARTIFACTS_DIR_PREFIX = 'web-ext-artifacts-'; From d11cf88ab27518f24943b686311a5b9c625dc289 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Mon, 11 Jan 2021 11:25:49 +0530 Subject: [PATCH 03/35] revert accidental changes to imports --- src/util/adb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/adb.js b/src/util/adb.js index 9e0cfb6908..33cb5e8586 100644 --- a/src/util/adb.js +++ b/src/util/adb.js @@ -4,7 +4,7 @@ import defaultADB from '@devicefarmer/adbkit'; import { isErrorWithCode, UsageError, - WebExtError + WebExtError, } from '../errors'; import {createLogger} from '../util/logger'; import packageIdentifiers, { From 712d5c697aed05122d78f64d544e6e3b601ec3a9 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Mon, 11 Jan 2021 11:35:29 +0530 Subject: [PATCH 04/35] add deviceId param --- src/util/adb.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util/adb.js b/src/util/adb.js index 33cb5e8586..20b651f88e 100644 --- a/src/util/adb.js +++ b/src/util/adb.js @@ -425,8 +425,9 @@ export async function listADBDevices(adbBin?: string): Promise> { } export async function listADBFirefoxAPKs( - adbBin?: string + adbBin?: string, + deviceId: string ): Promise> { const adbClient = new ADBUtils({adbBin}); - return await adbClient.discoverInstalledFirefoxAPKs(); + return await adbClient.discoverInstalledFirefoxAPKs(deviceId); } From 914847f830eb12953e576c2461d39fef086d2550 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Mon, 11 Jan 2021 12:32:13 +0530 Subject: [PATCH 05/35] add deviceId param --- src/util/adb.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/adb.js b/src/util/adb.js index 20b651f88e..e98bb61ce1 100644 --- a/src/util/adb.js +++ b/src/util/adb.js @@ -425,8 +425,8 @@ export async function listADBDevices(adbBin?: string): Promise> { } export async function listADBFirefoxAPKs( - adbBin?: string, - deviceId: string + deviceId: string, + adbBin?: string ): Promise> { const adbClient = new ADBUtils({adbBin}); return await adbClient.discoverInstalledFirefoxAPKs(deviceId); From 744f97dc035ea1527108007623b60c3516b1fcb4 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Thu, 14 Jan 2021 22:06:48 +0530 Subject: [PATCH 06/35] added lazy loading to adb function imports --- src/main.js | 11 ++++++++--- src/util/adb.js | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main.js b/src/main.js index a6c6283320..a42b1db39f 100644 --- a/src/main.js +++ b/src/main.js @@ -2,10 +2,15 @@ import {main} from './program'; import cmd from './cmd'; import * as logger from './util/logger'; -import {listADBDevices, listADBFirefoxAPKs} from './util/adb'; -// This only exposes util/logger so far. +// This only exposes util/logger and a couple of functions from util/adb so far. // Do we need anything else? -const util = {logger, listADBDevices, listADBFirefoxAPKs}; +const util = { + logger, + get adb() { + const {listADBDevices, listADBFirefoxAPKs} = require('./util/adb.js'); + return {listADBDevices, listADBFirefoxAPKs}; + }, +}; export default {main, cmd, util}; diff --git a/src/util/adb.js b/src/util/adb.js index e98bb61ce1..2aa667a05e 100644 --- a/src/util/adb.js +++ b/src/util/adb.js @@ -421,7 +421,7 @@ export default class ADBUtils { export async function listADBDevices(adbBin?: string): Promise> { const adbClient = new ADBUtils({adbBin}); - return await adbClient.discoverDevices(); + return adbClient.discoverDevices(); } export async function listADBFirefoxAPKs( @@ -429,5 +429,5 @@ export async function listADBFirefoxAPKs( adbBin?: string ): Promise> { const adbClient = new ADBUtils({adbBin}); - return await adbClient.discoverInstalledFirefoxAPKs(deviceId); + return adbClient.discoverInstalledFirefoxAPKs(deviceId); } From 72f31a3c54319d571b277418592370c1a9ca2b63 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Thu, 14 Jan 2021 23:44:14 +0530 Subject: [PATCH 07/35] added type annotation to getter --- src/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.js b/src/main.js index a42b1db39f..a27a098775 100644 --- a/src/main.js +++ b/src/main.js @@ -7,7 +7,7 @@ import * as logger from './util/logger'; // Do we need anything else? const util = { logger, - get adb() { + get adb(): Object { const {listADBDevices, listADBFirefoxAPKs} = require('./util/adb.js'); return {listADBDevices, listADBFirefoxAPKs}; }, From 2d8e5a998ba1e73b90535793dc193ddd5013ac06 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Fri, 15 Jan 2021 00:33:09 +0530 Subject: [PATCH 08/35] added tests to test out new adb util export --- tests/fixtures/import-as-esm/test-import.mjs | 5 +++++ tests/fixtures/require-as-cjs/test-require.js | 5 +++++ tests/unit/test.web-ext.js | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/tests/fixtures/import-as-esm/test-import.mjs b/tests/fixtures/import-as-esm/test-import.mjs index 0b1a856b20..981a9b4ddc 100644 --- a/tests/fixtures/import-as-esm/test-import.mjs +++ b/tests/fixtures/import-as-esm/test-import.mjs @@ -4,4 +4,9 @@ import assert from 'assert'; import webExt from 'web-ext'; assert.deepEqual(Object.keys(webExt).sort(), ['cmd', 'main', 'util'].sort()); +assert.deepEqual(Object.keys(webExt.util).sort(), ['logger', 'adb'].sort()); +assert.deepEqual( + Object.keys(webExt.util.adb).sort(), + ['listADBDevices', 'listADBFirefoxAPKs'].sort(), +); assert.equal(typeof webExt.cmd.run, 'function'); diff --git a/tests/fixtures/require-as-cjs/test-require.js b/tests/fixtures/require-as-cjs/test-require.js index a9a51b81a6..fd3a7e2fdc 100644 --- a/tests/fixtures/require-as-cjs/test-require.js +++ b/tests/fixtures/require-as-cjs/test-require.js @@ -3,4 +3,9 @@ const assert = require('assert'); const webExt = require('web-ext'); assert.deepEqual(Object.keys(webExt).sort(), ['cmd', 'main', 'util'].sort()); +assert.deepEqual(Object.keys(webExt.util).sort(), ['logger', 'adb'].sort()); +assert.deepEqual( + Object.keys(webExt.util.adb).sort(), + ['listADBDevices', 'listADBFirefoxAPKs'].sort(), +); assert.equal(typeof webExt.cmd.run, 'function'); diff --git a/tests/unit/test.web-ext.js b/tests/unit/test.web-ext.js index e40f6fbb3f..ab9ec6123c 100644 --- a/tests/unit/test.web-ext.js +++ b/tests/unit/test.web-ext.js @@ -6,6 +6,7 @@ import sinon from 'sinon'; import webExt from '../../src/main'; import {main} from '../../src/program'; import {consoleStream} from '../../src/util/logger'; +import {listADBDevices, listADBFirefoxAPKs} from '../../src/util/adb'; describe('webExt', () => { @@ -17,6 +18,14 @@ describe('webExt', () => { assert.equal(webExt.util.logger.consoleStream, consoleStream); }); + it('gives access to listADBDevices', () => { + assert.equal(webExt.util.adb.listADBDevices, listADBDevices); + }); + + it('gives access to listADBFirefoxAPKs', () => { + assert.equal(webExt.util.adb.listADBFirefoxAPKs, listADBFirefoxAPKs); + }); + describe('exposes commands', () => { let stub: any; afterEach(() => { From d3f799eeda4c5c7ac9fe02c3600b060b826f162c Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Fri, 15 Jan 2021 09:34:45 +0530 Subject: [PATCH 09/35] refactored test-import and test-require to reduce code duplication --- tests/fixtures/import-as-esm/test-import.mjs | 12 ------------ tests/fixtures/require-as-cjs/test-require.js | 11 ----------- tests/fixtures/webext-as-library/helpers.js | 11 +++++++++++ tests/fixtures/webext-as-library/test-import.mjs | 6 ++++++ tests/fixtures/webext-as-library/test-require.js | 5 +++++ 5 files changed, 22 insertions(+), 23 deletions(-) delete mode 100644 tests/fixtures/import-as-esm/test-import.mjs delete mode 100644 tests/fixtures/require-as-cjs/test-require.js create mode 100644 tests/fixtures/webext-as-library/helpers.js create mode 100644 tests/fixtures/webext-as-library/test-import.mjs create mode 100644 tests/fixtures/webext-as-library/test-require.js diff --git a/tests/fixtures/import-as-esm/test-import.mjs b/tests/fixtures/import-as-esm/test-import.mjs deleted file mode 100644 index 981a9b4ddc..0000000000 --- a/tests/fixtures/import-as-esm/test-import.mjs +++ /dev/null @@ -1,12 +0,0 @@ -import assert from 'assert'; - -// eslint-disable-next-line import/no-unresolved -import webExt from 'web-ext'; - -assert.deepEqual(Object.keys(webExt).sort(), ['cmd', 'main', 'util'].sort()); -assert.deepEqual(Object.keys(webExt.util).sort(), ['logger', 'adb'].sort()); -assert.deepEqual( - Object.keys(webExt.util.adb).sort(), - ['listADBDevices', 'listADBFirefoxAPKs'].sort(), -); -assert.equal(typeof webExt.cmd.run, 'function'); diff --git a/tests/fixtures/require-as-cjs/test-require.js b/tests/fixtures/require-as-cjs/test-require.js deleted file mode 100644 index fd3a7e2fdc..0000000000 --- a/tests/fixtures/require-as-cjs/test-require.js +++ /dev/null @@ -1,11 +0,0 @@ -const assert = require('assert'); - -const webExt = require('web-ext'); - -assert.deepEqual(Object.keys(webExt).sort(), ['cmd', 'main', 'util'].sort()); -assert.deepEqual(Object.keys(webExt.util).sort(), ['logger', 'adb'].sort()); -assert.deepEqual( - Object.keys(webExt.util.adb).sort(), - ['listADBDevices', 'listADBFirefoxAPKs'].sort(), -); -assert.equal(typeof webExt.cmd.run, 'function'); diff --git a/tests/fixtures/webext-as-library/helpers.js b/tests/fixtures/webext-as-library/helpers.js new file mode 100644 index 0000000000..ab523a26fd --- /dev/null +++ b/tests/fixtures/webext-as-library/helpers.js @@ -0,0 +1,11 @@ +const assert = require('assert'); + +export function testWebExtModuleImports(webExt) { + assert.deepEqual(Object.keys(webExt).sort(), ['cmd', 'main', 'util'].sort()); + assert.deepEqual(Object.keys(webExt.util).sort(), ['logger', 'adb'].sort()); + assert.deepEqual( + Object.keys(webExt.util.adb).sort(), + ['listADBDevices', 'listADBFirefoxAPKs'].sort(), + ); + assert.equal(typeof webExt.cmd.run, 'function'); +} diff --git a/tests/fixtures/webext-as-library/test-import.mjs b/tests/fixtures/webext-as-library/test-import.mjs new file mode 100644 index 0000000000..354df0538a --- /dev/null +++ b/tests/fixtures/webext-as-library/test-import.mjs @@ -0,0 +1,6 @@ +// eslint-disable-next-line import/no-unresolved +import webExt from 'web-ext'; + +import {testWebExtModuleImports} from './helpers'; + +testWebExtModuleImports(webExt); diff --git a/tests/fixtures/webext-as-library/test-require.js b/tests/fixtures/webext-as-library/test-require.js new file mode 100644 index 0000000000..aeca2d52a0 --- /dev/null +++ b/tests/fixtures/webext-as-library/test-require.js @@ -0,0 +1,5 @@ +import {testWebExtModuleImports} from './helpers'; + +const webExt = require('web-ext'); + +testWebExtModuleImports(webExt); From 1f061a130911d16df07f30ecd9c332dda87a0571 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Fri, 15 Jan 2021 09:59:26 +0530 Subject: [PATCH 10/35] fixed paths for newly refactored import tests --- tests/functional/common.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/common.js b/tests/functional/common.js index e78d6bedee..3709bedb06 100644 --- a/tests/functional/common.js +++ b/tests/functional/common.js @@ -21,9 +21,9 @@ export const fixturesDir: string = export const minimalAddonPath: string = path.join(fixturesDir, 'minimal-web-ext'); export const fixtureEsmImport: string = - path.join(fixturesDir, 'import-as-esm'); + path.join(fixturesDir, 'webext-as-library'); export const fixtureCjsRequire: string = - path.join(fixturesDir, 'require-as-cjs'); + path.join(fixturesDir, 'webext-as-library'); export const fakeFirefoxPath: string = path.join( functionalTestsDir, process.platform === 'win32' ? From e612848839deab087e71675b3fa4f8af4f88a35e Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Fri, 15 Jan 2021 10:07:42 +0530 Subject: [PATCH 11/35] fixed test-require imports --- tests/fixtures/webext-as-library/test-require.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/webext-as-library/test-require.js b/tests/fixtures/webext-as-library/test-require.js index aeca2d52a0..9612ebd0eb 100644 --- a/tests/fixtures/webext-as-library/test-require.js +++ b/tests/fixtures/webext-as-library/test-require.js @@ -1,5 +1,5 @@ -import {testWebExtModuleImports} from './helpers'; - const webExt = require('web-ext'); +const testWebExtModuleImports = require('./helpers.js'); + testWebExtModuleImports(webExt); From ea76ae31bfa3a164ec2fd775915d8364de88dcc3 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Fri, 15 Jan 2021 10:13:51 +0530 Subject: [PATCH 12/35] trying to fix webext-as-library imports --- tests/fixtures/webext-as-library/helpers.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/fixtures/webext-as-library/helpers.js b/tests/fixtures/webext-as-library/helpers.js index ab523a26fd..b598366c95 100644 --- a/tests/fixtures/webext-as-library/helpers.js +++ b/tests/fixtures/webext-as-library/helpers.js @@ -1,6 +1,6 @@ const assert = require('assert'); -export function testWebExtModuleImports(webExt) { +function testWebExtModuleImports(webExt) { assert.deepEqual(Object.keys(webExt).sort(), ['cmd', 'main', 'util'].sort()); assert.deepEqual(Object.keys(webExt.util).sort(), ['logger', 'adb'].sort()); assert.deepEqual( @@ -9,3 +9,7 @@ export function testWebExtModuleImports(webExt) { ); assert.equal(typeof webExt.cmd.run, 'function'); } + +module.exports = { + testWebExtModuleImports, +}; From 3354d88977df9ca727affe7f875b6b9b03cbb979 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Fri, 15 Jan 2021 10:27:55 +0530 Subject: [PATCH 13/35] trying to fix webext-as-library exports --- tests/fixtures/webext-as-library/helpers.js | 2 +- tests/fixtures/webext-as-library/test-require.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/fixtures/webext-as-library/helpers.js b/tests/fixtures/webext-as-library/helpers.js index b598366c95..1d05791d1d 100644 --- a/tests/fixtures/webext-as-library/helpers.js +++ b/tests/fixtures/webext-as-library/helpers.js @@ -1,6 +1,6 @@ const assert = require('assert'); -function testWebExtModuleImports(webExt) { +export function testWebExtModuleImports(webExt) { assert.deepEqual(Object.keys(webExt).sort(), ['cmd', 'main', 'util'].sort()); assert.deepEqual(Object.keys(webExt.util).sort(), ['logger', 'adb'].sort()); assert.deepEqual( diff --git a/tests/fixtures/webext-as-library/test-require.js b/tests/fixtures/webext-as-library/test-require.js index 9612ebd0eb..0a7a9588b4 100644 --- a/tests/fixtures/webext-as-library/test-require.js +++ b/tests/fixtures/webext-as-library/test-require.js @@ -1,5 +1,5 @@ const webExt = require('web-ext'); -const testWebExtModuleImports = require('./helpers.js'); +const helpers = require('./helpers.js'); -testWebExtModuleImports(webExt); +helpers.testWebExtModuleImports(webExt); From 20a52cd7710c95a21d4b78a124985f5748295dd5 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Fri, 15 Jan 2021 10:32:13 +0530 Subject: [PATCH 14/35] trying to fix webext-as-library exports --- tests/fixtures/webext-as-library/helpers.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/fixtures/webext-as-library/helpers.js b/tests/fixtures/webext-as-library/helpers.js index 1d05791d1d..ab523a26fd 100644 --- a/tests/fixtures/webext-as-library/helpers.js +++ b/tests/fixtures/webext-as-library/helpers.js @@ -9,7 +9,3 @@ export function testWebExtModuleImports(webExt) { ); assert.equal(typeof webExt.cmd.run, 'function'); } - -module.exports = { - testWebExtModuleImports, -}; From 90cf9553902285f7f4cd51d0f5c0b82543bb73e2 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Fri, 15 Jan 2021 10:42:55 +0530 Subject: [PATCH 15/35] trying to fix webext-as-library exports --- tests/fixtures/webext-as-library/helpers.js | 6 +++++- tests/fixtures/webext-as-library/test-import.mjs | 4 ++-- tests/fixtures/webext-as-library/test-require.js | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/fixtures/webext-as-library/helpers.js b/tests/fixtures/webext-as-library/helpers.js index ab523a26fd..b598366c95 100644 --- a/tests/fixtures/webext-as-library/helpers.js +++ b/tests/fixtures/webext-as-library/helpers.js @@ -1,6 +1,6 @@ const assert = require('assert'); -export function testWebExtModuleImports(webExt) { +function testWebExtModuleImports(webExt) { assert.deepEqual(Object.keys(webExt).sort(), ['cmd', 'main', 'util'].sort()); assert.deepEqual(Object.keys(webExt.util).sort(), ['logger', 'adb'].sort()); assert.deepEqual( @@ -9,3 +9,7 @@ export function testWebExtModuleImports(webExt) { ); assert.equal(typeof webExt.cmd.run, 'function'); } + +module.exports = { + testWebExtModuleImports, +}; diff --git a/tests/fixtures/webext-as-library/test-import.mjs b/tests/fixtures/webext-as-library/test-import.mjs index 354df0538a..94802b10c7 100644 --- a/tests/fixtures/webext-as-library/test-import.mjs +++ b/tests/fixtures/webext-as-library/test-import.mjs @@ -1,6 +1,6 @@ // eslint-disable-next-line import/no-unresolved import webExt from 'web-ext'; -import {testWebExtModuleImports} from './helpers'; +import * as _ from './helpers'; -testWebExtModuleImports(webExt); +_.testWebExtModuleImports(webExt); diff --git a/tests/fixtures/webext-as-library/test-require.js b/tests/fixtures/webext-as-library/test-require.js index 0a7a9588b4..7d578cf263 100644 --- a/tests/fixtures/webext-as-library/test-require.js +++ b/tests/fixtures/webext-as-library/test-require.js @@ -1,5 +1,5 @@ const webExt = require('web-ext'); -const helpers = require('./helpers.js'); +const _ = require('./helpers.js'); -helpers.testWebExtModuleImports(webExt); +_.testWebExtModuleImports(webExt); From a00f2aedbc87c770db9d1e055f044ff41d15607e Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Fri, 15 Jan 2021 10:46:57 +0530 Subject: [PATCH 16/35] trying to fix webext-as-library exports --- tests/fixtures/webext-as-library/test-import.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/webext-as-library/test-import.mjs b/tests/fixtures/webext-as-library/test-import.mjs index 94802b10c7..354df0538a 100644 --- a/tests/fixtures/webext-as-library/test-import.mjs +++ b/tests/fixtures/webext-as-library/test-import.mjs @@ -1,6 +1,6 @@ // eslint-disable-next-line import/no-unresolved import webExt from 'web-ext'; -import * as _ from './helpers'; +import {testWebExtModuleImports} from './helpers'; -_.testWebExtModuleImports(webExt); +testWebExtModuleImports(webExt); From 5e4760be85925fc239a1a470d28b061db03d5c3a Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Fri, 15 Jan 2021 11:09:06 +0530 Subject: [PATCH 17/35] trying to fix webext-as-library exports --- tests/fixtures/webext-as-library/test-import.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/webext-as-library/test-import.mjs b/tests/fixtures/webext-as-library/test-import.mjs index 354df0538a..1051e7dad9 100644 --- a/tests/fixtures/webext-as-library/test-import.mjs +++ b/tests/fixtures/webext-as-library/test-import.mjs @@ -1,6 +1,6 @@ // eslint-disable-next-line import/no-unresolved import webExt from 'web-ext'; -import {testWebExtModuleImports} from './helpers'; +import {testWebExtModuleImports} from '../helpers'; testWebExtModuleImports(webExt); From 2c3f3dabc7ac13bd405d509ec32d6823bcfb6067 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Fri, 15 Jan 2021 11:13:03 +0530 Subject: [PATCH 18/35] trying to fix webext-as-library exports --- tests/fixtures/webext-as-library/test-import.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/webext-as-library/test-import.mjs b/tests/fixtures/webext-as-library/test-import.mjs index 1051e7dad9..ddc81b58a5 100644 --- a/tests/fixtures/webext-as-library/test-import.mjs +++ b/tests/fixtures/webext-as-library/test-import.mjs @@ -1,6 +1,6 @@ // eslint-disable-next-line import/no-unresolved import webExt from 'web-ext'; -import {testWebExtModuleImports} from '../helpers'; +import {testWebExtModuleImports} from './helpers.js'; testWebExtModuleImports(webExt); From 8c659dbb8925b8ada1a7ed0410d0f79dce3ac335 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Fri, 15 Jan 2021 11:18:02 +0530 Subject: [PATCH 19/35] trying to fix webext-as-library exports --- tests/fixtures/webext-as-library/test-import.mjs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/webext-as-library/test-import.mjs b/tests/fixtures/webext-as-library/test-import.mjs index ddc81b58a5..6598a8d77d 100644 --- a/tests/fixtures/webext-as-library/test-import.mjs +++ b/tests/fixtures/webext-as-library/test-import.mjs @@ -1,6 +1,7 @@ // eslint-disable-next-line import/no-unresolved import webExt from 'web-ext'; -import {testWebExtModuleImports} from './helpers.js'; +// eslint-disable-next-line import/extensions +import * as _ from './helpers.js'; -testWebExtModuleImports(webExt); +_.testWebExtModuleImports(webExt); From 116d49f4e76da6450c222d8d234a18d22b4b3858 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Fri, 15 Jan 2021 11:21:27 +0530 Subject: [PATCH 20/35] more trying to fix webext-as-library exports --- tests/fixtures/webext-as-library/test-import.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/webext-as-library/test-import.mjs b/tests/fixtures/webext-as-library/test-import.mjs index 6598a8d77d..35ec1443b5 100644 --- a/tests/fixtures/webext-as-library/test-import.mjs +++ b/tests/fixtures/webext-as-library/test-import.mjs @@ -2,6 +2,6 @@ import webExt from 'web-ext'; // eslint-disable-next-line import/extensions -import * as _ from './helpers.js'; +import _ from './helpers.js'; _.testWebExtModuleImports(webExt); From 2ea94706025537e000b1c7753d6b1070c0522414 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Tue, 19 Jan 2021 08:27:43 +0530 Subject: [PATCH 21/35] addressing minor changes --- tests/fixtures/webext-as-library/helpers.js | 21 ++++++++++++++++--- .../webext-as-library/test-import.mjs | 6 ++++-- .../webext-as-library/test-require.js | 4 ++-- tests/functional/common.js | 4 +--- tests/functional/test.lib.imports.js | 6 +++--- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/tests/fixtures/webext-as-library/helpers.js b/tests/fixtures/webext-as-library/helpers.js index b598366c95..a4f42f16ed 100644 --- a/tests/fixtures/webext-as-library/helpers.js +++ b/tests/fixtures/webext-as-library/helpers.js @@ -1,15 +1,30 @@ const assert = require('assert'); -function testWebExtModuleImports(webExt) { +function testModuleExports(webExt) { assert.deepEqual(Object.keys(webExt).sort(), ['cmd', 'main', 'util'].sort()); assert.deepEqual(Object.keys(webExt.util).sort(), ['logger', 'adb'].sort()); + assert.equal(typeof webExt.cmd.run, 'function'); + + assertImportedADB({expectLoaded: false}); assert.deepEqual( Object.keys(webExt.util.adb).sort(), ['listADBDevices', 'listADBFirefoxAPKs'].sort(), ); - assert.equal(typeof webExt.cmd.run, 'function'); + assertImportedADB({expectLoaded: true}); +} + +function assertImportedADB({expectLoaded}) { + const hasAdbDeps = Object.keys(require.cache).filter( + (filePath) => filePath.includes('@devicefarmer/adbkit') + ).length > 0; + + const msg = expectLoaded + ? 'adb module should have been loaded' + : 'adb module should not be loaded yet'; + + assert.equal(hasAdbDeps, expectLoaded, msg); } module.exports = { - testWebExtModuleImports, + testModuleExports, }; diff --git a/tests/fixtures/webext-as-library/test-import.mjs b/tests/fixtures/webext-as-library/test-import.mjs index 35ec1443b5..8d9cf34636 100644 --- a/tests/fixtures/webext-as-library/test-import.mjs +++ b/tests/fixtures/webext-as-library/test-import.mjs @@ -2,6 +2,8 @@ import webExt from 'web-ext'; // eslint-disable-next-line import/extensions -import _ from './helpers.js'; +import helpers from './helpers.js'; -_.testWebExtModuleImports(webExt); +const {testModuleExports} = helpers; + +testModuleExports(webExt); diff --git a/tests/fixtures/webext-as-library/test-require.js b/tests/fixtures/webext-as-library/test-require.js index 7d578cf263..afc2f39874 100644 --- a/tests/fixtures/webext-as-library/test-require.js +++ b/tests/fixtures/webext-as-library/test-require.js @@ -1,5 +1,5 @@ const webExt = require('web-ext'); -const _ = require('./helpers.js'); +const {testModuleExports} = require('./helpers.js'); -_.testWebExtModuleImports(webExt); +testModuleExports(webExt); diff --git a/tests/functional/common.js b/tests/functional/common.js index 3709bedb06..00e8fe5561 100644 --- a/tests/functional/common.js +++ b/tests/functional/common.js @@ -20,9 +20,7 @@ export const fixturesDir: string = path.join(functionalTestsDir, '..', 'fixtures'); export const minimalAddonPath: string = path.join(fixturesDir, 'minimal-web-ext'); -export const fixtureEsmImport: string = - path.join(fixturesDir, 'webext-as-library'); -export const fixtureCjsRequire: string = +export const fixturesUseAsLibrary: string = path.join(fixturesDir, 'webext-as-library'); export const fakeFirefoxPath: string = path.join( functionalTestsDir, diff --git a/tests/functional/test.lib.imports.js b/tests/functional/test.lib.imports.js index ce23a4ec40..0c0bbd45ea 100644 --- a/tests/functional/test.lib.imports.js +++ b/tests/functional/test.lib.imports.js @@ -6,7 +6,7 @@ import {describe, it, before, after} from 'mocha'; import shell from 'shelljs'; import { - withTempDir, fixtureEsmImport, fixtureCjsRequire, + withTempDir, fixturesUseAsLibrary, } from './common'; const npm = shell.which('npm').toString(); @@ -35,7 +35,7 @@ describe('web-ext imported as a library', () => { it('can be imported as an ESM module', async () => { await withTempDir(async (tmpDir) => { execFileSync(npm, ['link', 'web-ext'], {cwd: tmpDir.path()}); - shell.cp('-rf', `${fixtureEsmImport}/*`, tmpDir.path()); + shell.cp('-rf', `${fixturesUseAsLibrary}/*`, tmpDir.path()); execFileSync(node, ['--experimental-modules', 'test-import.mjs'], { cwd: tmpDir.path(), }); @@ -45,7 +45,7 @@ describe('web-ext imported as a library', () => { it('can be imported as a CommonJS module', async () => { await withTempDir(async (tmpDir) => { execFileSync(npm, ['link', 'web-ext'], {cwd: tmpDir.path()}); - shell.cp('-rf', `${fixtureCjsRequire}/*`, tmpDir.path()); + shell.cp('-rf', `${fixturesUseAsLibrary}/*`, tmpDir.path()); execFileSync(node, ['--experimental-modules', 'test-require.js'], { cwd: tmpDir.path(), }); From 610e85e826129d3d655cf2738a762b0fef01ed4d Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Tue, 19 Jan 2021 08:35:59 +0530 Subject: [PATCH 22/35] testing --- tests/fixtures/webext-as-library/helpers.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/fixtures/webext-as-library/helpers.js b/tests/fixtures/webext-as-library/helpers.js index a4f42f16ed..2735148e0f 100644 --- a/tests/fixtures/webext-as-library/helpers.js +++ b/tests/fixtures/webext-as-library/helpers.js @@ -21,6 +21,10 @@ function assertImportedADB({expectLoaded}) { const msg = expectLoaded ? 'adb module should have been loaded' : 'adb module should not be loaded yet'; + // eslint-disable-next-line no-console + console.log(Object.keys(require.cache).filter( + (filePath) => filePath.includes('@devicefarmer/adbkit') + )); assert.equal(hasAdbDeps, expectLoaded, msg); } From 40c626f227b1796223fbb20686e823659cb4f04f Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Thu, 21 Jan 2021 05:23:05 +0530 Subject: [PATCH 23/35] testing windows inports/exports --- tests/functional/test.lib.imports.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/functional/test.lib.imports.js b/tests/functional/test.lib.imports.js index 0c0bbd45ea..f9ab20fd95 100644 --- a/tests/functional/test.lib.imports.js +++ b/tests/functional/test.lib.imports.js @@ -38,6 +38,7 @@ describe('web-ext imported as a library', () => { shell.cp('-rf', `${fixturesUseAsLibrary}/*`, tmpDir.path()); execFileSync(node, ['--experimental-modules', 'test-import.mjs'], { cwd: tmpDir.path(), + stdio: 'inherit', }); }); }); @@ -48,6 +49,7 @@ describe('web-ext imported as a library', () => { shell.cp('-rf', `${fixturesUseAsLibrary}/*`, tmpDir.path()); execFileSync(node, ['--experimental-modules', 'test-require.js'], { cwd: tmpDir.path(), + stdio: 'inherit', }); }); }); From 56bb049dc83efad6beb5b22bc77b103b94f64ce2 Mon Sep 17 00:00:00 2001 From: ankushduacodes Date: Wed, 20 Jan 2021 17:11:54 -0800 Subject: [PATCH 24/35] trying to distingush between win32 path and posix path --- tests/fixtures/webext-as-library/helpers.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/fixtures/webext-as-library/helpers.js b/tests/fixtures/webext-as-library/helpers.js index 2735148e0f..5bb9367df8 100644 --- a/tests/fixtures/webext-as-library/helpers.js +++ b/tests/fixtures/webext-as-library/helpers.js @@ -14,8 +14,10 @@ function testModuleExports(webExt) { } function assertImportedADB({expectLoaded}) { + const adbPathString = process.platform === 'win32' ? + '@devicefarmer\\adbkit' : '@devicefarmer/adbkit'; const hasAdbDeps = Object.keys(require.cache).filter( - (filePath) => filePath.includes('@devicefarmer/adbkit') + (filePath) => filePath.includes(adbPathString) ).length > 0; const msg = expectLoaded From cc3f3e903345cdf50f2dd3f5299b83e7843fd53c Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Thu, 21 Jan 2021 06:54:05 +0530 Subject: [PATCH 25/35] removing log statemet --- tests/fixtures/webext-as-library/helpers.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/fixtures/webext-as-library/helpers.js b/tests/fixtures/webext-as-library/helpers.js index 5bb9367df8..d522324e30 100644 --- a/tests/fixtures/webext-as-library/helpers.js +++ b/tests/fixtures/webext-as-library/helpers.js @@ -23,10 +23,6 @@ function assertImportedADB({expectLoaded}) { const msg = expectLoaded ? 'adb module should have been loaded' : 'adb module should not be loaded yet'; - // eslint-disable-next-line no-console - console.log(Object.keys(require.cache).filter( - (filePath) => filePath.includes('@devicefarmer/adbkit') - )); assert.equal(hasAdbDeps, expectLoaded, msg); } From 49f1e7175c3fb37b4fae7507afafe6bf108fb8f1 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Thu, 21 Jan 2021 09:05:57 +0530 Subject: [PATCH 26/35] testing new exposed adb functions --- tests/unit/test-util/test.adb.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/unit/test-util/test.adb.js b/tests/unit/test-util/test.adb.js index ac97324431..6725cfee1b 100644 --- a/tests/unit/test-util/test.adb.js +++ b/tests/unit/test-util/test.adb.js @@ -13,6 +13,7 @@ import { import ADBUtils, { ARTIFACTS_DIR_PREFIX, DEVICE_DIR_BASE, + listADBDevices, listADBFirefoxAPKs, } from '../../../src/util/adb'; import { consoleStream, // instance is imported to inspect logged messages @@ -1310,4 +1311,32 @@ describe('utils/adb', () => { }); }); + describe('test exposed adb API functions', () => { + it('test listADBDevices', async () => { + const stubDiscoverDevices = sinon.stub( + ADBUtils.prototype, 'discoverDevices' + ); + stubDiscoverDevices.resolves(['emulator1', 'device2']); + const promise = listADBDevices(); + const devices = await assert.isFulfilled(promise); + assert.deepEqual(devices, ['emulator1', 'device2']); + }); + + it('test listADBFirefoxAPKs', async () => { + const adb = getFakeADBKit({}); + const stubDiscoverInstalledFirefoxAPKs = sinon.stub( + ADBUtils.prototype, 'discoverInstalledFirefoxAPKs' + ); + stubDiscoverInstalledFirefoxAPKs + .resolves(['package1', 'package2', 'package3']); + const promise = listADBFirefoxAPKs('device1'); + const packages = await assert.isFulfilled(promise); + sinon.assert.calledWith( + new ADBUtils({adb}).discoverInstalledFirefoxAPKs, + 'device1' + ); + assert.deepEqual(packages, ['package1', 'package2', 'package3']); + }); + }); + }); From bad409f57cb336b024faf1adf8445b38b86ccd2c Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Thu, 21 Jan 2021 09:54:47 +0530 Subject: [PATCH 27/35] added some documentation for new ADB functions and on how to run an extension on android --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fc937552cd..14ecb9af43 100644 --- a/README.md +++ b/README.md @@ -122,9 +122,16 @@ You are able to execute command functions without any argument validation. If yo import webExt from 'web-ext'; webExt.cmd.run({ + // To run an extension on android, uncomment next three lines + // target: 'firefox-android', + // firefoxApk: 'firefox apk package name', + // adbDevice: '', + + // To run an extension on desktop, uncomment next line + // firefox: '/path/to/Firefox-executable', + // These are command options derived from their CLI conterpart. // In this example, --source-dir is specified as sourceDir. - firefox: '/path/to/Firefox-executable', sourceDir: '/path/to/your/extension/source/', }, { // These are non CLI related options for each function. @@ -142,6 +149,16 @@ webExt.cmd.run({ }); ``` +To get a list of connected adb devices, you may use the following function which takes an optional argument `adbBin` which is a path to custom adb binary: +```js +webExt.util.adb.listADBDevices(); // returns a Promise> +``` + +To get a list of installed firefox APK packages for an ADB client, you may use the following function which takes in deviceId(required) and adbBin(optional) as arguments: +```js +webExt.util.adb.listADBFirefoxAPKs(deviceId); // returns a Promise> +``` + If you would like to control logging, you can access the logger object. Here is an example of turning on verbose logging: ```js From 5ebea0139f3348e297bc77e39a3db15453a868a8 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Thu, 21 Jan 2021 17:59:56 +0530 Subject: [PATCH 28/35] updated adbPathString to use path lib --- tests/fixtures/webext-as-library/helpers.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/webext-as-library/helpers.js b/tests/fixtures/webext-as-library/helpers.js index d522324e30..513fa70a3f 100644 --- a/tests/fixtures/webext-as-library/helpers.js +++ b/tests/fixtures/webext-as-library/helpers.js @@ -1,4 +1,5 @@ const assert = require('assert'); +const path = require('path'); function testModuleExports(webExt) { assert.deepEqual(Object.keys(webExt).sort(), ['cmd', 'main', 'util'].sort()); @@ -14,8 +15,7 @@ function testModuleExports(webExt) { } function assertImportedADB({expectLoaded}) { - const adbPathString = process.platform === 'win32' ? - '@devicefarmer\\adbkit' : '@devicefarmer/adbkit'; + const adbPathString = path.join('@devicefarmer', 'adbkit'); const hasAdbDeps = Object.keys(require.cache).filter( (filePath) => filePath.includes(adbPathString) ).length > 0; From 96166820f9edae727f62c525cf856b344790c650 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Thu, 21 Jan 2021 18:16:53 +0530 Subject: [PATCH 29/35] docs update --- README.md | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 14ecb9af43..3433d543e4 100644 --- a/README.md +++ b/README.md @@ -121,11 +121,24 @@ You are able to execute command functions without any argument validation. If yo // or... import webExt from 'web-ext'; +// If you would like to run an extension on Firefox for Android: + +// Path to adb binary (optional parameter, auto-detected if missing) +const adbBin = 'path/to/adb/binary'; +// Get an array of connected device ids (Array) +const deviceIds = await webExt.util.adb.listADBDevices(adbBin); +const adbDevice = deviceIds[0]; +// Get an array of Firefox APKs (Array) on a device +const firefoxAPKs = await webExt.util.adb.listADBFirefoxAPKs( + deviceId, adbBin +); +const firefoxApk = firefoxAPKs[0]; + webExt.cmd.run({ - // To run an extension on android, uncomment next three lines - // target: 'firefox-android', - // firefoxApk: 'firefox apk package name', - // adbDevice: '', + // Comment out next 3 lines to run the extension on firefox-desktop + target: 'firefox-android', + firefoxApk + adbDevice // To run an extension on desktop, uncomment next line // firefox: '/path/to/Firefox-executable', From c74a4e244260b2a10f863c91721538eb72e8f45a Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Sat, 23 Jan 2021 03:20:27 +0530 Subject: [PATCH 30/35] Addressing minor nits --- src/main.js | 5 ++++- tests/unit/test-util/test.adb.js | 9 ++++----- tests/unit/test.web-ext.js | 12 +++++++----- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main.js b/src/main.js index a27a098775..683a144d8e 100644 --- a/src/main.js +++ b/src/main.js @@ -3,10 +3,13 @@ import {main} from './program'; import cmd from './cmd'; import * as logger from './util/logger'; -// This only exposes util/logger and a couple of functions from util/adb so far. +// This only exposes util/logger and a subset of util/adb so far. // Do we need anything else? const util = { logger, + // Lazy load the adb module when util.adb is accessed for the first time, to defer loading + // the npm dependencies used by the adb module to when actually needed. + // This is being done to continue the courtesy of web-ext issue #1301 get adb(): Object { const {listADBDevices, listADBFirefoxAPKs} = require('./util/adb.js'); return {listADBDevices, listADBFirefoxAPKs}; diff --git a/tests/unit/test-util/test.adb.js b/tests/unit/test-util/test.adb.js index 6725cfee1b..ccc1f00e44 100644 --- a/tests/unit/test-util/test.adb.js +++ b/tests/unit/test-util/test.adb.js @@ -1311,8 +1311,8 @@ describe('utils/adb', () => { }); }); - describe('test exposed adb API functions', () => { - it('test listADBDevices', async () => { + describe('exports exposed in util.adb', () => { + it('lists connected adb devices', async () => { const stubDiscoverDevices = sinon.stub( ADBUtils.prototype, 'discoverDevices' ); @@ -1322,8 +1322,7 @@ describe('utils/adb', () => { assert.deepEqual(devices, ['emulator1', 'device2']); }); - it('test listADBFirefoxAPKs', async () => { - const adb = getFakeADBKit({}); + it('lists installed firefox apks on a device', async () => { const stubDiscoverInstalledFirefoxAPKs = sinon.stub( ADBUtils.prototype, 'discoverInstalledFirefoxAPKs' ); @@ -1332,7 +1331,7 @@ describe('utils/adb', () => { const promise = listADBFirefoxAPKs('device1'); const packages = await assert.isFulfilled(promise); sinon.assert.calledWith( - new ADBUtils({adb}).discoverInstalledFirefoxAPKs, + stubDiscoverInstalledFirefoxAPKs, 'device1' ); assert.deepEqual(packages, ['package1', 'package2', 'package3']); diff --git a/tests/unit/test.web-ext.js b/tests/unit/test.web-ext.js index ab9ec6123c..9bdd75dbb1 100644 --- a/tests/unit/test.web-ext.js +++ b/tests/unit/test.web-ext.js @@ -18,12 +18,14 @@ describe('webExt', () => { assert.equal(webExt.util.logger.consoleStream, consoleStream); }); - it('gives access to listADBDevices', () => { - assert.equal(webExt.util.adb.listADBDevices, listADBDevices); - }); + describe('exposes adb utils', () => { + it('gives access to listADBDevices', () => { + assert.equal(webExt.util.adb.listADBDevices, listADBDevices); + }); - it('gives access to listADBFirefoxAPKs', () => { - assert.equal(webExt.util.adb.listADBFirefoxAPKs, listADBFirefoxAPKs); + it('gives access to listADBFirefoxAPKs', () => { + assert.equal(webExt.util.adb.listADBFirefoxAPKs, listADBFirefoxAPKs); + }); }); describe('exposes commands', () => { From 24c448387a65787268d685fd1d479fffe03a469b Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Sat, 23 Jan 2021 03:20:37 +0530 Subject: [PATCH 31/35] Update README.md --- README.md | 50 +++++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 3433d543e4..a4b678ae1d 100644 --- a/README.md +++ b/README.md @@ -116,33 +116,14 @@ Aside from [using web-ext on the command line][web-ext-user-docs], you may wish You are able to execute command functions without any argument validation. If you want to execute `web-ext run` you would do so like this: +#### Running the extension on Firefox for desktop: ```js // const webExt = require('web-ext'); // or... import webExt from 'web-ext'; -// If you would like to run an extension on Firefox for Android: - -// Path to adb binary (optional parameter, auto-detected if missing) -const adbBin = 'path/to/adb/binary'; -// Get an array of connected device ids (Array) -const deviceIds = await webExt.util.adb.listADBDevices(adbBin); -const adbDevice = deviceIds[0]; -// Get an array of Firefox APKs (Array) on a device -const firefoxAPKs = await webExt.util.adb.listADBFirefoxAPKs( - deviceId, adbBin -); -const firefoxApk = firefoxAPKs[0]; - webExt.cmd.run({ - // Comment out next 3 lines to run the extension on firefox-desktop - target: 'firefox-android', - firefoxApk - adbDevice - - // To run an extension on desktop, uncomment next line - // firefox: '/path/to/Firefox-executable', - + firefox: '/path/to/Firefox-executable', // These are command options derived from their CLI conterpart. // In this example, --source-dir is specified as sourceDir. sourceDir: '/path/to/your/extension/source/', @@ -162,16 +143,31 @@ webExt.cmd.run({ }); ``` -To get a list of connected adb devices, you may use the following function which takes an optional argument `adbBin` which is a path to custom adb binary: +#### Running the extension on Firefox for android: ```js -webExt.util.adb.listADBDevices(); // returns a Promise> -``` +// Path to adb binary (optional parameter, auto-detected if missing) +const adbBin = "/path/to/adb"; +// Get an array of device ids (Array) +const deviceIds = await webExt.util.adb.listADBDevices(adbBin); +const adbDevice = ... +// Get an array of Firefox APKs (Array) +const firefoxAPKs = await webExt.util.adb.listADBFirefoxAPKs( + deviceId, adbBin +); +const firefoxApk = ... -To get a list of installed firefox APK packages for an ADB client, you may use the following function which takes in deviceId(required) and adbBin(optional) as arguments: -```js -webExt.util.adb.listADBFirefoxAPKs(deviceId); // returns a Promise> +webExt.cmd.run({ + target: 'firefox-android', + firefoxApk, + adbDevice, + sourceDir: ... +}).then((extensionRunner) => ...); ``` + + + + If you would like to control logging, you can access the logger object. Here is an example of turning on verbose logging: ```js From 22edc262cc83fc510e73b4cffc86132c463c5764 Mon Sep 17 00:00:00 2001 From: ankushduacodes <61025943+ankushduacodes@users.noreply.github.com> Date: Sat, 23 Jan 2021 03:23:55 +0530 Subject: [PATCH 32/35] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a4b678ae1d..8ca9a86a9d 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ webExt.cmd.run({ firefoxApk, adbDevice, sourceDir: ... -}).then((extensionRunner) => ...); +}).then((extensionRunner) => {...}); ``` From 4794f81264c39b0042097ef600d473f1a7cfb321 Mon Sep 17 00:00:00 2001 From: ankushduacodes Date: Tue, 26 Jan 2021 16:46:14 +0530 Subject: [PATCH 33/35] wording change --- README.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/README.md b/README.md index 8ca9a86a9d..cb072afb93 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,6 @@ Aside from [using web-ext on the command line][web-ext-user-docs], you may wish You are able to execute command functions without any argument validation. If you want to execute `web-ext run` you would do so like this: -#### Running the extension on Firefox for desktop: ```js // const webExt = require('web-ext'); // or... @@ -143,7 +142,7 @@ webExt.cmd.run({ }); ``` -#### Running the extension on Firefox for android: +If you would like to run an extension on Firefox for Android: ```js // Path to adb binary (optional parameter, auto-detected if missing) const adbBin = "/path/to/adb"; @@ -164,10 +163,6 @@ webExt.cmd.run({ }).then((extensionRunner) => {...}); ``` - - - - If you would like to control logging, you can access the logger object. Here is an example of turning on verbose logging: ```js From 3c3bd4a7adab12e2acf81b2f20e07df6a13f1642 Mon Sep 17 00:00:00 2001 From: ankushduacodes Date: Tue, 26 Jan 2021 16:53:12 +0530 Subject: [PATCH 34/35] more wording change --- src/main.js | 2 +- tests/unit/test-util/test.adb.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.js b/src/main.js index 683a144d8e..d2c9d8d74d 100644 --- a/src/main.js +++ b/src/main.js @@ -11,7 +11,7 @@ const util = { // the npm dependencies used by the adb module to when actually needed. // This is being done to continue the courtesy of web-ext issue #1301 get adb(): Object { - const {listADBDevices, listADBFirefoxAPKs} = require('./util/adb.js'); + const {listADBDevices, listADBFirefoxAPKs} = require('./util/adb'); return {listADBDevices, listADBFirefoxAPKs}; }, }; diff --git a/tests/unit/test-util/test.adb.js b/tests/unit/test-util/test.adb.js index ccc1f00e44..60b25e74c8 100644 --- a/tests/unit/test-util/test.adb.js +++ b/tests/unit/test-util/test.adb.js @@ -1312,7 +1312,7 @@ describe('utils/adb', () => { }); describe('exports exposed in util.adb', () => { - it('lists connected adb devices', async () => { + it('should export a listADBDevices method', async () => { const stubDiscoverDevices = sinon.stub( ADBUtils.prototype, 'discoverDevices' ); @@ -1322,7 +1322,7 @@ describe('utils/adb', () => { assert.deepEqual(devices, ['emulator1', 'device2']); }); - it('lists installed firefox apks on a device', async () => { + it('should export a listADBFirefoxAPKs method', async () => { const stubDiscoverInstalledFirefoxAPKs = sinon.stub( ADBUtils.prototype, 'discoverInstalledFirefoxAPKs' ); From 315c0f7dccf615a40abdd715a94f635898589510 Mon Sep 17 00:00:00 2001 From: ankushduacodes Date: Wed, 27 Jan 2021 13:49:30 +0530 Subject: [PATCH 35/35] addressing final few nits and polish requests --- README.md | 3 ++- tests/functional/test.lib.imports.js | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cb072afb93..93501ddc8e 100644 --- a/README.md +++ b/README.md @@ -122,9 +122,9 @@ You are able to execute command functions without any argument validation. If yo import webExt from 'web-ext'; webExt.cmd.run({ - firefox: '/path/to/Firefox-executable', // These are command options derived from their CLI conterpart. // In this example, --source-dir is specified as sourceDir. + firefox: '/path/to/Firefox-executable', sourceDir: '/path/to/your/extension/source/', }, { // These are non CLI related options for each function. @@ -143,6 +143,7 @@ webExt.cmd.run({ ``` If you would like to run an extension on Firefox for Android: + ```js // Path to adb binary (optional parameter, auto-detected if missing) const adbBin = "/path/to/adb"; diff --git a/tests/functional/test.lib.imports.js b/tests/functional/test.lib.imports.js index f9ab20fd95..0c0bbd45ea 100644 --- a/tests/functional/test.lib.imports.js +++ b/tests/functional/test.lib.imports.js @@ -38,7 +38,6 @@ describe('web-ext imported as a library', () => { shell.cp('-rf', `${fixturesUseAsLibrary}/*`, tmpDir.path()); execFileSync(node, ['--experimental-modules', 'test-import.mjs'], { cwd: tmpDir.path(), - stdio: 'inherit', }); }); }); @@ -49,7 +48,6 @@ describe('web-ext imported as a library', () => { shell.cp('-rf', `${fixturesUseAsLibrary}/*`, tmpDir.path()); execFileSync(node, ['--experimental-modules', 'test-require.js'], { cwd: tmpDir.path(), - stdio: 'inherit', }); }); });